From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05266C433EF for ; Tue, 26 Apr 2022 22:13:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355661AbiDZWQc (ORCPT ); Tue, 26 Apr 2022 18:16:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232124AbiDZWQb (ORCPT ); Tue, 26 Apr 2022 18:16:31 -0400 Received: from out1.migadu.com (out1.migadu.com [IPv6:2001:41d0:2:863f::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 527933BF86; Tue, 26 Apr 2022 15:13:22 -0700 (PDT) Date: Tue, 26 Apr 2022 15:13:13 -0700 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= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Vasily Averin Cc: Vlastimil Babka , Shakeel Butt , kernel@openvz.org, Florian Westphal , linux-kernel@vger.kernel.org, Michal Hocko , cgroups@vger.kernel.org, netdev@vger.kernel.org, "David S. Miller" , Jakub Kicinski , Paolo Abeni Subject: Re: [PATCH memcg v4] net: set proper memcg for net_init hooks allocations Message-ID: References: <33085523-a8b9-1bf6-2726-f456f59015ef@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <33085523-a8b9-1bf6-2726-f456f59015ef@openvz.org> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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!