From patchwork Thu Jun 23 14:50:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vasily Averin X-Patchwork-Id: 12892814 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AC23C433EF for ; Thu, 23 Jun 2022 14:50:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CCCDA8E0159; Thu, 23 Jun 2022 10:50:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C7AF38E0144; Thu, 23 Jun 2022 10:50:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B42388E0159; Thu, 23 Jun 2022 10:50:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A761A8E0144 for ; Thu, 23 Jun 2022 10:50:53 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 73E4F609A2 for ; Thu, 23 Jun 2022 14:50:53 +0000 (UTC) X-FDA: 79609787586.26.4D810F3 Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) by imf26.hostedemail.com (Postfix) with ESMTP id E37BD140014 for ; Thu, 23 Jun 2022 14:50:52 +0000 (UTC) Received: by mail-lj1-f176.google.com with SMTP id e4so23622951ljl.1 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=bJcKWLwAWExvymOvKkep6gZX9To0GU6DB1uIMbNAiLEfCaSakPIF7+UcIHT16Oqw0j 0HVg6pFf/4vAtbtPhEnhjQOQGMGd8SrruWL/ta7aZXLsAAVb6xoJRFXNjfq1upqMJPDy K9bHg4SOB9X24R2b1RKsNC6NCtHrta6EuzYUaHUCOc/oVTu58qTpny/JlOp+NfSBlfHH JfVTlhN6w0XPNCKejN/5NJxSvKpnFRRRnXbTvaQ45d9AMQowBfLdLz+M6fK4RClTcSzH DEQxN+DoW8dlRh3xsX2ypHK5VeRr+2CTlAhyE5SaxQb5nUAIi4cfx2+regedqUj5duOm RtKg== X-Gm-Message-State: AJIora8R0HOqd3RN4eyt0dkkJ9rVKnS1JbxeqBWQJoA/tqFBjbv2bE+7 jDNxRDlOeVLorRRF5U1LjRp2FQ== X-Google-Smtp-Source: AGRyM1vCXz1nYuxbK9EdnwlJRDs/Af+uT4YncjrwcBwC+7+RyvwRka/8mQzhi9po2lTKCsWceGmUXQ== 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> ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=openvz-org.20210112.gappssmtp.com header.s=20210112 header.b=0PHpaI3m; spf=pass (imf26.hostedemail.com: domain of vvs@openvz.org designates 209.85.208.176 as permitted sender) smtp.mailfrom=vvs@openvz.org; dmarc=pass (policy=none) header.from=openvz.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655995853; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gJ3rDFLPy4ULApkBUxHTk0EGt0vcK2KI8AydJnC3/9g=; b=q9aE6Fp/0TZJRl586Rfqax/Vyk4ic8ZC/YOdx+lkMq1G+HhYQY32F1b+uSlUZrSm7T/evI l4BIf/r+xUiyBElas/5Y3mN+0/0EfSlUGSOFqLIOW1il5lMEu8D3rYWRTEmgwkClwVOWy3 qscakzvhASzZ9gtuH4TrulYIWhpm87s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655995853; a=rsa-sha256; cv=none; b=d/y8vVYC/Jrom3XzE9UX/MQ++ayojhoq3z6q3p+tYzeDPbJBbpmUZcbylhK7AE0lgCnIIF rd4eIxmwXW1lmKeCSaU1TQPcAtgYwxbHZRSXMDfvzqMgZ/ERfeqiMkqsomqm7W11gZtJDM CdBq9VukZOILH44y+wApx/3KkMKlICk= X-Stat-Signature: b16nons1hsy8s7155x4fbftmzmguyom5 X-Rspam-User: X-Rspamd-Server: rspam07 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=openvz-org.20210112.gappssmtp.com header.s=20210112 header.b=0PHpaI3m; spf=pass (imf26.hostedemail.com: domain of vvs@openvz.org designates 209.85.208.176 as permitted sender) smtp.mailfrom=vvs@openvz.org; dmarc=pass (policy=none) header.from=openvz.org X-Rspamd-Queue-Id: E37BD140014 X-HE-Tag: 1655995852-448568 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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);