Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4386700ioa; Wed, 27 Apr 2022 02:40:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoGns6z65CPY1itaQMMtYRPfs6nnwiksR/7ZHmfCS/TuF+SdEypkgNPZd7iGvIuHfGFQ0I X-Received: by 2002:a17:902:8c82:b0:158:b701:c2a4 with SMTP id t2-20020a1709028c8200b00158b701c2a4mr27694092plo.66.1651052435005; Wed, 27 Apr 2022 02:40:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651052435; cv=none; d=google.com; s=arc-20160816; b=rjTOqLrl1Z2mOgiJvAzDkSSvk58dPKDDwHZYk9DJ5ZUp/ACBoaNJNxzTfLlwEQ92yq hiM3kVJthRJDFzLr9nKdLI0O9LJEdZYC0WGQC/IhhsWa2qNQqRKPDwEj8owmfq98EQ02 4lifOjPYgBH3/gIhG9m//IFrYcBs2u3vsv274XqG266+eA+CQGjiGXKpUnuBWgUwgo7/ 8tdbeh+LMd/MSJHrB2Q0uVu79sEbVXgVp3Q94wvM+WbbAxn0k01ENqxgzSs2hpanJ0LX D3XgCGr+Ff1+TT5H39f8dlsDnmDveG2IGqzFirqjEumN9yWj/IaJdHf4zIhIuTEu4pBv LaNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=pwauUeBlcHvBLcNyAimJGJIhIGSQVXs8oid0dWAxNRI=; b=fZSkdkT5Khc+K7x9dyomUrTHESrVvKGkFv2t5IOyCMhCYeZdHtItu138vUtgdmFfe1 fpQ5dR35NeiO+VwlZZuBp2ZuZ9r7gaF5Fm+0b6Tj1KoJX+gp6VVUcntxyJhTU5FhkmrR QW3jl4wMpem4oETXEJwrnlaSA6RzLv89sKfKhFHEHTTAmj7quwhKy8y6tYdAbDsvFit7 iH+JSO8j9qPQ+xtRQbaQZSCNBUH8xLPFBPFB+oX76Do4fnt+aIpRYEuQXeiITwlxMY8d MUzQ/X83QFgGBUf6oHvB9Bn11k4KKeeTGb93zg31X+nd8vHmgHxq9PWMig/4Ywxwho2b xs2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=nxABqQf6; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id k8-20020a63f008000000b0039d80004fcasi1043154pgh.221.2022.04.27.02.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 02:40:34 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=nxABqQf6; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 01A192715F7; Wed, 27 Apr 2022 02:16:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357842AbiD0F0z (ORCPT + 99 others); Wed, 27 Apr 2022 01:26:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242013AbiD0F0x (ORCPT ); Wed, 27 Apr 2022 01:26:53 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03F591154F3 for ; Tue, 26 Apr 2022 22:23:44 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id j17so658338pfi.9 for ; Tue, 26 Apr 2022 22:23:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pwauUeBlcHvBLcNyAimJGJIhIGSQVXs8oid0dWAxNRI=; b=nxABqQf6lZRKa97gncv5efuRIZgUZAdO5gy+OF4jUXCOKpj9bbJWK3r1gjH4Xw8PuN ktWmeG+np9gFm5AlHfhYGoEF6hgQvbXAvE8Quf/i9hC0H/nngx/EtDJDD9UyTTDYkAJT uHEDpmH3K3X7h19iV2m7d+uEYToyhrRt5/3VUYkZg4SOCqK0j5Nwhb1AdhdzECIqPo0D 6fiUmxExbZNRQJj1AZPLh48eAj/VDbqfjf/2RVcThYoIBxWVFZI0Gnq9jo9vnf4orWCu AcfxlihjntfM/JqbBBJDAEDbfYDCrNFcrzMLq9J5zMricu4rMtwS+dqCljWdIGdyWkVj vUAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pwauUeBlcHvBLcNyAimJGJIhIGSQVXs8oid0dWAxNRI=; b=6rV35bqcqet0/QbTnTBR/kBFX1IP/5Io0j3a8HzAnb1xJ9hs1HH2Zm1+AMeYmMwjKq NFm6slWNnkI01vGVm3jD3wTtHiAP1Gya3pL+hDuBeY/1h03zP5F8hJS6dCV7A0+QQqf+ KDp4NA1fQi15UIWtHu86VPVchBrCNGQluONzbUTlP97VVhtB3kC17WdFc6Ou9IW+pUrA b2LlS8IReTk+/rSMHqtRN9VHICS9z34nDA60Z4Dlg5MTUt8FlopsNEwg6t0EqWst3sue O46aScCIUDePkx6pPMr+1LE3KKbgj72dITC1tME6r1GVJl0E/iTcM4l3ZhYR+BzS1U1w DpDA== X-Gm-Message-State: AOAM533srE/zZ/Wm1zPS1vFr4PxJMSnM88MCsIVgQfDza7ZQ35FOhGfq pauUpnmfLLf1bpEVUIevTdOfjfkssOnO0xttitjcKQ== X-Received: by 2002:a63:5b53:0:b0:39c:c6b8:d53b with SMTP id l19-20020a635b53000000b0039cc6b8d53bmr22140578pgm.166.1651037023216; Tue, 26 Apr 2022 22:23:43 -0700 (PDT) MIME-Version: 1.0 References: <33085523-a8b9-1bf6-2726-f456f59015ef@openvz.org> In-Reply-To: <33085523-a8b9-1bf6-2726-f456f59015ef@openvz.org> From: Shakeel Butt Date: Tue, 26 Apr 2022 22:23:32 -0700 Message-ID: Subject: Re: [PATCH memcg v4] net: set proper memcg for net_init hooks allocations To: Vasily Averin Cc: Vlastimil Babka , Roman Gushchin , kernel@openvz.org, Florian Westphal , LKML , Michal Hocko , Cgroups , netdev , "David S. Miller" , Jakub Kicinski , Paolo Abeni Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 25, 2022 at 11:43 PM Vasily Averin wrote: > > __register_pernet_operations() executes init hook of registered > pernet_operation structure in all existing net namespaces. > > Typically, these hooks are called by a process associated with > the specified net namespace, and all __GFP_ACCOUNT marked > allocation are accounted for corresponding container/memcg. > > However __register_pernet_operations() calls the hooks in the same > context, and as a result all marked allocations are accounted > to one memcg for all processed net namespaces. > > This patch adjusts active memcg for each net namespace and helps > to account memory allocated inside ops_init() into the proper memcg. > > Signed-off-by: Vasily Averin Acked-by: Shakeel Butt [...] > > +static inline struct mem_cgroup *get_mem_cgroup_from_obj(void *p) > +{ > + struct mem_cgroup *memcg; > + Do we need memcg_kmem_enabled() check here or maybe mem_cgroup_from_obj() should be doing memcg_kmem_enabled() instead of mem_cgroup_disabled() as we can have "cgroup.memory=nokmem" boot param. > + rcu_read_lock(); > + do { > + memcg = mem_cgroup_from_obj(p); > + } while (memcg && !css_tryget(&memcg->css)); > + rcu_read_unlock(); > + return memcg; > +}