Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4426471ioa; Wed, 27 Apr 2022 03:43:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztgZW16BW0UxrLup35RiCFz3F3JHc0XJ4ZBhXeSlsPK1ITm7vQ8wgvadO9LcLJf9fQAsOQ X-Received: by 2002:a05:6a00:228b:b0:50d:3c82:911a with SMTP id f11-20020a056a00228b00b0050d3c82911amr16577002pfe.16.1651056212984; Wed, 27 Apr 2022 03:43:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651056212; cv=none; d=google.com; s=arc-20160816; b=JJe4/YCG1orpmxrTJvxGb954qpepqO1ksek0JjTJKjbgBlvDtUYx/+c4tqNqJouALK 7L0td/AkyClPGPGIK3acBc+GZNeTiktILii3jmGX0FjeYenAB/3Zc2cVclOvG0Tj5XAS s1CNO/2amgxS6tfsqPSRlOlpkAgeeiAiIg2sofAm3kS/64Fr9DSTKAnzH3j2ukR1A2dY ijVWiPQ7M0zhjZ5Ed6+qsCavo8JexWSClCfVGoiD4Z7Z0cRrf2S9h6g6eAJZ8WcU3yXh 05ObbkdJdGKEkpEJz3Jec510cMiNFupV8Zuyz676N+myAJr0S7F+NEx/qnC71k5s7lUa 7Amg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=ONCBO+e5tQXeuB1xqqICB6bR57S4tXEQxOiBCuhrW/I=; b=bNFd8CgFi97WChzAym8bjBX/CFPStG2OZAQRo8umk8Y1LNwHFIZu9OhxoxX+8cpS2m koPumZo2+Zb+hpG5VD4K5u6sUlOJ0WaJV7b5QUTZN2hTTPtbYMrLYTJTA3fkBBkkzQSd l0WUz5Z6IG0HOuJ3BQkFo7zt2hRBCenoOKQInAvxzzMifBQwXoikcNLRjCrywh0KowlA nUsVmYHaTBKcElUEaSSWDKnjD2LMcNJ76bzjtP6YfJkpvjP8sttynz3uC1O9aNqrT/83 WXmVofaBNFTzzpqd2FKHmNcXwEMuoLELFX0ceCqFGRu5tcAUBNvXU0oJYXFi2DXoY5j8 6xPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=OOGII0He; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id p11-20020a63740b000000b003aa0077f0e7si1162214pgc.83.2022.04.27.03.43.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 03:43:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=OOGII0He; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 42B1D3FAF6C; Wed, 27 Apr 2022 02:52:50 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355664AbiDZWQd (ORCPT + 99 others); Tue, 26 Apr 2022 18:16:33 -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 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE 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 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!