Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp169760iog; Sun, 12 Jun 2022 23:06:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1C7Z2sZe6n0ZwvBG0FwZhydVbg3SBeXz9ma+oZCc7yIQn26zxEctx6CAL37ojt9l6nzCa X-Received: by 2002:a17:902:e889:b0:167:523c:6011 with SMTP id w9-20020a170902e88900b00167523c6011mr47692735plg.114.1655100367268; Sun, 12 Jun 2022 23:06:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655100367; cv=none; d=google.com; s=arc-20160816; b=bgtoL9jWj/4cJl2w40wUrk63gN6LmAUca04xRlzWJH1comkqtSYNCgTf6DbjtlovCW 3sM/Ie/RoEufl23CEXRtLmLOWNbAKodMfuzjxtegdBmC6h6Ozdh0YX4EzP8TzBmbTnvU fvDgxjybGNYK8exK68dYWp6R7AOQIj5VQI1uBD89ojc7UFnl264ydm2KdDb04RYJB0vc PZeZEOjkVSfxE9zBrBdpY185HaaaoF68r7GoIS8lbF5Fmr4/Ga6qXm/OyprIPKeke92X P8rHFmAwCLTuwq096Jzvktv4thxYFsu5GkZlUCyEhRGyvhxvFYwUm93siLUvQNRMc83q nfXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-language:references:cc:to:subject:from:user-agent :mime-version:date:message-id:dkim-signature; bh=gx5BulmdWVt1E6J23Q6sWTUkZpDqVLFQzvPT6hFPLlw=; b=dwu3/MXTCLUdM93v2+qDU00KDYdutGA6F/5XnDzPth5DqfjloLTPsy1KbQcvmzibpx f9NzUDt0dniKXn0AdQRyVBvo3WLonj0r06TgpsIUxvMXJxjNC22+XlgZ+vozMZmm1OFL lH7nf2axPw6VK2IEeA1yvFfPBsKnHCkzlHs4ObCNF7gy2swCcedUsv0nk2FVpi1MPZKw HjFsU/Ulyvpl6CIi/uc6zoUw4Xr4b0RfzO7m5pGcOx+3FPp+YolXqIdHkWzCfeb29gVO dZi1wuRZVcWHZe+BWKg1UHxINb6HuWY6kRzpeushL0XFqWL1biYH4VNngO2exWryGPsr Y4Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz-org.20210112.gappssmtp.com header.s=20210112 header.b=LHjwdf83; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvz.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e7-20020a170902ef4700b0015ea33c252esi8030524plx.234.2022.06.12.23.05.51; Sun, 12 Jun 2022 23:06:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@openvz-org.20210112.gappssmtp.com header.s=20210112 header.b=LHjwdf83; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvz.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230215AbiFMFgC (ORCPT + 99 others); Mon, 13 Jun 2022 01:36:02 -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-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: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org kernfs nodes are quite small kernel objects, however there are few scenarios where it consumes significant piece of all allocated memory: 1) creating a new netdevice allocates ~50Kb of memory, where ~10Kb was allocated for 80+ kernfs nodes. 2) cgroupv2 mkdir allocates ~60Kb of memory, ~10Kb of them are kernfs structures. 3) Shakeel Butt reports that Google has workloads which create 100s of subcontainers and they have observed high system overhead without memcg accounting of kernfs. Usually new kernfs node creates few other objects: Allocs Alloc Allocation number size -------------------------------------------- 1 + 128 (__kernfs_new_node+0x4d) kernfs node 1 + 88 (__kernfs_iattrs+0x57) kernfs iattrs 1 + 96 (simple_xattr_alloc+0x28) simple_xattr, can grow over 4Kb 1 32 (simple_xattr_set+0x59) 1 8 (__kernfs_new_node+0x30) '+' -- to be accounted This patch enables accounting for kernfs nodes slab cache. Signed-off-by: Vasily Averin Reviewed-by: Roman Gushchin Reviewed-by: Michal Koutný Acked-by: Shakeel Butt Reviewed-by: Muchun Song --- fs/kernfs/mount.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c index cfa79715fc1a..3ac4191b1c40 100644 --- a/fs/kernfs/mount.c +++ b/fs/kernfs/mount.c @@ -391,7 +391,8 @@ void __init kernfs_init(void) { kernfs_node_cache = kmem_cache_create("kernfs_node_cache", sizeof(struct kernfs_node), - 0, SLAB_PANIC, NULL); + 0, SLAB_PANIC | SLAB_ACCOUNT, + NULL); /* Creates slab cache for kernfs inode attributes */ kernfs_iattrs_cache = kmem_cache_create("kernfs_iattrs_cache", -- 2.36.1