Skip to content

Commit 43d9bb4

Browse files
hygonitehcaster
authored andcommitted
ext4: specify the free pointer offset for ext4_inode_cache
Convert ext4_inode_cache to use the kmem_cache_args interface and specify a free pointer offset. Since ext4_inode_cache uses a constructor, the free pointer would be placed after the object to prevent overwriting fields used by the constructor. However, some fields such as ->i_flags are not used by the constructor and can safely be repurposed for the free pointer. Specify the free pointer offset at i_flags to reduce the object size. Signed-off-by: Harry Yoo <harry.yoo@oracle.com> Link: https://patch.msgid.link/20260113061845.159790-4-harry.yoo@oracle.com Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
1 parent a13b68d commit 43d9bb4

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

fs/ext4/super.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,12 +1491,19 @@ static void init_once(void *foo)
14911491

14921492
static int __init init_inodecache(void)
14931493
{
1494-
ext4_inode_cachep = kmem_cache_create_usercopy("ext4_inode_cache",
1495-
sizeof(struct ext4_inode_info), 0,
1496-
SLAB_RECLAIM_ACCOUNT | SLAB_ACCOUNT,
1497-
offsetof(struct ext4_inode_info, i_data),
1498-
sizeof_field(struct ext4_inode_info, i_data),
1499-
init_once);
1494+
struct kmem_cache_args args = {
1495+
.useroffset = offsetof(struct ext4_inode_info, i_data),
1496+
.usersize = sizeof_field(struct ext4_inode_info, i_data),
1497+
.use_freeptr_offset = true,
1498+
.freeptr_offset = offsetof(struct ext4_inode_info, i_flags),
1499+
.ctor = init_once,
1500+
};
1501+
1502+
ext4_inode_cachep = kmem_cache_create("ext4_inode_cache",
1503+
sizeof(struct ext4_inode_info),
1504+
&args,
1505+
SLAB_RECLAIM_ACCOUNT | SLAB_ACCOUNT);
1506+
15001507
if (ext4_inode_cachep == NULL)
15011508
return -ENOMEM;
15021509
return 0;

0 commit comments

Comments
 (0)