From nobody Tue Apr 28 18:07:54 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 B2A76C43334 for ; Mon, 13 Jun 2022 05:36:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232173AbiFMFf6 (ORCPT ); Mon, 13 Jun 2022 01:35:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231950AbiFMFfZ (ORCPT ); Mon, 13 Jun 2022 01:35:25 -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 CF88713D70 for ; Sun, 12 Jun 2022 22:34:44 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id s6so7071642lfo.13 for ; Sun, 12 Jun 2022 22:34:44 -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=vVFg1kFJ1ZrAuYqNU+G4M2YG4vffoF6tfug6s1kVYgc=; b=Tu0ulCRi9G/dXEAfgaijmX0Oo+JHLmSXnmrJ+MEuxOIvzY3vhXf0LacSOeN87REMdt 0EqL9howlhfqHTYOCyGIVa5yxvuBcSAQ+J5glfRzw1ieygNZvfqcNJp/hQEadqGHIoBk cVwK70e7kA/PCPZ5d4ZK0wPzt33x/rXcNf75GLCkQJ4/9yah+076fyA0Mwtpd4DFVtTE OEe7Av8QYdWetO9Jfkjje1xVuCyvJXcNowOmDKUgUK2/xylEl0nTMyJoPhlRkQlkUliw H6ZJSkmEBCbS2XIUcoiGJCr8kg+4ug0gZ3OfnLNzV6l/B7ci7LgBuBznFgJr3hgP3NQw hYDA== 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=vVFg1kFJ1ZrAuYqNU+G4M2YG4vffoF6tfug6s1kVYgc=; b=pbi/rpIIlXyJw5tgqdYjznyXtuAtwmrNionhWyHrwbBcro4LuatLE5RCHWRdkEnBP1 SlSRRtaRn0FpS3FJXwakWcLQ6usB1vYvdQqiu8HshkT58y6ceslIpiPesB1w//KH2eO8 0MgaPyO7cvdRRCO3GIIk8T7q+gdcXTxN0KlYYOTAhR9drVAA4KC9SppJ7cIuS4l+uabB 6l1/SNXgYQGO3n57ZDHLOXNBnNerjJOgZNB1P2P8frMc4ZnzQ1wzczYHGfwoYkFh9riP IsKYF2IUqB/V7iR+gu2mJecLBPFtzApRiLRHx74pWVZ9CRhC+iHqzH3OwPnvQiWE8Ji2 JzgA== X-Gm-Message-State: AOAM533anyUiay8xiiHbiO2uT0R9QghCVfy3phzr4cI/vSUwtomFFtcr cVtc1pQFRQaej3CYu/VXi5QWrg== X-Google-Smtp-Source: ABdhPJz9g22UtbqUqRQrAPjssQkh/JLrsa/hrQftvJymHjpwcOduOutW0vw/76d3RMB9I39vIXRfzw== X-Received: by 2002:a19:5f1d:0:b0:478:f072:8dc9 with SMTP id t29-20020a195f1d000000b00478f0728dc9mr35072871lfb.440.1655098483186; Sun, 12 Jun 2022 22:34:43 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.129]) by smtp.gmail.com with ESMTPSA id p13-20020ac246cd000000b0047db8b30670sm845259lfo.136.2022.06.12.22.34.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Jun 2022 22:34:42 -0700 (PDT) Message-ID: <4c393a46-f6cf-ce8a-7771-81cbbc9ca278@openvz.org> Date: Mon, 13 Jun 2022 08:34:42 +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 v4 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: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@openvz.org> Content-Language: en-US In-Reply-To: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@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 90a654cb8a1e..9adf4ad4b623 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 Tue Apr 28 18:07:54 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 C116AC43334 for ; Mon, 13 Jun 2022 05:36:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230308AbiFMFgD (ORCPT ); Mon, 13 Jun 2022 01:36:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232622AbiFMFf0 (ORCPT ); Mon, 13 Jun 2022 01:35:26 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 637281147D for ; Sun, 12 Jun 2022 22:34:51 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id w20so7079090lfa.11 for ; Sun, 12 Jun 2022 22:34:51 -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=LHjwdf838XwqeAg8Nc229RaNa822fvU0tfolsDGvnGxgxaJJuYInYiO0Y1/se6H3N6 eSoUNfXTq9ViSfUVk2pQROnPmYKfyqjdabi2PzdI6GG3YDyJ5KbeVprN7xizrKfczl27 oOY7dL2b1sgAGsJuu4L85fjavdMcXTonfnkDG0f5Jzl1kQ0sCxoscdmXVUTlU68okhJ9 DA2ifBo1oc1LVvm7vn9bzJDoKJzCFuVoyuYtsarZnQ2xx/H/7LiOz4uBg3Y+Rt39vvxR KoGRxRNLkoNOToIZ57RKjPfuqae0oHimGFLyGLLEXdqDL//s5b3jDkGgcS6OD1N4fHA/ ob2w== 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=moybEzllanTKZDz4RM0JypXFDB1NreFkjfszciViLvEIK1N+BG6uy74wzyZzz7jRoE BUX/cIzP09jRdbyhG/7ovOk6XGgTJ5aZgNmyyN2QJohcHrO21Kh722Bb4YoIy4mbrPaN tMDsbGi4HnxRP0wQ7juoVJQ+ne3vPlitd/J+3ZQWAR51/hzafBTnmuaB6PF1l/z7lbsJ Q+9JEw65qBovdzxBUk5e73ZHdh0fABXZbCvJy/tH+OGkwpRstfT8is2Z9LneUNi48Kmn mBa6Ynbpl2iPE3u8j6HevJvXIvBko+4n29imddxENNhwQ4vfKjuQ0bo5i9xmBKSy5fMs D2Kw== X-Gm-Message-State: AOAM530mX9I7H0rgbECTMWVZ4uVCKAnxIisYh1Ld3pRely8fKUffQqyw POdT1G64V/Q0hXA9MwG5of0JuQ== X-Google-Smtp-Source: ABdhPJxwvjjFC+nbS7k4Hx0PfOGges13cDVPl80sm9xEZjEmzUcmZNS/oNjeKVJPRMV+PlaFVGkQxw== X-Received: by 2002:a05:6512:130c:b0:477:e2ea:396e with SMTP id x12-20020a056512130c00b00477e2ea396emr78241747lfu.489.1655098490971; Sun, 12 Jun 2022 22:34:50 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.129]) by smtp.gmail.com with ESMTPSA id d22-20020a05651c089600b002553768424esm879156ljq.112.2022.06.12.22.34.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Jun 2022 22:34:50 -0700 (PDT) Message-ID: Date: Mon, 13 Jun 2022 08:34:49 +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 v4 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: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@openvz.org> Content-Language: en-US In-Reply-To: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@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 Tue Apr 28 18:07:54 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 08346C433EF for ; Mon, 13 Jun 2022 05:36:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233222AbiFMFgJ (ORCPT ); Mon, 13 Jun 2022 01:36:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233204AbiFMFfa (ORCPT ); Mon, 13 Jun 2022 01:35:30 -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 86487FD05 for ; Sun, 12 Jun 2022 22:35:00 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id s6so7071642lfo.13 for ; Sun, 12 Jun 2022 22:35:00 -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=poLeG6zhCv/e/uvaonfvqyZcWLUQoZKI6x1zrBYzR8yEcLqX5MJjRu0DpBmK0UieGM 9s8GkMwlIhLIZoQPjVePmWg9+eHaw3B/mxAbv92cla9k0nTwF0/t7OND21vBl/jnCbIU IRCipafuU6E/GhmoUqu9xNvZBtbB5Z528WMihwahUcILGFkidaBexjc14Cq8pW8Z7Pvj N7AfutKNP8hBX8d3mBRFD1w6M6/KhKiGE+zL5Mh/NHBVYzb1srbsoyGopRzu/uGFFuO0 9CT6RkUDfugqIiBXyVg6DD3bipqyjO7hrVYqc1/pWq903VKpx9vz96zgU+w6o/ZlFCvC 9x1A== 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=iui6TLodh35ocJ5nQIkwuurKw+RzC1IIhcT9ocHNESEeibOPT+d7e2GS2NS34scHpj o30pz1DWZAN4JXlt8jornb2mrUEGKHVmN/UL1CUQJM97D2yG1iDRss6HxfOC5rt5YZbv L9Lf5cblf94eJw4rcrnOh0WWaRaeFpe1WXHWCtZ7eWQxWLHbV6m+LOx2fyMt2wtyvhbK Sws1Zxfs8QOY4oFfEHecytNPpUuM7rkpTnCPezAq3UQJ2k/Qz3aGn3D33kIZpiIRQEeU Ew23r+XWGaQ7Thsfr4V2+zZ2frEvhTSdLBCowvTKqZt2aHT3HVQeHSQwyHeU6Ybs7FO/ Wo9w== X-Gm-Message-State: AOAM530EnxqfGm2+J778dr2ZzIdW29B9n/gXeXx81/Lk1p4JU2NP81X7 hXbzn1/abPxP/PP0iI21DKsgyw== X-Google-Smtp-Source: ABdhPJz8mC+oy5QTxd+FVDFv22laevGRjje04Lf2wVUa8G+vhmhElanXbHdoiJIbuGw58hKsSQKOWg== X-Received: by 2002:a05:6512:2249:b0:478:f926:ad7 with SMTP id i9-20020a056512224900b00478f9260ad7mr38742258lfu.511.1655098500094; Sun, 12 Jun 2022 22:35:00 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.129]) by smtp.gmail.com with ESMTPSA id j2-20020a2e6e02000000b002555c9d5d7fsm894992ljc.11.2022.06.12.22.34.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Jun 2022 22:34:59 -0700 (PDT) Message-ID: <647143fa-2521-10ae-2c4d-41dbb74d00cf@openvz.org> Date: Mon, 13 Jun 2022 08:34:59 +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 v4 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: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@openvz.org> Content-Language: en-US In-Reply-To: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@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 Tue Apr 28 18:07:54 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 2CC92C433EF for ; Mon, 13 Jun 2022 05:36:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232995AbiFMFgY (ORCPT ); Mon, 13 Jun 2022 01:36:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233350AbiFMFfe (ORCPT ); Mon, 13 Jun 2022 01:35:34 -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 771F61261E for ; Sun, 12 Jun 2022 22:35:09 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id a15so7097461lfb.9 for ; Sun, 12 Jun 2022 22:35:09 -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=QCCq2RzIkfRwteIiJbTj0Zzj5B4WLYxGewaFjiLQoUpyY6C9/Jm2Kois2pCwI52eRl UWOOFNQGDLwx1lliCTUM0VlyS1cfr43JGICQoEtjpMgxRtJrEiG+o2Aer69l3xQbvAMO 17aLlEwsCfIfrW9BO251dX2yEKDMW4oh9hb6fWYUavQ77/aSKnjKqBFskE9d7rWE3tRX f8vJkhfg1+am5rI9o/1tQmSF0l6xMThUXR/eOThEQ0riKpRPQhouMRKgLTnMtRUS5vGF b7jkhFk1BQHlwczmyMTCNI2SUCBYRAdsDib0POvKjJEOl2kbFpgAMhR4/4VnYLmAp7Bh bz/A== 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=6rF1GCHAvAL16WSRvHPpVaiLFRzjiyZUAhyBD9+P27myMKuYGkG+yygVoExtVrj/BI a9MFNzk1eOiiPaJnxbMF/e7M1awab8xJtvQ/jP9aWc/WtH4/51KYP3ZtJJRGSJT5ZAT4 SJv4x7H/RYkyCvvSN1Fj+x9nDUgvkiFhDJcfsl7q1RkScBMk5EbDicUMIwSAmxOjI6cR M9NPI80zV4UdOc6P4FGm27bRO2OxDP+Zae77jXev1ZilJP1RbSVUKJjjyufgO80c/MvD 8Ki9E7FcpjFh4Z3CHUEs2A376WUpuB3m99g79uSRDsPION/ZWPR/oqyOoXb+SjYJksR4 1Zfw== X-Gm-Message-State: AOAM531r9iMbxtw/kdY0dIFJ6i2cjhMGh99QUU2Hwi3KeaLDU77m0Dek IiD3q2czGCbYxIl1fV1df34Puw== X-Google-Smtp-Source: ABdhPJxlklyclOFDaFEDttumwb5rFLdd5oyZnDa4Qw5e8gcdQoX+swRc3jh5ZNuvaf2KIiJcxFlz/g== X-Received: by 2002:a05:6512:2252:b0:479:4fc9:f651 with SMTP id i18-20020a056512225200b004794fc9f651mr21452200lfu.247.1655098509032; Sun, 12 Jun 2022 22:35:09 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.129]) by smtp.gmail.com with ESMTPSA id i20-20020a056512341400b0047255d211c2sm849476lfr.241.2022.06.12.22.35.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Jun 2022 22:35:08 -0700 (PDT) Message-ID: <82caac31-1dbb-d3af-185a-6469c93f7a48@openvz.org> Date: Mon, 13 Jun 2022 08:35:07 +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 v4 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: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@openvz.org> Content-Language: en-US In-Reply-To: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@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 Tue Apr 28 18:07:54 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 20226C43334 for ; Mon, 13 Jun 2022 05:36:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233586AbiFMFga (ORCPT ); Mon, 13 Jun 2022 01:36:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229799AbiFMFf4 (ORCPT ); Mon, 13 Jun 2022 01:35:56 -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 C36F811151 for ; Sun, 12 Jun 2022 22:35:19 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id a29so7142137lfk.2 for ; Sun, 12 Jun 2022 22:35:19 -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=B3zm8wtF1vA2GYm2+mdF7egB2sMmmpE2kcaPBaO2eto=; b=aNTN9ecStVPQ2d3BHO8r2ERVbHTttzP8TpBGu400gwgeTcHpH5cOc8cGKcJF5B4VSG Pl404daaNaSR+XfYhnMPIJuJDZNnXll9sSKc8Bl7DpIBinOElRj9Cdogfo8nhbIPgz6H LEhnRv6PLI/1q4OQhQVbZHRXsvpYNjKANwS6bgzq+oxPSUzB7Oijv5PyZP6r2dUx8G0b 5/U0JAHLUzb4KnI6Ev9AKyFvBj77iQEV+KqIkwQ1NbPYXEy0SxOYw8Yaln47mLwPQ3Ko TdBRQtjCGU4GK/9EIclgy8Gop96FJszFi5oVXiUUTrnqwe52akMXbhog8arLPS0+Gyux fXRQ== 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=B3zm8wtF1vA2GYm2+mdF7egB2sMmmpE2kcaPBaO2eto=; b=4lWfaxcQMmE/r5zgNxarulPq2jwnRqqMH9zXUXglNM9T4zMxsPCZKksUjHlejEGdJg MeIBgxYiJxYA6hlseadcxjCAKdGxadr1BqfYCCjm3RfAX+JOw4D/6ix67x82aEIENFfl ni0lKt4cvMnXDE+4vYue2DXkz0Ck2Fx6RmUS8nbnp0Ch1baq1QiUEHTkTJFVIqfOJACB MkFoW4AC6quxwl4rqxyvB0XSFZKyOwpnOQWi0QpbZbPx2uXKf2J+BlFuvQzPzW0JEJvD vnmzBxmfgXdyikjk9YEbZ0QfWnklB/AYn9ntTaNWVR+G6kyr6yjrdId3p1OEAg6cL20g WP0A== X-Gm-Message-State: AOAM531K4O+UcB72gvzcHKyxjPdKIsn43UvbYpQYQyIbcrbKYNrNs91E YIB6zwk2gXQ9bJl3fnKai/Nqlg== X-Google-Smtp-Source: ABdhPJyFjrBYaSumRmMWd09J6whp9J9igWSZ+y3nTisSme3IrGUsLbSkT5Qvc8TfA25hMj3+GYM3JQ== X-Received: by 2002:a05:6512:1595:b0:479:1e0a:283b with SMTP id bp21-20020a056512159500b004791e0a283bmr28839782lfb.141.1655098518177; Sun, 12 Jun 2022 22:35:18 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.129]) by smtp.gmail.com with ESMTPSA id s7-20020a2eb8c7000000b002556a17e193sm875735ljp.38.2022.06.12.22.35.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Jun 2022 22:35:17 -0700 (PDT) Message-ID: <33151594-4168-d01b-56b6-dc996d226a7d@openvz.org> Date: Mon, 13 Jun 2022 08:35:17 +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 v4 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: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@openvz.org> Content-Language: en-US In-Reply-To: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index ec66b40bdd40..c95e87269fc5 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -957,11 +957,12 @@ int psi_cgroup_alloc(struct cgroup *cgroup) if (static_branch_likely(&psi_disabled)) return 0; =20 - cgroup->psi =3D kmalloc(sizeof(struct psi_group), GFP_KERNEL); + cgroup->psi =3D kmalloc(sizeof(struct psi_group), GFP_KERNEL_ACCOUNT); if (!cgroup->psi) return -ENOMEM; =20 - cgroup->psi->pcpu =3D alloc_percpu(struct psi_group_cpu); + cgroup->psi->pcpu =3D alloc_percpu_gfp(struct psi_group_cpu, + GFP_KERNEL_ACCOUNT); if (!cgroup->psi->pcpu) { kfree(cgroup->psi); return -ENOMEM; --=20 2.36.1 From nobody Tue Apr 28 18:07:54 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 2755CC433EF for ; Mon, 13 Jun 2022 05:36:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232709AbiFMFge (ORCPT ); Mon, 13 Jun 2022 01:36:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233588AbiFMFf5 (ORCPT ); Mon, 13 Jun 2022 01:35:57 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFA3E11479 for ; Sun, 12 Jun 2022 22:35:28 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id c4so7088517lfj.12 for ; Sun, 12 Jun 2022 22:35:28 -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=zIUP7XJmmGybhomix4qhj4dsvVJz3qpTtmJxAHZo+FS3qMKA29sQ0rVxITb06XZqrD nZC+ARODXgb3uW8IID/NoPvHZF9I+vmsgg6S2S3doreOAfToddHYk1Xvd8rWktSA8nfW ahOnjls08LK/iVwueICAsn0ZIC7TfutQY9y1bJsENsR5gcnyHgUNUiHtMrbOcicbvOE2 QVKi01RzoRWCS8SpdjYkxAJRvKM/V18mk3VtVZeCBa7GBMjYuZ9WMAr51wHQPnrptMvn 8xgK0UlON2cwUtsy7uUQEVj443cXKJL8OSjA3MdZI+qOZ/kfjJeo689lqFDEg/SHaxHZ d7mA== 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=PnwwsaPHTVe4TvOuKQKYrfyPT5bpp475FCglbfSULdPg0fRRImA/fc3ERSWpi9uRNj RNnZ1HUFHL900ObGaj/AQzeUHE07i02xRpBycuIR3xuHuaFTNA6/DlN1jGaYlSXXmmep 6lJ8gqnpUHCdbt3KI5FejyzWbJzWaYmdW9KcfSHzNxb0/Pif3BSPN71Hg49IExIwT44D Y0iFO0954WjN4OSEfrfD25Yw68DcUGvKcJgy1YsPAYGsNDp+VPwEPSsg/QFQFwUdkifd 96Zo0+XZwyt3E4NemJJFzGGvty1Rf20EGxBlVbjIgPekhOKdohj/UxdHMO7o2VKafnB5 t/nA== X-Gm-Message-State: AOAM530erNCd+x7M0cJBWcWEDKw9hWGcBzWg3jclTc5AOtqIlJuxbpba H5VuWI36vWXeKN5GeNpSKE67smFrN5R7zw== X-Google-Smtp-Source: ABdhPJzvN/XuMilatlDTG99FEYXRhOvXWQuq2fWz3UrzAYP/w/zAkDHEQehBYIW4xnHBlzBchtcVjQ== X-Received: by 2002:a05:6512:2614:b0:47d:c632:896b with SMTP id bt20-20020a056512261400b0047dc632896bmr5177459lfb.532.1655098527149; Sun, 12 Jun 2022 22:35:27 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.129]) by smtp.gmail.com with ESMTPSA id j21-20020a05651231d500b00478f3bb79d6sm845297lfe.194.2022.06.12.22.35.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Jun 2022 22:35:26 -0700 (PDT) Message-ID: <05bcd9df-970c-f8f8-0577-9dbb164b1180@openvz.org> Date: Mon, 13 Jun 2022 08:35:26 +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 v4 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: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@openvz.org> Content-Language: en-US In-Reply-To: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@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 Tue Apr 28 18:07:54 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 F1838C43334 for ; Mon, 13 Jun 2022 05:36:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233027AbiFMFgi (ORCPT ); Mon, 13 Jun 2022 01:36:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232781AbiFMFgD (ORCPT ); Mon, 13 Jun 2022 01:36:03 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE22712A9E for ; Sun, 12 Jun 2022 22:35:36 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id h23so7138107lfe.4 for ; Sun, 12 Jun 2022 22:35:36 -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=LySdGa6WSWuP57DyggEJLR/XgrjUl+fsCS3/BfNoxBo=; b=MMQLuUr/04JdD6h+bOSVzq6FkKGW1jK4dRUQ5RRZgULnPkx8ZPAbdMfROKB0f01oM2 xtYIkf9112uEUuIkZV/zBrk6d7Ru8iB3LRi1ee260+FrR1jNCqxsW8hBdTa4M6TVqb42 PNJS7FJvKSSTEmrzL+Jgf91ADt0Ca0zpmxEJhBKqzC84MYEsuwd+4SSmote16X1Mvqps kvUAWAoCgOTXygT1y7N5+eb0PZ5bGR63mHbra6sZ3h+5LaEY7aZRoJ9G2vwSfkzRDk/M otgCOEA+Ecp2xbajvZSrKQmj9agTuFAAuD9tN2aAfrcL5UdcrflBlsakdQrPqksA4xT9 i+GQ== 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=LySdGa6WSWuP57DyggEJLR/XgrjUl+fsCS3/BfNoxBo=; b=tNRlCgeYD4B/75f1WWIXQn2YcOpk4YR1xTdGQVjefzj3cSXdXCavsiXS2hLAUEjIPx IaHHMicPb+5YvIwTkiVerLKPIKvO2xXQHiUx13KRNsJlPt6qrLii5FECYwRKf3Cz7Fh2 xKChit9vmECT38dDnqkZerZE9PqJuZfioPMPyltcKQCbT9ugPvim7wd836I6TIZCwEcs APUef1nz+S7red1sQdiKhJTk/KFm6nUGyyLIHY/t1In0ew1Sd5u891JR48tqwRvfGbrU 0KoBXBEYxwDArE3SFTYwKuKRWMkecErcSQAJKWha8VkrPEMnBpIUu0NEsmrFvDmfgZen 9f7g== X-Gm-Message-State: AOAM533nBCQXH9l7lZMt6HBThmQdllcZZk6Vc1hn3sPyQjbG58Q9AjrX UEc0FLowtoMZUXy6SSMjm28OJQ== X-Google-Smtp-Source: ABdhPJxMkyKV5vTx93A1xGgc69W892dcXfu6ndsf9V1Krre+8NazIcBvdEnZNLY1jvfV+XYxmOL/zg== X-Received: by 2002:a05:6512:ac6:b0:479:2bdf:749 with SMTP id n6-20020a0565120ac600b004792bdf0749mr27273040lfu.686.1655098535032; Sun, 12 Jun 2022 22:35:35 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.129]) by smtp.gmail.com with ESMTPSA id y2-20020a05651c020200b002557df3669bsm880245ljn.21.2022.06.12.22.35.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Jun 2022 22:35:34 -0700 (PDT) Message-ID: Date: Mon, 13 Jun 2022 08:35:33 +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 v4 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: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@openvz.org> Content-Language: en-US In-Reply-To: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@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 27cebaa53472..a8647a8417e4 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5086,7 +5086,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 @@ -5138,7 +5138,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 Tue Apr 28 18:07:54 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 D2883C43334 for ; Mon, 13 Jun 2022 05:36:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235292AbiFMFgq (ORCPT ); Mon, 13 Jun 2022 01:36:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234418AbiFMFgR (ORCPT ); Mon, 13 Jun 2022 01:36:17 -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 92A0712ABC for ; Sun, 12 Jun 2022 22:35:44 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id w20so7081867lfa.11 for ; Sun, 12 Jun 2022 22:35:44 -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=58aW1GKW2Xnc6hX7c4ajeoo5cdVM2VXNCWYj3+RmWPIsMMcEya9nceDLXfxdDuL1RJ vFqjZjdUplMMnXO+GoNqLVSBeyv2codJ/Cdo/0P+m25U99sRmLSf87r3bRpz2KtogSHX nDg2iKGP1amPG4uJ/PV6KCiE/RHnOr64u2KfbnAupwelgVto6u2iX/YRnr6ea52wfDQH egQipz1wqYLmRlmNtCWxWVXO8L3KKQV9Wzlt3vZADHi8YHEB9nJ8HJIkn9dp8H0u3tl4 qFMxNsnU970ET5KhuiG5uGtXVrTkrI5+kltSmMicveonR3WCCFzn2uyzFuOg4dK17cO6 zlRA== 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=QqU3PTFGCmhuOEeAE6RPUqOzHl1/XDo1KFqbPeJp6CD+k83yV/7/517L+2r3nmLaw+ juryJNNniMYkwUAapRgO0aC7RhlaRZX6fbj7iOEEs/ofZ4iJIx+8xcjXHiptpzYPBYyH IcKLWcU0kBv4x+Q/+nFEwSAbYJyaAp7qWPrMm4c2rf8VdEM+3BWMI5r5Ef2Ch7U4lEJg 25ommTI6+/k4gIXm3t43tOh4HiOXwjI+zTdahZ1FjlAodZ7eW7/xZPJ8t6fi986pMSYp HurDeCUn8bc2cQsxeW/bxpMee2tKpFV+34KX+0WwSDr2ocblexT6RiLFjU6hhC9FgqAy XS4g== X-Gm-Message-State: AOAM533ZuLqy6NJUZDoWosQQ4uVc53eWYUBnySxX8wTMHcRZgYM5yk0T GZ3i0Mdo5146Ux4iQYbcYwQYYw== X-Google-Smtp-Source: ABdhPJxQBfYbPYKPzP4lAQx/hX3LHay0XfcAyKL3ncwHVwjrbKjWRsBcyYWQd752Gw7d8lUuqHGnaQ== X-Received: by 2002:a05:6512:3b07:b0:479:1535:b6e9 with SMTP id f7-20020a0565123b0700b004791535b6e9mr33502212lfv.494.1655098542761; Sun, 12 Jun 2022 22:35:42 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.129]) by smtp.gmail.com with ESMTPSA id w26-20020a05651204da00b0047863382e3dsm844618lfq.215.2022.06.12.22.35.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Jun 2022 22:35:42 -0700 (PDT) Message-ID: <813662e2-bb99-2339-04f2-48cfa0d385db@openvz.org> Date: Mon, 13 Jun 2022 08:35:41 +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 v4 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: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@openvz.org> Content-Language: en-US In-Reply-To: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@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 Tue Apr 28 18:07:54 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 7B40EC43334 for ; Mon, 13 Jun 2022 05:36:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235396AbiFMFgv (ORCPT ); Mon, 13 Jun 2022 01:36:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234620AbiFMFgY (ORCPT ); Mon, 13 Jun 2022 01:36:24 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6213E12AF0 for ; Sun, 12 Jun 2022 22:35:52 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id 20so7108650lfz.8 for ; Sun, 12 Jun 2022 22:35: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=GpreIe1vVrFK0GRTTTBCrmu4K38+/AoKp6X51SotBdU=; b=pOR7O1t5o1xCznms3YZVoDk//h+f8/fV4zwbTF71juOxY1C62zNSCCgDsAvK4WX+hN wsAJDy6ZwBwLoUy5BIB1oRNm4wHPLlfZ8DY1WmWTBalya5YxORe+47B+QWkq1whgFSPE NALVRGhpOBGJ8npvVljSdkejj7UwD33OQ3IXaaMzsb2YhN9Vd+x0GS1QdHn11aYnQdbh j81zIPiB/Y6l0WXfdX+sWHlsuHGnoM1TO/QbZl7dZQxj68I7nAVGUydJvYKOvwTV3L55 15XFDDiDYb79xpH1rJssMF4rPQd99yM34z3FIvgplvSdziiZXPCcdj7IYtwxn7W+CSWX tHaw== 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=feEX6H0TLhFTk3zZH2UNIp6I4TOQt11asETzsitNetgwJdh24FZCK1EDvyNHCR6QTK 7e23HUvlqqckF6D7ZWxGXVWwU/8V7gMr3TdvQXHDlnggjruaKMeKiAXFRGiJhIwUXVkQ Zz3sboWgc0rOwp4IUb4ZGDhZhj7DhpdTKow3imEOSRg1mAKKAl4y8pmAeaKADC0OMNjU iwR2Wr8rRFEaV32bxRi5OeC8R526xA1RfPqTqmUXCloxAKkF+LB3nSNyGvcPbOKJitGQ N6BCRtFcBWmHISMG+lm98R1vFNLv6C3t9GjjVb5RDeU+h4OmmPKBjWmZ0crE6+YqM+PG SU8Q== X-Gm-Message-State: AOAM531CowLEFFK8q5ay2SCgsBqaBr6Q98NFs2JLacnBXPaUJ/uAuII7 DWLZoNE7KJY39jWmTdqS4cKRjw== X-Google-Smtp-Source: ABdhPJxPvSt6k8AUnB6ZJ3SMXvAsv5IjtCPcbXB6Mfc+ct6OavP454s3ddoBvVuHhuA2+bplOYHLag== X-Received: by 2002:a05:6512:3dab:b0:479:56a9:d513 with SMTP id k43-20020a0565123dab00b0047956a9d513mr20487427lfv.531.1655098551395; Sun, 12 Jun 2022 22:35:51 -0700 (PDT) Received: from [192.168.1.65] ([46.188.121.129]) by smtp.gmail.com with ESMTPSA id m14-20020a056512358e00b00478ed80852dsm847592lfr.58.2022.06.12.22.35.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Jun 2022 22:35:51 -0700 (PDT) Message-ID: Date: Mon, 13 Jun 2022 08:35: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 v4 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: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@openvz.org> Content-Language: en-US In-Reply-To: <3e1d6eab-57c7-ba3d-67e1-c45aa0dfa2ab@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