From nobody Mon Apr 27 13:49:44 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54140C43334 for ; Thu, 23 Jun 2022 14:50:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231920AbiFWOu6 (ORCPT ); Thu, 23 Jun 2022 10:50:58 -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-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> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 Acked-by: Shakeel Butt Reviewed-by: Michal Koutn=C3=BD Reviewed-by: Muchun Song Reviewed-by: Roman Gushchin -------------------------------------------- 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=3Dpsi_cgroup_alloc+0x1e 1 + 96 96 288 call_site=3Dcgroup_rstat_init+0x5f 2 12 24 312 call_site=3Dpercpu_ref_init+0x23 1 6 6 318 call_site=3D__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=C3=BD 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 *pa= rent, const char *name, =20 /* allocate the cgroup and its ID, 0 is reserved for the root */ cgrp =3D kzalloc(struct_size(cgrp, ancestor_ids, (level + 1)), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!cgrp) return ERR_PTR(-ENOMEM); =20 --=20 2.36.1 From nobody Mon Apr 27 13:49:44 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64D34C43334 for ; Thu, 23 Jun 2022 14:51:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232026AbiFWOvE (ORCPT ); Thu, 23 Jun 2022 10:51:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232023AbiFWOvA (ORCPT ); Thu, 23 Jun 2022 10:51:00 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4CFA46B3E for ; Thu, 23 Jun 2022 07:50:58 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id i18so20153536lfu.8 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=5xqtjW74eoTHoLa0YLbYU/8NMFpeCAcEzUCcdypXhz0DMTfF1NUxis+I69mKmEPg6A SkzARHi/nIPMC9ENMNiGpnjRNXAVlXhMzWCqrxo7uLtp1WbQLvr7TVJQLQewPGtpHSzC pzOQp0ehi/mCPlSuN5cLLiJY2AMLBDqIFaXE68xUZIM6yiAZ8HkZDHwv7MC4bF4dtn9X i0DKkp8TYIeIrpUzevLhJnhGVc7LarIjnlLESE5fAn6KnrVQNKgi63oC7FE3zJHKqXD2 Gitlw/RGOPlHnfw+09/QyrFb+XKn3+R+kHpyKZREWcUoAzUweW0hjgZLIfKYlzFva2Ow Vvow== X-Gm-Message-State: AJIora/+/ws5a6VSMct/Nq1qR+ZRA35R01P3d0X4Y5thfI6J69ZhRmTa zNrNka456OGGA09IPo/zHVW0UWy01FNkpA== 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> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Shakeel Butt Reviewed-by: Michal Koutn=C3=BD Reviewed-by: Muchun Song Reviewed-by: Roman Gushchin -------------------------------------------- 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=C3=BD 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 =3D kmem_cache_create("kernfs_node_cache", sizeof(struct kernfs_node), - 0, SLAB_PANIC, NULL); + 0, SLAB_PANIC | SLAB_ACCOUNT, + NULL); =20 /* Creates slab cache for kernfs inode attributes */ kernfs_iattrs_cache =3D kmem_cache_create("kernfs_iattrs_cache", --=20 2.36.1 From nobody Mon Apr 27 13:49:44 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 919ACC43334 for ; Thu, 23 Jun 2022 14:51:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232035AbiFWOvK (ORCPT ); Thu, 23 Jun 2022 10:51:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231890AbiFWOvH (ORCPT ); Thu, 23 Jun 2022 10:51:07 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACE6146CA9 for ; Thu, 23 Jun 2022 07:51:05 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id w20so33753143lfa.11 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=ooavryFFdV7JF9tZCP+h5KoaVXP8jEpe5acR0aTbIQO1rDVF+/KqNokotUoeM1GssZ zYAXCs+icAt+8sWAPqlbybwl2HoOZeKONk1nOzn0LTMU/EMfXrI+dNL0d1EH09jG0IZR WXYPOJjBF9/ipZlnSE7FY6PY/x1IRMn7Bhk1MKlDYDJkUAP+05NvsveCXTJPUQmJZmeq x2Lkj0wyK8aZsoUEX/WGG75y6fTihc+YYZ9Di/nQUCA3fL+axKubSw2aD2HXlH1x+vcq FYYVat48szHNnCdBLWDDIFj/GQVK3hz/TEvAb+uzVYc//8A3mcW1sQP18fmK3ziHRPOa QG4w== X-Gm-Message-State: AJIora9E8kfm3TYMoWqyHtQ6fGpiLTB2XDWntbIj2nSsuP5abev6sgFU 2q6O/VleRU76SQaLH2TuKSt5Gw== 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> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Shakeel Butt Reviewed-by: Michal Koutn=C3=BD Reviewed-by: Muchun Song Reviewed-by: Roman Gushchin -------------------------------------------- 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=C3=BD 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 =3D kmem_cache_create("kernfs_iattrs_cache", sizeof(struct kernfs_iattrs), - 0, SLAB_PANIC, NULL); + 0, SLAB_PANIC | SLAB_ACCOUNT, + NULL); } --=20 2.36.1 From nobody Mon Apr 27 13:49:44 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 548A8C433EF for ; Thu, 23 Jun 2022 14:51:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232039AbiFWOvY (ORCPT ); Thu, 23 Jun 2022 10:51:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231890AbiFWOvR (ORCPT ); Thu, 23 Jun 2022 10:51:17 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8DD54707B for ; Thu, 23 Jun 2022 07:51:13 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id s10so23575592ljh.12 for ; Thu, 23 Jun 2022 07:51:13 -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=k8OfFf3zteeGV4NoXsW7mYQBRm/UT3jxMOm3SilJFI0=; b=hsg2w+abNmxBuNt4Iv4r+V21/tVetnU4U/D2SV+gm392hJCFDklntUJOdfxD3yiiPB MvGH3he8zMgV8AYjS8QEzaWnf3xrJB9UhPqWdSpP+22GycMOwBSKrGK7aJI0AfhBEPL2 2NAxJyMQ816jqIBDzXSq4r4bLuH82L0hneLKdzdBxFx3SI+2TxhhWeT7s/0YEabpfnTG 6MBUo28BBuCeUwV6cMOrM0zubkHeEB1KFTTA4V0riTQBjXFDcFelIFctLJlb4yTs7sM7 XEx9XLZ9Sh20UTK7vVfDEkaniIvsLVt0dL4fjbigg+OME17vZ4F8f7WcUs3ubT10zDlJ FNbw== 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=k8OfFf3zteeGV4NoXsW7mYQBRm/UT3jxMOm3SilJFI0=; b=e8m4VZCpp3xVVM+ktPz2evq4KHJbmyDxtRGHIavVR+rcZqD9YaxMR5RuaZkQwUM6T+ XsM4MSqCKCz7O7zkziKhKiI3sfecXYqNQeeKrBpimKHm5JT1CJSDWd9iBHnQ7TwUisO9 SVgwGM1bjxkY6tPFQQoIxOgqNVkHMxkBxAEYgNN9kmEcO819ATD7NC1RmiH0ZaVRK0b6 F0mgZL9JfSgwLrwFACrklcghGX4lKLE6zuIKxzVxpfnsk53FT7VZLrrdVNJXRAjx2TxI sRYKfCG85gaQbLL6aWfU7INuaq8vjHpiOBFnKPq8m1FgDK+K6IOCM2wvFzf9Ccmjrkur OCdw== X-Gm-Message-State: AJIora99Nu9waL7COVgsjMGafcDzOueRVX8Za3nsiiOVHynRFAWLiyKF t9Cyn9kwJ9rnY5hYld+MLH/H9g== X-Google-Smtp-Source: AGRyM1vQgmT9L5cc+RG2sEr65xPeqzzwssWUnhh/SDAvla0mPtj3N0Dc6e5uRv4S9hq2r/hbwJI8Ug== X-Received: by 2002:a05:651c:11c1:b0:25a:8968:b834 with SMTP id z1-20020a05651c11c100b0025a8968b834mr4871877ljo.212.1655995872261; Thu, 23 Jun 2022 07:51:12 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.129]) by smtp.gmail.com with ESMTPSA id a4-20020a19ca04000000b0047255d210dcsm2247637lfg.11.2022.06.23.07.51.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jun 2022 07:51:11 -0700 (PDT) Message-ID: <97e05495-d74e-275c-0739-8abff974cdc5@openvz.org> Date: Thu, 23 Jun 2022 17:51:11 +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 4/9] memcg: enable accounting for struct simple_xattr 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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Shakeel Butt Reviewed-by: Michal Koutn=C3=BD Reviewed-by: Muchun Song Reviewed-by: Roman Gushchin -------------------------------------------- 1 + 128 (__kernfs_new_node+0x4d) kernfs node 1 + 88 (__kernfs_iattrs+0x57) kernfs iattrs 1 + 96 (simple_xattr_alloc+0x28) simple_xattr 1 32 (simple_xattr_set+0x59) 1 8 (__kernfs_new_node+0x30) '+' -- to be accounted This patch enables accounting for struct simple_xattr. Size of this structure depends on userspace and can grow over 4Kb. Signed-off-by: Vasily Averin Reviewed-by: Roman Gushchin Reviewed-by: Michal Koutn=C3=BD Acked-by: Shakeel Butt Reviewed-by: Muchun Song --- fs/xattr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/xattr.c b/fs/xattr.c index e8dd03e4561e..98dcf6600bd9 100644 --- a/fs/xattr.c +++ b/fs/xattr.c @@ -1001,7 +1001,7 @@ struct simple_xattr *simple_xattr_alloc(const void *v= alue, size_t size) if (len < sizeof(*new_xattr)) return NULL; =20 - new_xattr =3D kvmalloc(len, GFP_KERNEL); + new_xattr =3D kvmalloc(len, GFP_KERNEL_ACCOUNT); if (!new_xattr) return NULL; =20 --=20 2.36.1 From nobody Mon Apr 27 13:49:44 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3251C43334 for ; Thu, 23 Jun 2022 14:51:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231890AbiFWOvk (ORCPT ); Thu, 23 Jun 2022 10:51:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231467AbiFWOvh (ORCPT ); Thu, 23 Jun 2022 10:51:37 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD90C47AF3 for ; Thu, 23 Jun 2022 07:51:30 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id z13so3298780lfj.13 for ; Thu, 23 Jun 2022 07:51:30 -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=waMbR4Vj3d2Yx3tC82MaoYQ2maUSxBJAR+0Iakz5FDI=; b=YNvr4xo3AtwQzeXJO0a0Zs/pJf/cfhwOyUbueOMf0dW7rfYbzeNXzzeTckjXHZagnx IL85gF0d8dj8iu8D/NKKFFpKBqeU48c+utRpVkVyvj5DixZAKXeknlRq8N2LyZGOTi+R hGN8BepYHBGzguV4vsrHooHWcagsJSb29bCFzzGcw2QHmp3PiwCLs5lRYky96HtSBt7M EA4L0Sp+aBwKz/fZyvAIqFUTbxk9l9Tji0K20GNE67AGI98/zeiTxuFXgKawjUa1NN+o 2Sces7CzSgUk2DMCdi7DOn11celMtSmNASSbOpBFHfM4AG9IAqxKziAlLGfROZMJkciM MZ7A== 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=waMbR4Vj3d2Yx3tC82MaoYQ2maUSxBJAR+0Iakz5FDI=; b=eVb7q0NciLN4dUwc27r/5JwctJmI3FoOSikRUmfjMBJ2wHmvFpR2wvjQcCyOea6pJw imlsAQSQU8OQmI2zbINWuOtapJSnZAQgOvSnfjJ414CEp/x8yv6FK6qIB4i1BGOx2TpA xRNcJZy++sk2CCTTsxg0LOX2xdathp5VzJXvAULjnpl0RaS9/P/pyLwFRPWOsxy9XtRa LmwokIa7MwyQyqvbe/pawieX8VkMIbR0kFzgzPaVKMK20QlcBj1VrWYWTglIeGsmRnI+ up6C59z0AdlpbYX9/05TZ9+NBJWN1iwZjeBT7wesZD6xmhg2aTUYh0P1XhYL+kPSXVcE 42Ig== X-Gm-Message-State: AJIora9wtyX5ZONdLn5AvLtOPJe4PzE6FswCg4fGraW5ZDC13gOKVIlD /xjI9n8XxTY0H3Gba/lvZPQmNA== X-Google-Smtp-Source: AGRyM1vjQLvKYp0+eENX0/rDukz52soKH3xoEj53Z2BfUrKic9B7uCsBN+XLEWAdw3JqKLyNVVN0kA== X-Received: by 2002:a05:6512:228c:b0:479:7a60:5e0c with SMTP id f12-20020a056512228c00b004797a605e0cmr5584521lfu.323.1655995890370; Thu, 23 Jun 2022 07:51:30 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.129]) by smtp.gmail.com with ESMTPSA id s16-20020a056512203000b0047fa40b5052sm354193lfs.62.2022.06.23.07.51.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jun 2022 07:51:30 -0700 (PDT) Message-ID: Date: Thu, 23 Jun 2022 17:51:29 +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 5/9] memcg: enable accounting for percpu allocation of struct psi_group_cpu 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-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" struct pci_group_cpu is percpu allocated for each new cgroup and can consume a significant portion of all allocated memory on nodes with a large number of CPUs. Common part of the cgroup creation: Allocs Alloc $1*$2 Sum Allocation number size Acked-by: Roman Gushchin Acked-by: Shakeel Butt Reviewed-by: Muchun Song -------------------------------------------- 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=3Dpsi_cgroup_alloc+0x1e 1 + 96 96 288 call_site=3Dcgroup_rstat_init+0x5f 2 12 24 312 call_site=3Dpercpu_ref_init+0x23 1 6 6 318 call_site=3D__percpu_counter_init+0x22 '+' -- to be accounted, '~' -- partially accounted Signed-off-by: Vasily Averin Acked-by: Shakeel Butt Reviewed-by: Muchun Song Acked-by: Roman Gushchin --- kernel/sched/psi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index a337f3e35997..0da10159d3d9 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -957,7 +957,7 @@ int psi_cgroup_alloc(struct cgroup *cgroup) if (static_branch_likely(&psi_disabled)) return 0; =20 - cgroup->psi.pcpu =3D alloc_percpu(struct psi_group_cpu); + cgroup->psi.pcpu =3D alloc_percpu_gfp(struct psi_group_cpu, GFP_KERNEL_AC= COUNT); if (!cgroup->psi.pcpu) return -ENOMEM; group_init(&cgroup->psi); --=20 2.36.1 From nobody Mon Apr 27 13:49:44 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E7BCC433EF for ; Thu, 23 Jun 2022 14:51:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232091AbiFWOvt (ORCPT ); Thu, 23 Jun 2022 10:51:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232066AbiFWOvn (ORCPT ); Thu, 23 Jun 2022 10:51:43 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3EFB473B3 for ; Thu, 23 Jun 2022 07:51:38 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id s10so23575592ljh.12 for ; Thu, 23 Jun 2022 07:51:38 -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=fYBLg0GorDblKEye4tioxlFuzZ/2NCtjLKl9KE3W8YI=; b=ilILMVAcvthPkldn+Fa+LkoIG/WSsFH8M7YG6eZI6EykQ+3oB7c4PdbWYXjZqjJ+43 FWPcHN93ez+UtYY/3FGn60gVrWz2wmHIsFXq/TFUle1S2965DVGnZ+G7T88vtlrYFmp+ yXP01mugIN86XV+s+rNzVqBycfic42Rq5VXNV9DBPQH+yuwZrrP0STBifVHqjRAjGW7J uYweDn2FveDwN4KUNlAFLo/+FqPrpfOFrs2q/44dDgBdmYC7a4GXjqZwPQuqOjaHf6cx cJOheLE1U00l7XXoRAwkq1Qbu9NV/7vftEsfDxwdNHKeI9Z/sKkWD5mRMqV1KP3cgxL5 p0uQ== 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=fYBLg0GorDblKEye4tioxlFuzZ/2NCtjLKl9KE3W8YI=; b=l9ENv4Baen5jOF06CNeSK49bwX81KWspE3qJVYZJYzFpf35MNiNuUYNlFJC9OVq+NN WyIVpcuABJFYicrl269AB4z0IJgE21c8iexA6QHNnHTb8M8s0WfonmQDD9ffYTRmKhJn 3wlpOmnrxRHR1H18/YXMn/JC9DbHPwHi7/mRyP4JKY3YG8vgp7xIDVOuKqnuF/GYGQEw ifoCU+FIBOxTodI4d3I9/IEooAVPo4Paf/Up6a9t9U1+pwBkgldukLfNlCtNj5Punu55 liB6Z9Cad0C1rTCqyuYWnpBPx/tJh0fWPxrUJTZSpK4P9piDJqh+lEBEwf1Hc4RNEuHI bmQA== X-Gm-Message-State: AJIora/rdj+dJk0tx189WWWNlXoAxxAjNUN3YUG+qLk7SPL6TFKO/z7v 97Thi2z6ncaEO11BUYZnoZ+T/Q== X-Google-Smtp-Source: AGRyM1udS3E55vm1oyA4f9dG+HCY/f/metx7YC5LCY/7klXf+OChmEahji97QdNkhTvrkhGGH6yfag== X-Received: by 2002:a2e:2418:0:b0:25a:662e:5051 with SMTP id k24-20020a2e2418000000b0025a662e5051mr5149208ljk.137.1655995898416; Thu, 23 Jun 2022 07:51:38 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.129]) by smtp.gmail.com with ESMTPSA id q5-20020a19f205000000b0047255d210easm3025736lfh.25.2022.06.23.07.51.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jun 2022 07:51:38 -0700 (PDT) Message-ID: <9c7957f8-ba89-4c9a-bd61-d86bca18a546@openvz.org> Date: Thu, 23 Jun 2022 17:51:37 +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 6/9] memcg: enable accounting for percpu allocation of struct cgroup_rstat_cpu 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-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" struct cgroup_rstat_cpu is percpu allocated for each new cgroup and can consume a significant portion of all allocated memory on nodes with a large number of CPUs. Common part of the cgroup creation: Allocs Alloc $1*$2 Sum Allocation number size Acked-by: Muchun Song Acked-by: Roman Gushchin Acked-by: Shakeel Butt -------------------------------------------- 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=3Dpsi_cgroup_alloc+0x1e 1 + 96 96 288 call_site=3Dcgroup_rstat_init+0x5f 2 12 24 312 call_site=3Dpercpu_ref_init+0x23 1 6 6 318 call_site=3D__percpu_counter_init+0x22 '+' -- to be accounted, '~' -- partially accounted Signed-off-by: Vasily Averin Acked-by: Shakeel Butt Acked-by: Roman Gushchin Acked-by: Muchun Song --- kernel/cgroup/rstat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c index 24b5c2ab5598..2904b185b01b 100644 --- a/kernel/cgroup/rstat.c +++ b/kernel/cgroup/rstat.c @@ -257,7 +257,8 @@ int cgroup_rstat_init(struct cgroup *cgrp) =20 /* the root cgrp has rstat_cpu preallocated */ if (!cgrp->rstat_cpu) { - cgrp->rstat_cpu =3D alloc_percpu(struct cgroup_rstat_cpu); + cgrp->rstat_cpu =3D alloc_percpu_gfp(struct cgroup_rstat_cpu, + GFP_KERNEL_ACCOUNT); if (!cgrp->rstat_cpu) return -ENOMEM; } --=20 2.36.1 From nobody Mon Apr 27 13:49:44 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B904C43334 for ; Thu, 23 Jun 2022 14:51:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232085AbiFWOv6 (ORCPT ); Thu, 23 Jun 2022 10:51:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232080AbiFWOvu (ORCPT ); Thu, 23 Jun 2022 10:51:50 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68F334739E for ; Thu, 23 Jun 2022 07:51:49 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id t24so21560670lfr.4 for ; Thu, 23 Jun 2022 07:51:49 -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=RJ0ABL9uCwvFv63ZyK8hl1S+g8awXPTVNvHTVH+sSkA=; b=VgAQKKEsiHE7SoRPkk1oRDOCQig2wAGOd4W/o+dF2VxecW1m7m7A8NKaTdjY6rAajT mVPbyprusIoCKB4TPm6SHYIe3KpCqQ4pzIY7CbdHfGyr5ORXzNRmj2PRvHPzPDQPueHn Z76hXIZzwuiGUftMNpZoKoWS9xthi1G7AC/Ew2GNKdBfQqhZ3MUsCmNqCVzvGpl9wzfU sa/0UyQ27uVR+L11DOohImUdZ4+okomUQIW1WXxaGaYIvE/q5N8bZW/ooU71RpIi+Eo/ iAM0GC4i5D9/nVN8TJEWbT3QYi7fwJCEyg7P3n9TS/6boGeH0zIjxQU8xKVtxvk7K9A7 5rYw== 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=RJ0ABL9uCwvFv63ZyK8hl1S+g8awXPTVNvHTVH+sSkA=; b=cL7OAnrtdwTBpN1LYIQ01rnxK6RIPhskT4wLpEmRakhV3BhX9feKvaYsCM5pXbMBhQ u+ONAyRMerfl8a2wo3hrx5/eDL0RSBPGmoFwXy7VcAZzYnzBCEo3IxAupGjTyBLxoV3+ Y/QHgaavPz65/ayCejz86viXgVWbMjiE/dahJ71Y18dvd5BZvxyjXf6cIdfIZ5deVLBt dNXDNefKGSvsVEtnOh0NRK8cBBooYFw7a61tGzxmT6wxU7aEgOmxSZr4LunU1XbkE5uO X0rSsYDMXCfPskDTUhYWX2jqMDo+dhX9M9We5xEn7N4ubvA/GWsGr0Tu5/6m71qpVT8f emJQ== X-Gm-Message-State: AJIora/c9RSOsX5kKDNLgsRXD6NVw/8irpqMURNyFmd6Rdv6vJHIC7Tn BzQBOXuGg+Prc1QYSz+xwWRDPw== X-Google-Smtp-Source: AGRyM1v+wrtYYFhb0JXolKG7l98gJTFPDw4sPts1HZmI4WNoqYhmZ/QU9LxTvX7ieU9TzkpzKZmNyw== X-Received: by 2002:a05:6512:2247:b0:47f:5dff:2eef with SMTP id i7-20020a056512224700b0047f5dff2eefmr5689792lfu.493.1655995907826; Thu, 23 Jun 2022 07:51:47 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.129]) by smtp.gmail.com with ESMTPSA id bd7-20020a05651c168700b0025a8ef49c64sm342231ljb.140.2022.06.23.07.51.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jun 2022 07:51:47 -0700 (PDT) Message-ID: <045740af-d2a0-a81d-cbb6-153649705087@openvz.org> Date: Thu, 23 Jun 2022 17:51:46 +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 7/9] memcg: enable accounting for large allocations in mem_cgroup_css_alloc 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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Creation of each memory cgroup allocates few huge objects in mem_cgroup_css_alloc(). Its size exceeds the size of memory accounted in common part of cgroup creation: common part: ~11Kb + 318 bytes percpu memcg: ~17Kb + 4692 bytes percpu memory: Acked-by: Shakeel Butt Reviewed-by: Michal Koutn=C3=BD Reviewed-by: Muchun Song Reviewed-by: Roman Gushchin ------ Allocs Alloc $1*$2 Sum Allocation number size -------------------------------------------- 1 + 8192 8192 8192 (mem_cgroup_css_alloc+0x4a) Reviewed-by: Roman Gushchin Reviewed-by: Michal Koutn=C3=BD Acked-by: Shakeel Butt Reviewed-by: Muchun Song --- mm/memcontrol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 85adc43c5a25..275d0c847f05 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5257,7 +5257,7 @@ static int alloc_mem_cgroup_per_node_info(struct mem_= cgroup *memcg, int node) { struct mem_cgroup_per_node *pn; =20 - pn =3D kzalloc_node(sizeof(*pn), GFP_KERNEL, node); + pn =3D kzalloc_node(sizeof(*pn), GFP_KERNEL_ACCOUNT, node); if (!pn) return 1; =20 @@ -5309,7 +5309,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void) int __maybe_unused i; long error =3D -ENOMEM; =20 - memcg =3D kzalloc(struct_size(memcg, nodeinfo, nr_node_ids), GFP_KERNEL); + memcg =3D kzalloc(struct_size(memcg, nodeinfo, nr_node_ids), GFP_KERNEL_A= CCOUNT); if (!memcg) return ERR_PTR(error); =20 --=20 2.36.1 From nobody Mon Apr 27 13:49:44 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A0AEC433EF for ; Thu, 23 Jun 2022 14:52:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231698AbiFWOwK (ORCPT ); Thu, 23 Jun 2022 10:52:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231467AbiFWOv6 (ORCPT ); Thu, 23 Jun 2022 10:51:58 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6ADF047543 for ; Thu, 23 Jun 2022 07:51:57 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id y32so33804313lfa.6 for ; Thu, 23 Jun 2022 07:51:57 -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=hqvRcJBRW/zXn9o8PLaPnPcK1byd11F8xwtbZSlj240=; b=L3GdFJ5msAUKjEBgJr8tC0Ye/uf5rOW/nTjACFOPDVkM4uV2p2NICHRx0qbgkWRrHW xye3mNc9OUGNDUkdfVMWc+YCL7Uw2FtXXna0LVEbGKFaP1NtOR9VxXehiJAtnQEze01M zD25I3FxU8/N5GjP9dXmVKZL2giwMWH1O04S/yKV3I/NnfvtJbiXvpW1ovOGu9+QwMgj GBDOyIDuwc8e82tKToKvcUFx39aq2ki+Tp6x/9ooZM/+FRKSWkYPJ3fK+x6UXHRL0vlb /b9h4l4s9Eg3vjeZyOWNwEHeOq/ax6nMC3d26/bpwKwaZyykWOqIebfDdRo9GEwfGrzZ C52A== 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=hqvRcJBRW/zXn9o8PLaPnPcK1byd11F8xwtbZSlj240=; b=JH/8JGUmgR6Bedd/x8+0Ip1I60a/KTlTNQQJncxCTJLY3LsjMELTUaQB1fztiuGUSh e8tdKAl8yEPV1DvCK6YOCg7ru35+7nCegez5SJKDVbm/bYQSLe8CA78ijPY4EwTeJ01i tjXhylaX4kr6KKR60Y7lHKBDIX11hATMgv1NfOQqUkrGmgdm6/I98Qr0cZ+fu/ymk57F qO8Cvo12wxWYGlxE+peVq93tZqs3mewFOOZXvDvIaM9qE1oteRQJtP25o1sm8kFIBmGH IDE/vWhwN3x4cdFXUdKIK3BHLPGbEWADRHlekRlTPsjoKF91bq77CSgZ1daP93C6MMBc +TVg== X-Gm-Message-State: AJIora/u7sNsfkS6oPQxGUbF9ByRy1Y0L3hhGh3ttl8b4b5ZL09q2dlH z95Q7t/SJZ1g2d8KpAcuL6z9eQ== X-Google-Smtp-Source: AGRyM1v6I/+vDXiKc4oKtXa6cXcr1Fi2ubJWusXb8148nVz1lt5JY6qWafShI9FEMt2PZmgT4xszhw== X-Received: by 2002:a19:f207:0:b0:47f:6890:60b0 with SMTP id q7-20020a19f207000000b0047f689060b0mr5440246lfh.327.1655995915827; Thu, 23 Jun 2022 07:51:55 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.129]) by smtp.gmail.com with ESMTPSA id s3-20020a195e03000000b0047861cba7bdsm3019220lfb.53.2022.06.23.07.51.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jun 2022 07:51:55 -0700 (PDT) Message-ID: <6a0f9fb4-2ddd-8ad0-4f2a-d3780c1d9397@openvz.org> Date: Thu, 23 Jun 2022 17:51:54 +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 8/9] memcg: enable accounting for allocations in alloc_fair_sched_group 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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Creating of each new cpu cgroup allocates two 512-bytes kernel objects per CPU. This is especially important for cgroups shared parent memory cgroup. In this scenario, on nodes with multiple processors, these allocations become one of the main memory consumers. Memory allocated during new cpu cgroup creation: common part: ~11Kb + 318 bytes percpu cpu cgroup: ~2.5Kb + 1036 bytes percpu Accounting for this memory helps to avoid misuse inside memcg-limited contianers. Signed-off-by: Vasily Averin Reviewed-by: Roman Gushchin Reviewed-by: Michal Koutn=C3=BD Acked-by: Shakeel Butt Reviewed-by: Muchun Song --- kernel/sched/fair.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index e8202b5cd3d5..71161be1e783 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -11503,12 +11503,12 @@ int alloc_fair_sched_group(struct task_group *tg,= struct task_group *parent) =20 for_each_possible_cpu(i) { cfs_rq =3D kzalloc_node(sizeof(struct cfs_rq), - GFP_KERNEL, cpu_to_node(i)); + GFP_KERNEL_ACCOUNT, cpu_to_node(i)); if (!cfs_rq) goto err; =20 se =3D kzalloc_node(sizeof(struct sched_entity_stats), - GFP_KERNEL, cpu_to_node(i)); + GFP_KERNEL_ACCOUNT, cpu_to_node(i)); if (!se) goto err_free_rq; =20 --=20 2.36.1 From nobody Mon Apr 27 13:49:44 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA83FC433EF for ; Thu, 23 Jun 2022 14:52:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231915AbiFWOwa (ORCPT ); Thu, 23 Jun 2022 10:52:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232140AbiFWOwH (ORCPT ); Thu, 23 Jun 2022 10:52:07 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 893294833B for ; Thu, 23 Jun 2022 07:52:04 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id c30so23591400ljr.9 for ; Thu, 23 Jun 2022 07:52:04 -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=GpreIe1vVrFK0GRTTTBCrmu4K38+/AoKp6X51SotBdU=; b=2uzehPa+7Yh1/1yI1Z5UrlQSBeyJcy6RsaVimJTiqlPLLRwUTOoHga1Wb1egu6p0wr H4yVijZAlfpr1xU4lEH1LNys0LFqKbKhTvHcKfJN0QQnqLklYEEUW4JNuFdZP9h1Zlmu pgUzAi4h5gzZMlV5HEAx9NHHw8mHh72qr5FZF9tx+uUOCdvUuPNtzgsxyZItchwHqvwc 27BKuqvxrJvJkYcdvswWerNHUVfq4ecN5rBvXuLkqYoXEhXdLKw9vWYgZvIb6gFgw7Ec QNjDw3kOBNAZtq1hleAu9lG2BqZJu4Y1MITm+G0yIj7c0AYmDdz9vRi8wuTMvlSLeK+8 uS0g== 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=GpreIe1vVrFK0GRTTTBCrmu4K38+/AoKp6X51SotBdU=; b=4QjUnY7JM4fxue/gTbuoLwmrzmVboF4cWm5TIW0mpDVNehUWKMOAryYKcIvMp22Ioh GbMZs9b4iyhz/n8MUX9FCtCfQo7ACq6QewPJx2P/IYVk8QDY4jNgxeLUdLV+ZPggzKN6 0j20GMbT957DWrAT3skwLze3P4PQ1pCO6Mb5wE6HkfSjFLkp5+Y2b/E0sPpGlLSfq9gg /fn2YXa1l/WgfDvXuW/uYJmo/PvEBCtSjLJfJzkS9Xa35ujnFz7DY5yUNiHoM7arDLJn kalsHZAWoyR852o5haRJ9Yysznbl0XnCmmbTufgQQ05+ugh8E+4aA6h6w8bJcQt3ha+U 293A== X-Gm-Message-State: AJIora8Z6wlDWW7o/OgubcJwOmRsfwRSvZVrc6H5h8GTqVM7KjlLrxYa 2w6Nr2bAS5mkX/2WVXuINsBFNYUSCjSFQQ== X-Google-Smtp-Source: AGRyM1tPC+bd/t6EAqAmy50rsGPhX0wzCtEVeqe8450OaAKfA0Mm3KD6F91h0GbMVpg/lGxD+y3qSw== X-Received: by 2002:a2e:2e07:0:b0:25a:4bb3:a2c2 with SMTP id u7-20020a2e2e07000000b0025a4bb3a2c2mr5083546lju.450.1655995922945; Thu, 23 Jun 2022 07:52:02 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.129]) by smtp.gmail.com with ESMTPSA id n16-20020a2e7210000000b0025a6f7000c0sm1547457ljc.11.2022.06.23.07.52.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jun 2022 07:52:02 -0700 (PDT) Message-ID: Date: Thu, 23 Jun 2022 17:52:01 +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 9/9] memcg: enable accounting for perpu allocation of struct rt_rq 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-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If enabled in config, alloc_rt_sched_group() is called for each new cpu cgroup and allocates a huge (~1700 bytes) percpu struct rt_rq. This significantly exceeds the size of the percpu allocation in the common part of cgroup creation. Memory allocated during new cpu cgroup creation (with enabled RT_GROUP_SCHED): common part: ~11Kb + 318 bytes percpu cpu cgroup: ~2.5Kb + ~2800 bytes percpu Accounting for this memory helps to avoid misuse inside memcg-limited containers. Signed-off-by: Vasily Averin Acked-by: Shakeel Butt Acked-by: Roman Gushchin Acked-by: Muchun Song --- kernel/sched/rt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 8c9ed9664840..44a8fc096e33 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -256,7 +256,7 @@ int alloc_rt_sched_group(struct task_group *tg, struct = task_group *parent) =20 for_each_possible_cpu(i) { rt_rq =3D kzalloc_node(sizeof(struct rt_rq), - GFP_KERNEL, cpu_to_node(i)); + GFP_KERNEL_ACCOUNT, cpu_to_node(i)); if (!rt_rq) goto err; =20 --=20 2.36.1