fs: pack fields `i_state` and `i_fsnotify_mask`
PATCH v2 1/1 fs: pack fields `i_state` and `i_fsnotify_mask`
Both were 32 bit fields followed by a 32 bit hole. This reduces size of struct inode by 8 bytes.
Moving i_fsnotify_marks there as well so they can be in the same cacheline.
---v1->v2: move i_fsnotify_marks up as well because "should better be
in the same cacheline because these two are accessed on some performance sensitive paths" (Jan Kara)
--- include/linux/fs.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
include/linux/fs.h +7 -8
@@ -813,7 +813,13 @@ struct inode {/* Misc */ struct inode_state_flags i_state; -/* 32-bit hole */ + +#ifdef CONFIG_FSNOTIFY +__u32 i_fsnotify_mask;/* all events this inode cares about */ + +struct fsnotify_mark_connector __rcu *i_fsnotify_marks; +#endif +struct rw_semaphore i_rwsem;/* Timestamp for writeback list ordering and age checks (jiffies). */
@@ -863,13 +869,6 @@ struct inode {unsigned i_dir_seq; }; - -#ifdef CONFIG_FSNOTIFY -__u32 i_fsnotify_mask;/* all events this inode cares about */ -/* 32-bit hole reserved for expanding i_fsnotify_mask */ -struct fsnotify_mark_connector __rcu *i_fsnotify_marks; -#endif -void *i_private;/* fs or device private pointer */ } __randomize_layout;
Signature · 1 line
2.53.0
Quoted 7 lines · Max Kellermann
Both were 32 bit fields followed by a 32 bit hole. This reduces size of
struct inodeby 8 bytes.Moving
i_fsnotify_marksthere as well so they can be in the same cacheline.Signed-off-by Max Kellermann <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 44 lines
---
v1->v2: movei_fsnotify_marksup as well because "should better be
in the same cacheline because these two are accessed on some performance sensitive paths" (Jan Kara)--- include/linux/fs.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)include/linux/fs.h +7
-8@@ -813,7 +813,13 @@ struct inode {/* Misc */ struct inode_state_flags i_state; -/* 32-bit hole */ + +#ifdef CONFIG_FSNOTIFY +__u32 i_fsnotify_mask;/* all events this inode cares about */ + +struct fsnotify_mark_connector __rcu *i_fsnotify_marks; +#endif +struct rw_semaphore i_rwsem;/* Timestamp for writeback list ordering and age checks (jiffies). */ @@ -863,13 +869,6 @@ struct inode {unsigned i_dir_seq; }; - -#ifdef CONFIG_FSNOTIFY -__u32 i_fsnotify_mask;/* all events this inode cares about */ -/* 32-bit hole reserved for expanding i_fsnotify_mask */ -struct fsnotify_mark_connector __rcu *i_fsnotify_marks; -#endif -void *i_private;/* fs or device private pointer */ } __randomize_layout;Signature · 1 line
2.53.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
On Fri, 13 Nov 2026 12:44:26 +0100
Max Kellermann <[email protected]> wrote:
I'd use a different workd than 'pack', made me think of __packed.
Quoted 20 lines
Both were 32 bit fields followed by a 32 bit hole. This reduces size of
struct inodeby 8 bytes.Moving
i_fsnotify_marksthere as well so they can be in the same cacheline.Signed-off-by Max Kellermann <[email protected]>---
v1->v2: movei_fsnotify_marksup as well because "should better be
in the same cacheline because these two are accessed on some performance sensitive paths" (Jan Kara)--- include/linux/fs.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)include/linux/fs.h +0
-0
include/linux/fs.h struct inode { · line 820
Quoted 9 lines
include/linux/fs.h +5
-1@@ -813,7 +813,13 @@ struct inode {/* Misc */ struct inode_state_flags i_state; -/* 32-bit hole */ + +#ifdef CONFIG_FSNOTIFY +__u32 i_fsnotify_mask;/* all events this inode cares about */ + +struct fsnotify_mark_connector __rcu *i_fsnotify_marks;
#else /* 32-bit hole */
??
David
Quoted 19 lines
include/linux/fs.h +2
-7+#endif +struct rw_semaphore i_rwsem;/* Timestamp for writeback list ordering and age checks (jiffies). */ @@ -863,13 +869,6 @@ struct inode {unsigned i_dir_seq; }; - -#ifdef CONFIG_FSNOTIFY -__u32 i_fsnotify_mask;/* all events this inode cares about */ -/* 32-bit hole reserved for expanding i_fsnotify_mask */ -struct fsnotify_mark_connector __rcu *i_fsnotify_marks; -#endif -void *i_private;/* fs or device private pointer */ } __randomize_layout;
Quoted 1 line · David Laight
I'd use a different workd than 'pack', made me think of
__packed.
What word would you use?
I think GCC's "packed" attribute is confusing and the name is somewhat misleading - yes, in the end the struct members will be "packed" which makes it sound like a nice idea, but it's really about forcing member alignment to be 1 byte, and accessing such fields is UB, which the GCC documentation fails to mention...
Quoted 7 lines
include/linux/fs.h struct inode { · line 820
Quoted 4 lines
include/linux/fs.h +4
-0+#ifdef CONFIG_FSNOTIFY +__u32 i_fsnotify_mask;/* all events this inode cares about */ + +struct fsnotify_mark_connector __rcu *i_fsnotify_marks;#else /* 32-bit hole */
Good idea, I'll re-add the comment in the next revision.
Signature · 8 lines
Max Kellermann Principal Architect Hosting Technology cm4all | Im Mediapark 6a | 50670 Köln | Germany General information about the company can be found here: https://www.cm4all.com/impressum A member of the IONOS Group