[2/3] kernfs: Rearrange kernfs_node fields to reduce its size on 64bit

Message ID 20240109214828.252092-3-tj@kernel.org
State New
Headers
Series [1/3] Revert "kernfs: convert kernfs_idr_lock to an irq safe raw spinlock" |

Commit Message

Tejun Heo Jan. 9, 2024, 9:48 p.m. UTC
  Moving .flags and .mode right below .hash makes kernfs_node smaller by 8
bytes on 64bit.

Signed-off-by: Tejun Heo <tj@kernel.org>
---
 include/linux/kernfs.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Comments

Geert Uytterhoeven Jan. 10, 2024, 3:18 p.m. UTC | #1
Hi Tejun,

On Tue, Jan 9, 2024 at 10:49 PM Tejun Heo <tj@kernel.org> wrote:
> Moving .flags and .mode right below .hash makes kernfs_node smaller by 8
> bytes on 64bit.
>
> Signed-off-by: Tejun Heo <tj@kernel.org>

Thanks for your patch!

> --- a/include/linux/kernfs.h
> +++ b/include/linux/kernfs.h
> @@ -206,6 +206,9 @@ struct kernfs_node {
>
>         const void              *ns;    /* namespace tag */
>         unsigned int            hash;   /* ns + name hash */
> +       unsigned short          flags;
> +       umode_t                 mode;
> +
>         union {
>                 struct kernfs_elem_dir          dir;
>                 struct kernfs_elem_symlink      symlink;
> @@ -220,8 +223,6 @@ struct kernfs_node {
>          */
>         u64                     id;
>
> -       unsigned short          flags;
> -       umode_t                 mode;
>         struct kernfs_iattrs    *iattr;

Note that there is now a hole at the end of the structure on 32-bit
architectures
where the alignment of u64 is 8 bytes.

Hence, sizeof(struct kernfs_node) grew from 104 to 112 bytes on (at
least) arm32 and rv32.
It did shrink by 8 bytes on amd64, arm64, mips64, and rv64.
Size is unchanged on ia32, m68k and sh.

I didn't check any other architectures.

Gr{oetje,eeting}s,

                        Geert
  
Tejun Heo Jan. 10, 2024, 6:26 p.m. UTC | #2
On Wed, Jan 10, 2024 at 04:18:36PM +0100, Geert Uytterhoeven wrote:
> Hi Tejun,
> 
> On Tue, Jan 9, 2024 at 10:49 PM Tejun Heo <tj@kernel.org> wrote:
> > Moving .flags and .mode right below .hash makes kernfs_node smaller by 8
> > bytes on 64bit.
> >
> > Signed-off-by: Tejun Heo <tj@kernel.org>
> 
> Thanks for your patch!
> 
> > --- a/include/linux/kernfs.h
> > +++ b/include/linux/kernfs.h
> > @@ -206,6 +206,9 @@ struct kernfs_node {
> >
> >         const void              *ns;    /* namespace tag */
> >         unsigned int            hash;   /* ns + name hash */
> > +       unsigned short          flags;
> > +       umode_t                 mode;
> > +
> >         union {
> >                 struct kernfs_elem_dir          dir;
> >                 struct kernfs_elem_symlink      symlink;
> > @@ -220,8 +223,6 @@ struct kernfs_node {
> >          */
> >         u64                     id;
> >
> > -       unsigned short          flags;
> > -       umode_t                 mode;
> >         struct kernfs_iattrs    *iattr;
> 
> Note that there is now a hole at the end of the structure on 32-bit
> architectures
> where the alignment of u64 is 8 bytes.
> 
> Hence, sizeof(struct kernfs_node) grew from 104 to 112 bytes on (at
> least) arm32 and rv32.
> It did shrink by 8 bytes on amd64, arm64, mips64, and rv64.
> Size is unchanged on ia32, m68k and sh.
> 
> I didn't check any other architectures.

Ah, thanks. I'll shuffle things a bit more so that the size doesn't increase
for 32bits.
  

Patch

diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
index 99aaa050ccb7..03c3fb83ab9e 100644
--- a/include/linux/kernfs.h
+++ b/include/linux/kernfs.h
@@ -206,6 +206,9 @@  struct kernfs_node {
 
 	const void		*ns;	/* namespace tag */
 	unsigned int		hash;	/* ns + name hash */
+	unsigned short		flags;
+	umode_t			mode;
+
 	union {
 		struct kernfs_elem_dir		dir;
 		struct kernfs_elem_symlink	symlink;
@@ -220,8 +223,6 @@  struct kernfs_node {
 	 */
 	u64			id;
 
-	unsigned short		flags;
-	umode_t			mode;
 	struct kernfs_iattrs	*iattr;
 };