Skip to content

Commit dca3aa6

Browse files
mjguzikbrauner
authored andcommitted
fs: move inode fields used during fast path lookup closer together
This should avoid *some* cache misses. Successful path lookup is guaranteed to load at least ->i_mode, ->i_opflags and ->i_acl. At the same time the common case will avoid looking at more fields. struct inode is not guaranteed to have any particular alignment, notably ext4 has it only aligned to 8 bytes meaning nearby fields might happen to be on the same or only adjacent cache lines depending on luck (or no luck). According to pahole: umode_t i_mode; /* 0 2 */ short unsigned int i_opflags; /* 2 2 */ kuid_t i_uid; /* 4 4 */ kgid_t i_gid; /* 8 4 */ unsigned int i_flags; /* 12 4 */ struct posix_acl * i_acl; /* 16 8 */ struct posix_acl * i_default_acl; /* 24 8 */ ->i_acl is unnecessarily separated by 8 bytes from the other fields. With struct inode being offset 48 bytes into the cacheline this means an avoidable miss. Note it will still be there for the 56 byte case. New layout: umode_t i_mode; /* 0 2 */ short unsigned int i_opflags; /* 2 2 */ unsigned int i_flags; /* 4 4 */ struct posix_acl * i_acl; /* 8 8 */ struct posix_acl * i_default_acl; /* 16 8 */ kuid_t i_uid; /* 24 4 */ kgid_t i_gid; /* 28 4 */ I verified with pahole there are no size or hole changes. This is stopgap until someone(tm) sanitizes the layout in the first place, allocation methods aside. Signed-off-by: Mateusz Guzik <mjguzik@gmail.com> Link: https://patch.msgid.link/20251109121931.1285366-1-mjguzik@gmail.com Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 5b8ed52 commit dca3aa6

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

include/linux/fs.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,14 +781,13 @@ enum inode_state_flags_t {
781781
struct inode {
782782
umode_t i_mode;
783783
unsigned short i_opflags;
784-
kuid_t i_uid;
785-
kgid_t i_gid;
786784
unsigned int i_flags;
787-
788785
#ifdef CONFIG_FS_POSIX_ACL
789786
struct posix_acl *i_acl;
790787
struct posix_acl *i_default_acl;
791788
#endif
789+
kuid_t i_uid;
790+
kgid_t i_gid;
792791

793792
const struct inode_operations *i_op;
794793
struct super_block *i_sb;

0 commit comments

Comments
 (0)