From patchwork Sun Nov 26 14:49:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 169864 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp2513351vqx; Sun, 26 Nov 2023 06:50:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFwkQaXU2Xyb7XrBmMY4g97tNf0otf1vVWk9gOaMuTofYGq17iTBP+X7OVtb7EFCzpd2jEi X-Received: by 2002:aa7:930e:0:b0:6cb:ccea:e311 with SMTP id cz14-20020aa7930e000000b006cbcceae311mr7766214pfb.4.1701010199847; Sun, 26 Nov 2023 06:49:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701010199; cv=none; d=google.com; s=arc-20160816; b=M8DLmxizBg4bWjqTRZaaUoOn0jzwEBD/P3odeCNnm5BJVdW9BKnXZhOApn5apLFWT9 yORR1qdam+dKI+kHo1o0f7y/5ZZ0VauHTYHwioHgnWn3Li9MDFcZa/Ycxdc28B3CJcYN 7jhbiJJuG/26/7zfdtJ+ccOzTgXboq/To6Gyi3JT54Ej9fXD35+TNAReGIPEEsrmPu4v 76345hIZLORBn+qwSQNPEi7NMIeP68piP+fd5YWQTujvQRZclZaNmYdgacPa3lKXLg79 AiseYiSVn+CM++D1QsJhxGDwmNJMdxZDCBatAnrMDTgTpEetwbsxzigQj9+5aFgrudc8 is5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=iCucAYF477kNI1im5xQ/khbymwoZZ8iwxk7MzQbavyc=; fh=fBxk5GXNfDAEdtpnu5e+7MAG2qZqSwAWJGPMAwm0Bpg=; b=mxt8qehbZ/VcQsBw+Vpo3ieRGw2Dyg0YJUS5rym0WT2MLCf+bHE9knADbI9vP1eh1o LTIypnY9y/5NWt2ap/qSUFiAOfxkVwZ1I2trxPAeChoqjMb4GNKZVBIla1bsVyQKeF27 UjHzifVBzJZtRSRs6l7V7VMgHzU2b3tPjAn0F/956XhxQNj1fd/Y8ZjbQRi1CETV0uup XGKkjas5rPOwt/ky91S0jv3pK8+avA0c8fHs8HNwusMjAhC7oBI5aFUqDRlFenPT5zYl ap9XFwDMXCQj/y2UXzuZY3BM1gFJILaesOA2DORQ3xamAUP6NDZA45fpbyE3DsUA2RKz Gn+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=NxlB7LRX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id q11-20020a056a00084b00b006c3b92140ebsi7897517pfk.151.2023.11.26.06.49.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 06:49:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=NxlB7LRX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 01145805F87D; Sun, 26 Nov 2023 06:49:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230003AbjKZOtl (ORCPT + 99 others); Sun, 26 Nov 2023 09:49:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjKZOtk (ORCPT ); Sun, 26 Nov 2023 09:49:40 -0500 Received: from smtp.smtpout.orange.fr (smtp-13.smtpout.orange.fr [80.12.242.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B658192 for ; Sun, 26 Nov 2023 06:49:45 -0800 (PST) Received: from pop-os.home ([92.140.202.140]) by smtp.orange.fr with ESMTPA id 7GS6rtIcCmTW57GS7rbvab; Sun, 26 Nov 2023 15:49:43 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1701010183; bh=iCucAYF477kNI1im5xQ/khbymwoZZ8iwxk7MzQbavyc=; h=From:To:Cc:Subject:Date; b=NxlB7LRXIS360L+bGzATYs/jW1KNTT9Ejfv1fOlGUtvMipDIyLZnHUiKaypxBGKjp ivYgt/TkCjScIRNrB0Y9ajojgTnXQl/Qd+cZOS2yfXU2qeiH7/+KRaVilbuFEab3Fh AY1tGJNy2fXokJw2ONntvG5YtnY2jinFx16/y9zYMF2wK6roTVf8H2Ex62muzMemIB +zQWetqIvqUJ7h7FEOdzJ3dugib0FmvNMxcB9uDgDs4X7o7tPyMXSSgytFQ2XThI/H 6FFJYNk58uU2mZ7QmoYETKlKvinsKbPZVVog6vE0/Ke6BCrmDb7KSjbA7iwRp6Ln5f GIoAZm5TY767w== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 26 Nov 2023 15:49:43 +0100 X-ME-IP: 92.140.202.140 From: Christophe JAILLET To: Greg Kroah-Hartman , Tejun Heo Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH] kernfs: reorder 'struct kernfs_node' to save some memory Date: Sun, 26 Nov 2023 15:49:37 +0100 Message-Id: <465890c56c6f5ad702a091a1ecd3c70bd4a3a74c.1701010150.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sun, 26 Nov 2023 06:49:57 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783638471387607041 X-GMAIL-MSGID: 1783638471387607041 'struct kernfs_node' uses a dedicated cache, so shrinking its size is always a good idea. On my system, each entry is 128 bytes and their are 32 entries per pages. After the re-ordering, the struct is 120 bytes and 34 entries are stored in each page. Signed-off-by: Christophe JAILLET --- The numbers below are with a allmodconfig configuration. The delta is related to CONFIG_DEBUG_LOCK_ALLOC and struct lockdep_map dep_map. When I checked on my system, it would have saved 372kb of RAM: sudo less /proc/slabinfo | grep kernf kernfs_node_cache 49397 49504 128 32 1 : tunables 0 0 0 : slabdata 1547 1547 0 I have left flags close to the union, I *think* that they are related. I don't if having 'mode' here is logical or not. Before: ====== struct kernfs_node { atomic_t count; /* 0 4 */ atomic_t active; /* 4 4 */ struct lockdep_map dep_map; /* 8 48 */ struct kernfs_node * parent; /* 56 8 */ /* --- cacheline 1 boundary (64 bytes) --- */ const char * name; /* 64 8 */ struct rb_node rb __attribute__((__aligned__(8))); /* 72 24 */ const void * ns; /* 96 8 */ unsigned int hash; /* 104 4 */ /* XXX 4 bytes hole, try to pack */ union { struct kernfs_elem_dir dir; /* 112 32 */ struct kernfs_elem_symlink symlink; /* 112 8 */ struct kernfs_elem_attr attr; /* 112 32 */ }; /* 112 32 */ /* --- cacheline 2 boundary (128 bytes) was 16 bytes ago --- */ void * priv; /* 144 8 */ u64 id; /* 152 8 */ short unsigned int flags; /* 160 2 */ umode_t mode; /* 162 2 */ /* XXX 4 bytes hole, try to pack */ struct kernfs_iattrs * iattr; /* 168 8 */ /* size: 176, cachelines: 3, members: 14 */ /* sum members: 168, holes: 2, sum holes: 8 */ /* forced alignments: 1 */ /* last cacheline: 48 bytes */ } __attribute__((__aligned__(8))); After: ===== struct kernfs_node { atomic_t count; /* 0 4 */ atomic_t active; /* 4 4 */ struct lockdep_map dep_map; /* 8 48 */ struct kernfs_node * parent; /* 56 8 */ /* --- cacheline 1 boundary (64 bytes) --- */ const char * name; /* 64 8 */ struct rb_node rb __attribute__((__aligned__(8))); /* 72 24 */ const void * ns; /* 96 8 */ unsigned int hash; /* 104 4 */ umode_t mode; /* 108 2 */ short unsigned int flags; /* 110 2 */ union { struct kernfs_elem_dir dir; /* 112 32 */ struct kernfs_elem_symlink symlink; /* 112 8 */ struct kernfs_elem_attr attr; /* 112 32 */ }; /* 112 32 */ /* --- cacheline 2 boundary (128 bytes) was 16 bytes ago --- */ void * priv; /* 144 8 */ u64 id; /* 152 8 */ struct kernfs_iattrs * iattr; /* 160 8 */ /* size: 168, cachelines: 3, members: 14 */ /* forced alignments: 1 */ /* last cacheline: 40 bytes */ } __attribute__((__aligned__(8))); --- include/linux/kernfs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h index 99aaa050ccb7..b7cd6e793286 100644 --- a/include/linux/kernfs.h +++ b/include/linux/kernfs.h @@ -206,6 +206,8 @@ struct kernfs_node { const void *ns; /* namespace tag */ unsigned int hash; /* ns + name hash */ + umode_t mode; + unsigned short flags; union { struct kernfs_elem_dir dir; struct kernfs_elem_symlink symlink; @@ -220,8 +222,6 @@ struct kernfs_node { */ u64 id; - unsigned short flags; - umode_t mode; struct kernfs_iattrs *iattr; };