From mboxrd@z Thu Jan 1 00:00:00 1970 From: Roman Gushchin Subject: Re: [PATCH memcg v4] net: set proper memcg for net_init hooks allocations Date: Tue, 26 Apr 2022 15:13:13 -0700 Message-ID: References: <33085523-a8b9-1bf6-2726-f456f59015ef@openvz.org> Mime-Version: 1.0 Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1651011200; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ONCBO+e5tQXeuB1xqqICB6bR57S4tXEQxOiBCuhrW/I=; b=OOGII0HetFVOSjsZLi1gd3RE3w3HK4eGA85+lFWnNQINk7PsQUCLJ6D1oUhrMf5JkaAujg XDzi8sLsAZF/tBbAdHmIYRTcyhoA+SwIJWTb/ZqtXVoQRxGvN4ArsCo2kGa35XnhRbuRUC RvV9i34s3cE/gM7iK4P2z0BJnQu+bA8= Content-Disposition: inline In-Reply-To: <33085523-a8b9-1bf6-2726-f456f59015ef-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org> List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Vasily Averin Cc: Vlastimil Babka , Shakeel Butt , kernel-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org, Florian Westphal , linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Michal Hocko , cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, "David S. Miller" , Jakub Kicinski , Paolo Abeni On Tue, Apr 26, 2022 at 09:43:43AM +0300, 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 > --- > v4: get_mem_cgroup_from_kmem() renamed to get_mem_cgroup_from_obj(), > get_net_memcg() replaced by mem_cgroup_or_root(), suggested by Roman. > > v3: put_net_memcg() replaced by an alreay existing mem_cgroup_put() > It checks memcg before accessing it, this is required for > __register_pernet_operations() called before memcg initialization. > Additionally fixed leading whitespaces in non-memcg_kmem version > of mem_cgroup_from_obj(). > > v2: introduced get/put_net_memcg(), > new functions are moved under CONFIG_MEMCG_KMEM > to fix compilation issues reported by Intel's kernel test robot > > v1: introduced get_mem_cgroup_from_kmem(), which takes the refcount > for the found memcg, suggested by Shakeel > --- > include/linux/memcontrol.h | 27 ++++++++++++++++++++++++++- > net/core/net_namespace.c | 7 +++++++ > 2 files changed, 33 insertions(+), 1 deletion(-) Acked-by: Roman Gushchin Thanks!