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); From patchwork Thu Jun 23 14:50:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vasily Averin X-Patchwork-Id: 12892815 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 BA2B0C433EF for ; Thu, 23 Jun 2022 14:50:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C6D28E015A; Thu, 23 Jun 2022 10:50:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 575758E0144; Thu, 23 Jun 2022 10:50:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 43E4F8E015A; Thu, 23 Jun 2022 10:50:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 368A38E0144 for ; Thu, 23 Jun 2022 10:50:59 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 061FC34429 for ; Thu, 23 Jun 2022 14:50:59 +0000 (UTC) X-FDA: 79609787838.23.46CAE21 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by imf19.hostedemail.com (Postfix) with ESMTP id A00961A001B for ; Thu, 23 Jun 2022 14:50:58 +0000 (UTC) Received: by mail-lf1-f54.google.com with SMTP id f39so18151289lfv.3 for ; Thu, 23 Jun 2022 07:50:58 -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=gx5BulmdWVt1E6J23Q6sWTUkZpDqVLFQzvPT6hFPLlw=; b=zFPWnFhORhhkx+K6C2WQvQM0YSy+ZbfRPmzcQLsty0RSOgd+5dgld9MCRIQ56cNSRK BCnClixQqpL7OFP/+tRWG1VBGjAlAcE8nDR1yKu9FAfO39DLsaWvqo7E8phYLKhdHn5x /OnNOgxfX3uytsUOosIdIHz6LvZu6wTX+qQEK1PEN6Py9mGCUTJEWhQ827qs34DAAMD7 lNFvFBB1BJqKZEBaIHQJG/Ip0/M4QLNQdIh00w//KELVSTh4dbSVMXiXkhuSlhcBwSyp OdEG1BVxEEkxeYlEP/S71/GXCS8L542kaiqVa6Ghai1qeB/4D4YZWX3qHzUD0YsJcJ/M aSAw== 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=gx5BulmdWVt1E6J23Q6sWTUkZpDqVLFQzvPT6hFPLlw=; b=uy3VKQJ/r36iub/xsCPtK5ykrMe77Vmo4wqAkLzLz+Ou4Xq46l8zWwqpvdw6VWyz8r YC7L4yLDRtOx323xNzfJdoUF+JptupbobSLNngXAWWz2XEQIBKjxsT5gt+NhXoLMVJiL qRIitoICJQmZcS5z4hQuv25zglKC6o3N7Cao9eHpthYHeQkc5RKIX0av3/lk9KC14oIF mPbbB8hqQMehpX4WUNLJtSRmiqIhGJ1dwXyMo6x6l52X8ifXi0t9ph/6QpTTRsmuYSsY sqx5WkddS8Jv0Few4XRIjNzEJapP/yS3IgzfHWoC3/KgM/DKziWMaioOMoSXD5QZOJft vpGg== X-Gm-Message-State: AJIora959Ef2tEBEFo1n/ORp5BSvAtBmSCBMZC0k8R1xd/ZtPtSq0gkl N5I0J8ziBe05KL3ZytMPwUiGcw== X-Google-Smtp-Source: AGRyM1uTnBSEDsDu11OjnHjb3FojldgzsC1VUsNRLNFNCtzVtvGbYs9IJOhajOCoRwBTb/baBFXjSQ== X-Received: by 2002:a05:6512:3b21:b0:47f:665a:bf50 with SMTP id f33-20020a0565123b2100b0047f665abf50mr5720843lfv.673.1655995857250; Thu, 23 Jun 2022 07:50:57 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.129]) by smtp.gmail.com with ESMTPSA id i8-20020a2ea228000000b0025a59470621sm490327ljm.26.2022.06.23.07.50.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jun 2022 07:50:56 -0700 (PDT) Message-ID: <58cbf16e-ae4a-b6c5-f2ef-ab9fb3d29baf@openvz.org> Date: Thu, 23 Jun 2022 17:50:56 +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 2/9] memcg: enable accounting for kernfs nodes 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; imf19.hostedemail.com; dkim=pass header.d=openvz-org.20210112.gappssmtp.com header.s=20210112 header.b=zFPWnFhO; dmarc=pass (policy=none) header.from=openvz.org; spf=pass (imf19.hostedemail.com: domain of vvs@openvz.org designates 209.85.167.54 as permitted sender) smtp.mailfrom=vvs@openvz.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655995858; 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=gx5BulmdWVt1E6J23Q6sWTUkZpDqVLFQzvPT6hFPLlw=; b=anWdrlzpcsCcMYSgPA5nxVsBPmNfA+3kgWDGVlKriwBUPplOjNQjbDkskvwv4F4CCS3kLT bUcX0UoMZke+5J42wuLEdikEp6DkqsENrV29la5GH5UPsw1DUCuWctsXzUFgIFLpuUNLh9 7wvETk+aRIUN4fTHdEI1R7n/OdVs1qA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655995858; a=rsa-sha256; cv=none; b=wrJHWzw4T/LNE3QBk7jRxI4bDqKyQTUwzkgV3dGx7preP9UVJNzmedPN4+VV26MGQlb/9r CFyOPVjmefdQLSIZ1N8y9+11VNWPzaWtpMc5gWB87Ou9MDxOeS3eY3rpezOpI6LfTWQo4N FZ08Et9ogclr0zB3RMz1X4ueTUcvYTM= X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: A00961A001B X-Rspam-User: Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=openvz-org.20210112.gappssmtp.com header.s=20210112 header.b=zFPWnFhO; dmarc=pass (policy=none) header.from=openvz.org; spf=pass (imf19.hostedemail.com: domain of vvs@openvz.org designates 209.85.167.54 as permitted sender) smtp.mailfrom=vvs@openvz.org X-Stat-Signature: s8ssf1sayi3pfrzd5p5ihtfhf9bxtdkw X-HE-Tag: 1655995858-812860 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: kernfs nodes are quite small kernel objects, however there are few scenarios where it consumes significant piece of all allocated memory: 1) creating a new netdevice allocates ~50Kb of memory, where ~10Kb was allocated for 80+ kernfs nodes. 2) cgroupv2 mkdir allocates ~60Kb of memory, ~10Kb of them are kernfs structures. 3) Shakeel Butt reports that Google has workloads which create 100s of subcontainers and they have observed high system overhead without memcg accounting of kernfs. Usually new kernfs node creates few other objects: Allocs Alloc Allocation number size -------------------------------------------- 1 + 128 (__kernfs_new_node+0x4d) kernfs node 1 + 88 (__kernfs_iattrs+0x57) kernfs iattrs 1 + 96 (simple_xattr_alloc+0x28) simple_xattr, can grow over 4Kb 1 32 (simple_xattr_set+0x59) 1 8 (__kernfs_new_node+0x30) '+' -- to be accounted This patch enables accounting for kernfs nodes slab cache. Signed-off-by: Vasily Averin Reviewed-by: Roman Gushchin Reviewed-by: Michal Koutný Acked-by: Shakeel Butt Reviewed-by: Muchun Song --- fs/kernfs/mount.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c index cfa79715fc1a..3ac4191b1c40 100644 --- a/fs/kernfs/mount.c +++ b/fs/kernfs/mount.c @@ -391,7 +391,8 @@ void __init kernfs_init(void) { kernfs_node_cache = kmem_cache_create("kernfs_node_cache", sizeof(struct kernfs_node), - 0, SLAB_PANIC, NULL); + 0, SLAB_PANIC | SLAB_ACCOUNT, + NULL); /* Creates slab cache for kernfs inode attributes */ kernfs_iattrs_cache = kmem_cache_create("kernfs_iattrs_cache", From patchwork Thu Jun 23 14:51:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vasily Averin X-Patchwork-Id: 12892816 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 6F90DCCA47C for ; Thu, 23 Jun 2022 14:51:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0953A8E015B; Thu, 23 Jun 2022 10:51:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 045D48E0144; Thu, 23 Jun 2022 10:51:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E77D78E015B; Thu, 23 Jun 2022 10:51:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D8E2B8E0144 for ; Thu, 23 Jun 2022 10:51:05 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id AF5E7808DA for ; Thu, 23 Jun 2022 14:51:05 +0000 (UTC) X-FDA: 79609788090.26.1EE65FC Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) by imf23.hostedemail.com (Postfix) with ESMTP id 5FF371400AD for ; Thu, 23 Jun 2022 14:51:05 +0000 (UTC) Received: by mail-lf1-f46.google.com with SMTP id a2so33791359lfg.5 for ; Thu, 23 Jun 2022 07:51:05 -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=buhJIxm8AqBO3bD99fC3A2PxIb9sSGllubXvwSLnjxI=; b=i/p1o/M8klz+95et0bgwJpltVKqCgK9M54afMq5vmjuCLAEfL2lvisExr0IgdMekvu tf1cimXjbPEFVWhzrSItzE1007SR0q12B7VZHtXazaQnKiyuWs4PSjAymxaW1j4O4P5d H3Jwm2v+2F+Bhhn5f1R8Q7OuwGM/ffLuUOy62bmulvutMKsnJhX/4NJnD4FRSVZQ/oZB R21gnYF30vDTNsNNc7Zri6ut8pZGbuCIKB51DHmUPpayYIR3ZTeU9z7xYQqjQ8TxdE1T UT5uMmYOuNDiJaGtg0ApIfWOb4pLIKsf7jLnMytt0GlIYkqXy4hVbvifv+enr8R0hnOM JuQg== 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=buhJIxm8AqBO3bD99fC3A2PxIb9sSGllubXvwSLnjxI=; b=dshvrQR+UEfgZGKbXgOpJX/Oby58q3KInsU3ORk1H3VxkkJ/JBgeJBS2mthv8hpuo5 Aau/atXcjo3kr7UewysWO39boSq76RLu4hQXDBMHfwvky3uBdSlmYIZA1v279v6+fu86 aO3mcLiLqwkM1/t6QfV9JxqQO3xj8tlBgw+5IYX7VrBp7hRDIrga4OtV7+DAxew69DXc 6szOWOv0BiRir1qZSEWZIkJJIr7zjZeL/xO/kOcbYxaqjGsdtJnrxAyHOMWpihmDfeDN x14MJ6cATqPHFGvFPcrbQ18R+8uAY4tPUhLc4nf3Xl7Xy6h4vCkpJ8tZPrQQShMKQKWd qLOw== X-Gm-Message-State: AJIora+guzas+vnGRm+/4OpAJ8EESFnFKqg6WQHmeVqGqIFcOwuT+pnE AyY5mSvsGfNBs9VABmpws6dlHw== X-Google-Smtp-Source: AGRyM1s9nRJMZXHQY6aNsU9CgmRfXjPefvAMOQyBH3yS4iOM/J39zAOpv9yr4y+2zq9TSeoa52DsCg== X-Received: by 2002:a05:6512:2811:b0:47f:6d20:6a71 with SMTP id cf17-20020a056512281100b0047f6d206a71mr5674081lfb.60.1655995863995; Thu, 23 Jun 2022 07:51:03 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.129]) by smtp.gmail.com with ESMTPSA id s19-20020a2e2c13000000b002558e1bec75sm2827343ljs.5.2022.06.23.07.51.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jun 2022 07:51:03 -0700 (PDT) Message-ID: Date: Thu, 23 Jun 2022 17:51:02 +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 3/9] memcg: enable accounting for kernfs iattrs 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; imf23.hostedemail.com; dkim=pass header.d=openvz-org.20210112.gappssmtp.com header.s=20210112 header.b="i/p1o/M8"; dmarc=pass (policy=none) header.from=openvz.org; spf=pass (imf23.hostedemail.com: domain of vvs@openvz.org designates 209.85.167.46 as permitted sender) smtp.mailfrom=vvs@openvz.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655995865; 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=buhJIxm8AqBO3bD99fC3A2PxIb9sSGllubXvwSLnjxI=; b=6X+Gcq2ElGgUnJQSu89yxnaJAvF05DhU2QQeihckfkSwLInAOvi2bZc9reLw2GYI39IfZN fdZ/TfKW45xETwFi81yj9Rn+3DdcTq9XmyG5UWjYOLsijqRNVENyZs+hD86RFY6/7jkAT4 DQGYQLCSWHSLauSynWS08dm8A5AD4J0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655995865; a=rsa-sha256; cv=none; b=CI5X5R0qnxOSvDAxJvaPd2PLMLiJgDhexOALL8zEJHOBVJU+MtxHtBgSg3kFbuY/KDXbW8 GF3G1JnfIYEsBg2tV8D6FjEZIMUkYAoQDL/j2Hs6ZL80pBmhkL447dOaQUOhXhificpsif mHa8myx8jR3LAM6HQAmWyFXkL0RjyPo= X-Rspam-User: Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=openvz-org.20210112.gappssmtp.com header.s=20210112 header.b="i/p1o/M8"; dmarc=pass (policy=none) header.from=openvz.org; spf=pass (imf23.hostedemail.com: domain of vvs@openvz.org designates 209.85.167.46 as permitted sender) smtp.mailfrom=vvs@openvz.org X-Stat-Signature: o8crktgrr654fiinxp8mgjd3qoc36sxh X-Rspamd-Queue-Id: 5FF371400AD X-Rspamd-Server: rspam12 X-HE-Tag: 1655995865-101809 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: kernfs nodes are quite small kernel objects, however there are few scenarios where it consumes significant piece of all allocated memory: 1) creating a new netdevice allocates ~50Kb of memory, where ~10Kb was allocated for 80+ kernfs nodes. 2) cgroupv2 mkdir allocates ~60Kb of memory, ~10Kb of them are kernfs structures. 3) Shakeel Butt reports that Google has workloads which create 100s of subcontainers and they have observed high system overhead without memcg accounting of kernfs. Usually new kernfs node creates few other objects: Allocs Alloc Allocation number size -------------------------------------------- 1 + 128 (__kernfs_new_node+0x4d) kernfs node 1 + 88 (__kernfs_iattrs+0x57) kernfs iattrs 1 + 96 (simple_xattr_alloc+0x28) simple_xattr, can grow over 4Kb 1 32 (simple_xattr_set+0x59) 1 8 (__kernfs_new_node+0x30) '+' -- to be accounted This patch enables accounting for kernfs_iattrs_cache slab cache Signed-off-by: Vasily Averin Reviewed-by: Roman Gushchin Reviewed-by: Michal Koutný Acked-by: Shakeel Butt Reviewed-by: Muchun Song --- fs/kernfs/mount.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c index 3ac4191b1c40..40e896c7c86b 100644 --- a/fs/kernfs/mount.c +++ b/fs/kernfs/mount.c @@ -397,5 +397,6 @@ void __init kernfs_init(void) /* Creates slab cache for kernfs inode attributes */ kernfs_iattrs_cache = kmem_cache_create("kernfs_iattrs_cache", sizeof(struct kernfs_iattrs), - 0, SLAB_PANIC, NULL); + 0, SLAB_PANIC | SLAB_ACCOUNT, + NULL); }