Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2497236pxb; Mon, 18 Apr 2022 01:20:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPYsiRmmlZd+Kc3skvGz8B447AU7NV5i2N+YrBYl3bEsfq6N3MagfpKhPhBYGEk5MRKKjv X-Received: by 2002:a05:6a00:21c7:b0:4fd:f89f:ec17 with SMTP id t7-20020a056a0021c700b004fdf89fec17mr11051574pfj.72.1650270003542; Mon, 18 Apr 2022 01:20:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650270003; cv=none; d=google.com; s=arc-20160816; b=zGWTJ6mNgTIWyFQ2Je7oQzzb2IIDYRQtReV3vIeAbEXI3yUOK5dBAq5FAzY+SkUtVK GVwWLU6IZ0ml0bDmJg8BynasRdk0liEybDCoCJg/82hZNPkWHfetfi5njF7ExBO5+TiQ FoGcnHsnwiT+lqkU5vFQxbVQqbdPfuDUNRVI6SXhBElnLmPkS63rRbvLpvc9iNenIQ+J X0fAuh3CxchGb2BinKF63ytF88QBimVVZjG+IemcRW5qfrgnEWohhlk+qYQlMeJ9IY/2 7Az22fa15LXZ1O3k+TGWX9ri7W2EcUpts7flqs/+WyEzXqFwNAKHtmpJZ3y2qFVvhHB8 9/6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-language:references:cc:to:subject:from:user-agent :mime-version:date:message-id:dkim-signature; bh=bT5KP076LNXAkBuT6bxsWqWs6Rnf/a89eLMuVK8//BE=; b=JTtKFUss8PmE4nrf8CE+9XXK6sTk6We1c63b9MrmLpRaT5/X1JMB2wZmjgPzitfRRq 2P4VbMAUAWbCB58oO9wRuU4/nhgMI+gA2Ms85K5ZatFkfMNvGX2b0gZ9O+KdGgCC8m5U 4KPCYNS1faMGMasb5/RRokCjmTZpL4Cy3JnfY6Lzw/+Hsb+juFVcggifnaLkUaf/Caoq IYXQ1hqHGoHwwjzO63sR4FlQyx0/Eid1YO3KvR+JIbr7uXJgsFdFgELExmnHcY1LxTNP dqoUuEygAHiUJQqQuU8qUcBy8S/dSAbjFnmGlJUQnijhFVK1gkc1wB0TvRiK4RiE0KMh GKCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz-org.20210112.gappssmtp.com header.s=20210112 header.b=ncW0cuAM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvz.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y2-20020a170902cac200b00153b2d16593si4713132pld.411.2022.04.18.01.19.48; Mon, 18 Apr 2022 01:20:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@openvz-org.20210112.gappssmtp.com header.s=20210112 header.b=ncW0cuAM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvz.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233509AbiDQGmR (ORCPT + 99 others); Sun, 17 Apr 2022 02:42:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231481AbiDQGmP (ORCPT ); Sun, 17 Apr 2022 02:42:15 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 062AA2B24D for ; Sat, 16 Apr 2022 23:39:41 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id bq30so20002193lfb.3 for ; Sat, 16 Apr 2022 23:39:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:from:subject:to:cc :references:content-language:in-reply-to:content-transfer-encoding; bh=bT5KP076LNXAkBuT6bxsWqWs6Rnf/a89eLMuVK8//BE=; b=ncW0cuAMb8hBdKsyH8A3kwzpFlf5AjHuKNEWWaWOGkn5vtR0OwYflZ/UOyblXqRhoX kbsctJzKaEA9bWHOVkTV9KuCRQcRcOgvcUf41KIzu3vHK2W9CC4bp4s9AHaibfLLOQjS bT1e05vF0QYw5pL8iOoteYlboX9TqJwxMFp/G4XDGLWUN1+Kmy6fQdP8Kl/4NuFsySkn HzOuRVfYzz0kv3CUSF1d0XcVL91nMfwKTE/4x0Inr2clsZHHMcHM8uhguc3zAzvEA9cl WWfK9ozD2CGno/6VT0O3Ng+LCRT/WPIh/FlwpOJ46w4aohgfKTn2GFxLEpSzV5i7vrat rK0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:from :subject:to:cc:references:content-language:in-reply-to :content-transfer-encoding; bh=bT5KP076LNXAkBuT6bxsWqWs6Rnf/a89eLMuVK8//BE=; b=pdzvKYqdazTDKtuh92FA0ixRFd0BO8lAgJFYJYWhGn9hbxzsQXDhV5xZzyqCiNrWcF RVx/vkSqr/Za/ydadK0RftNyd3VH9YlkXDLHA2j+N7KPAeEs0zjgH+BfMWeABJ6cnBBd WnZbTQ37NvnMEO2rXswMX0115CrIB9PbSC2G6gk41Ak0SKdUSQvL8nW8lq655gd3JpHS fLbQqGtqkGhs9LtzTVzm6+PUzzMEt2r7CDWLPRiGn2UnMOhbP9KiPgz4F2WstJBcKxk8 B94dUMPJaGHIU6f7u1inrqGJDSoo/6J0L1Cor90FLDeVX9Wpa9qxJrMT3n941t+t8+6J Vvtw== X-Gm-Message-State: AOAM5322AdH8bicX80enP7tGqDfEmhJN9X8dozh5faLyf9MMo+cVKARN FIuzqV3UjAj3wcAkMccA9XzgQg== X-Received: by 2002:a05:6512:1326:b0:45a:3a4:f25a with SMTP id x38-20020a056512132600b0045a03a4f25amr4319176lfu.575.1650177579195; Sat, 16 Apr 2022 23:39:39 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.177]) by smtp.gmail.com with ESMTPSA id x40-20020a056512132800b004489691436esm872040lfu.146.2022.04.16.23.39.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 16 Apr 2022 23:39:38 -0700 (PDT) Message-ID: <55605876-d05a-8be3-a6ae-ec26de9ee178@openvz.org> Date: Sun, 17 Apr 2022 09:39:37 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 From: Vasily Averin Subject: [PATCH memcg RFC] net: set proper memcg for net_init hooks allocations To: Vlastimil Babka , Roman Gushchin Cc: kernel@openvz.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, cgroups@vger.kernel.org, Shakeel Butt , Michal Hocko , Florian Westphal , "David S. Miller" , Jakub Kicinski , Paolo Abeni References: <46c1c59e-1368-620d-e57a-f35c2c82084d@linux.dev> Content-Language: en-US In-Reply-To: <46c1c59e-1368-620d-e57a-f35c2c82084d@linux.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 __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_ACCOUNTING 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 --- Dear Vlastimil, Roman, I'm not sure that memcg is used correctly here, is it perhaps some additional locking required? --- net/core/net_namespace.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index a5b5bb99c644..171c6e0b2337 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -26,6 +26,7 @@ #include #include +#include /* * Our network namespace constructor/destructor lists */ @@ -1147,7 +1148,13 @@ static int __register_pernet_operations(struct list_head *list, * setup_net() and cleanup_net() are not possible. */ for_each_net(net) { + struct mem_cgroup *old, *memcg = NULL; +#ifdef CONFIG_MEMCG + memcg = (net == &init_net) ? root_mem_cgroup : mem_cgroup_from_obj(net); +#endif + old = set_active_memcg(memcg); error = ops_init(ops, net); + set_active_memcg(old); if (error) goto out_undo; list_add_tail(&net->exit_list, &net_exit_list); -- 2.31.1