Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp5965291iog; Thu, 23 Jun 2022 08:39:48 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tcu7FYvAqopd9XDiL+s2tALWNnK1QCd89ysxVl27XyD17+hbBun0lkRm+jqzrp+LRqdJRL X-Received: by 2002:a17:906:118:b0:715:771b:251b with SMTP id 24-20020a170906011800b00715771b251bmr8918532eje.651.1655998787775; Thu, 23 Jun 2022 08:39:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655998787; cv=none; d=google.com; s=arc-20160816; b=rTCinKWLr4R3TqOmVa7WwQWVG4PF0SNYg5qQcONHYFLtNnX6SKM6tPvVaJYi90tJKC 929Ou2b+qKBwUI6y9JzBjWMedOmos8YAVq32hF3ryF5QjXt+NPDL+nkGuxUMccbS1DvT oyfQkirwL0FHCynRp1G6+EpcgQ2H2WoL+UvArjPwZsLA15mG6YRVzy7L6wIKUi132gE9 PiH7tiJOP36Yt5xrPPqqG6HblWG0sTG6jKLek5Wpn7Lb7YPN5yqS7mhQrjFT9JD3zLxT wtb12iS2umhcuiBKu7/uRmPYnmhwizxCVPm/7m4CY/llAGPtreF82HY5Emt/jmKhquDW wypg== 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=gJ3rDFLPy4ULApkBUxHTk0EGt0vcK2KI8AydJnC3/9g=; b=ijeHQ4xSDmVSq2sb/wtIIBS6JpSPThTAr7k/CJOHA9cvCXxvzOj8TGEquc6fJCjuLr LdOrUsLOH/8U+T8oXhKrkpvevgvdKrxYfZ2cXpxokl/CA2WPHLzVyK1EPij4vRiAJbvt PHkFPKp60b/HswAyl4ZnPqkEI4IB3M30JoCZEncVDXM2g5nsED+hkDk82cLdOF1b2G1/ mW3KCxF2yfBe2oHgCrxtGYlPq9rh4N+IJDJAajEvbAoW+3SsGeEnbmAgsTjutOKsdeGl v6SZ0a8dNg4939CIYxjfVEL/1f6ElluVpTtqKUoshxlaQjIJ0FLsfMJev9JbA3210jWY hlEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz-org.20210112.gappssmtp.com header.s=20210112 header.b=0PHpaI3m; 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 ga31-20020a1709070c1f00b007136091f459si5290186ejc.302.2022.06.23.08.39.21; Thu, 23 Jun 2022 08:39:47 -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=0PHpaI3m; 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 S232006AbiFWOu5 (ORCPT + 99 others); Thu, 23 Jun 2022 10:50:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231995AbiFWOuy (ORCPT ); Thu, 23 Jun 2022 10:50:54 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB93E46CA9 for ; Thu, 23 Jun 2022 07:50:52 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id q9so5588240ljp.4 for ; Thu, 23 Jun 2022 07:50:52 -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=gJ3rDFLPy4ULApkBUxHTk0EGt0vcK2KI8AydJnC3/9g=; b=0PHpaI3mugQcy26zKnEijg+MR8dK+awqtL8Wh5kFKIsrSTwwRJvE7JcyHOvgXYn1RM 38tko6Dj+NDRhGYQXtJO4BM5KB5cdLN8o5NV2kW27IQBAGnwtM7vRO+fscUUh+vbGm3T sqEmCuZbvBmr08aDz2zH5ucV4HFxXPFo2KUehHwPVXJXAKxuqYV78ktJviXMuNgs9U+M 17Db3nxxr+xFLTbpTNSuCRw+VP06vz+9Dk8stamcHShhCcdE1OmgwJXp9t5kEMq8g9MF IAMUaayL75UjHfaw9plqDRmZCXW+u/16I9LZyz9bWBSkyVDguBFHqNaqKUMEejQhmXy3 brMg== 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=gJ3rDFLPy4ULApkBUxHTk0EGt0vcK2KI8AydJnC3/9g=; b=D3vPV7QgW9ZkWcRaS0V5mGer4Bm/0ZB5jz/vEte5VPfTcfOVecEe9Hp/QbEsliRhIa 0VRt3h8VAbHO7hDWRdXeAguuWUlBMuJK6nmPrRbd8xZDYF/9UKHvZMFhjBLgOnTO2qqo An50dY1ePPx9sWVNzzfmOn7k6i41ffeBULBnoinDkipv6TqsCTx4Ld+uPimFyS0+7KTo FlX69qxL11j4VhSv4tZ55jigOFJiBQdVsBDw2Cj8j43Wn1jXaAiIuzi/ZiYOdTmFH3re PK24KcPwXWT3qgsXo9ZuD/oMF5Qgn7iuj09IcNvZv0QVwV5knT+vUB0t0ANo/Fy008V/ MeVA== X-Gm-Message-State: AJIora+98nS4HboIfUVEVxDuIlK9UUdX6bb4kgPsjO0iQcqYXTPIr0Qy Icr8ZtLlhrYHVt1136RWMPbp/Q== X-Received: by 2002:a2e:8e98:0:b0:255:9d3d:bac3 with SMTP id z24-20020a2e8e98000000b002559d3dbac3mr4809904ljk.103.1655995851256; Thu, 23 Jun 2022 07:50:51 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.129]) by smtp.gmail.com with ESMTPSA id q9-20020a194309000000b0047255d21171sm3024207lfa.160.2022.06.23.07.50.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jun 2022 07:50:50 -0700 (PDT) Message-ID: <96263f32-ff9b-c0e0-3af1-1c9f810861b3@openvz.org> Date: Thu, 23 Jun 2022 17:50:50 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 From: Vasily Averin Subject: [PATCH mm v5 1/9] memcg: enable accounting for struct cgroup To: Andrew Morton Cc: kernel@openvz.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Shakeel Butt , Roman Gushchin , =?UTF-8?Q?Michal_Koutn=c3=bd?= , Vlastimil Babka , Michal Hocko , Muchun Song , cgroups@vger.kernel.org References: <4e685057-b07d-745d-fdaa-1a6a5a681060@openvz.org> Content-Language: en-US In-Reply-To: <4e685057-b07d-745d-fdaa-1a6a5a681060@openvz.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Creating each new cgroup allocates 4Kb for struct cgroup. This is the largest memory allocation in this scenario and is epecially important for small VMs with 1-2 CPUs. Common part of the cgroup creation: Allocs Alloc $1*$2 Sum Allocation number size -------------------------------------------- 16 ~ 352 5632 5632 KERNFS 1 + 4096 4096 9728 (cgroup_mkdir+0xe4) 1 584 584 10312 (radix_tree_node_alloc.constprop.0+0x89) 1 192 192 10504 (__d_alloc+0x29) 2 72 144 10648 (avc_alloc_node+0x27) 2 64 128 10776 (percpu_ref_init+0x6a) 1 64 64 10840 (memcg_list_lru_alloc+0x21a) percpu: 1 + 192 192 192 call_site=psi_cgroup_alloc+0x1e 1 + 96 96 288 call_site=cgroup_rstat_init+0x5f 2 12 24 312 call_site=percpu_ref_init+0x23 1 6 6 318 call_site=__percpu_counter_init+0x22 '+' -- to be accounted, '~' -- partially accounted Accounting of this memory helps to avoid misuse inside memcg-limited containers. Signed-off-by: Vasily Averin Reviewed-by: Roman Gushchin Reviewed-by: Michal Koutný Acked-by: Shakeel Butt Reviewed-by: Muchun Song --- kernel/cgroup/cgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 1779ccddb734..1be0f81fe8e1 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -5353,7 +5353,7 @@ static struct cgroup *cgroup_create(struct cgroup *parent, const char *name, /* allocate the cgroup and its ID, 0 is reserved for the root */ cgrp = kzalloc(struct_size(cgrp, ancestor_ids, (level + 1)), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!cgrp) return ERR_PTR(-ENOMEM); -- 2.36.1