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 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>
---
fs/ext4/super.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 699c15db28a8..2860e0ee913f 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1474,12 +1474,20 @@ static void init_once(void *foo)
static int __init init_inodecache(void)
{
- ext4_inode_cachep = kmem_cache_create_usercopy("ext4_inode_cache",
- sizeof(struct ext4_inode_info), 0,
- SLAB_RECLAIM_ACCOUNT | SLAB_ACCOUNT,
- offsetof(struct ext4_inode_info, i_data),
- sizeof_field(struct ext4_inode_info, i_data),
- init_once);
+ struct kmem_cache_args args = {
+ .align = 0,
+ .useroffset = offsetof(struct ext4_inode_info, i_data),
+ .usersize = sizeof_field(struct ext4_inode_info, i_data),
+ .use_freeptr_offset = true,
+ .freeptr_offset = offsetof(struct ext4_inode_info, i_flags),
+ .ctor = init_once,
+ };
+
+ ext4_inode_cachep = kmem_cache_create("ext4_inode_cache",
+ sizeof(struct ext4_inode_info),
+ &args,
+ SLAB_RECLAIM_ACCOUNT | SLAB_ACCOUNT);
+
if (ext4_inode_cachep == NULL)
return -ENOMEM;
return 0;
--
2.43.0
On Mon, Oct 27, 2025 at 5:29 AM Harry Yoo <harry.yoo@oracle.com> wrote:
>
> 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 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>
> ---
> fs/ext4/super.c | 20 ++++++++++++++------
> 1 file changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 699c15db28a8..2860e0ee913f 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -1474,12 +1474,20 @@ static void init_once(void *foo)
>
> static int __init init_inodecache(void)
> {
> - ext4_inode_cachep = kmem_cache_create_usercopy("ext4_inode_cache",
> - sizeof(struct ext4_inode_info), 0,
> - SLAB_RECLAIM_ACCOUNT | SLAB_ACCOUNT,
> - offsetof(struct ext4_inode_info, i_data),
> - sizeof_field(struct ext4_inode_info, i_data),
> - init_once);
> + struct kmem_cache_args args = {
> + .align = 0,
> + .useroffset = offsetof(struct ext4_inode_info, i_data),
> + .usersize = sizeof_field(struct ext4_inode_info, i_data),
> + .use_freeptr_offset = true,
> + .freeptr_offset = offsetof(struct ext4_inode_info, i_flags),
Hi Harry,
AFAIK freeptr_offset can be used only with SLAB_TYPESAFE_BY_RCU caches
(see https://elixir.bootlin.com/linux/v6.18-rc3/source/include/linux/slab.h#L302)
and check at https://elixir.bootlin.com/linux/v6.18-rc3/source/mm/slab_common.c#L234
should fail otherwise. The cache you are changing does not seem to
have this flag set.
Thanks,
Suren.
> + .ctor = init_once,
> + };
> +
> + ext4_inode_cachep = kmem_cache_create("ext4_inode_cache",
> + sizeof(struct ext4_inode_info),
> + &args,
> + SLAB_RECLAIM_ACCOUNT | SLAB_ACCOUNT);
> +
> if (ext4_inode_cachep == NULL)
> return -ENOMEM;
> return 0;
> --
> 2.43.0
>
On Tue, Oct 28, 2025 at 10:22 AM Suren Baghdasaryan <surenb@google.com> wrote:
>
> On Mon, Oct 27, 2025 at 5:29 AM Harry Yoo <harry.yoo@oracle.com> wrote:
> >
> > 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 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>
> > ---
> > fs/ext4/super.c | 20 ++++++++++++++------
> > 1 file changed, 14 insertions(+), 6 deletions(-)
> >
> > diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> > index 699c15db28a8..2860e0ee913f 100644
> > --- a/fs/ext4/super.c
> > +++ b/fs/ext4/super.c
> > @@ -1474,12 +1474,20 @@ static void init_once(void *foo)
> >
> > static int __init init_inodecache(void)
> > {
> > - ext4_inode_cachep = kmem_cache_create_usercopy("ext4_inode_cache",
> > - sizeof(struct ext4_inode_info), 0,
> > - SLAB_RECLAIM_ACCOUNT | SLAB_ACCOUNT,
> > - offsetof(struct ext4_inode_info, i_data),
> > - sizeof_field(struct ext4_inode_info, i_data),
> > - init_once);
> > + struct kmem_cache_args args = {
> > + .align = 0,
> > + .useroffset = offsetof(struct ext4_inode_info, i_data),
> > + .usersize = sizeof_field(struct ext4_inode_info, i_data),
> > + .use_freeptr_offset = true,
> > + .freeptr_offset = offsetof(struct ext4_inode_info, i_flags),
>
> Hi Harry,
> AFAIK freeptr_offset can be used only with SLAB_TYPESAFE_BY_RCU caches
> (see https://elixir.bootlin.com/linux/v6.18-rc3/source/include/linux/slab.h#L302)
> and check at https://elixir.bootlin.com/linux/v6.18-rc3/source/mm/slab_common.c#L234
> should fail otherwise. The cache you are changing does not seem to
> have this flag set.
Oh, sorry, your patches got reordered in my mailbox and I missed the
first one where you are removing this limitation. Let me review that
first. Sorry for the noise.
> Thanks,
> Suren.
>
> > + .ctor = init_once,
> > + };
> > +
> > + ext4_inode_cachep = kmem_cache_create("ext4_inode_cache",
> > + sizeof(struct ext4_inode_info),
> > + &args,
> > + SLAB_RECLAIM_ACCOUNT | SLAB_ACCOUNT);
> > +
> > if (ext4_inode_cachep == NULL)
> > return -ENOMEM;
> > return 0;
> > --
> > 2.43.0
> >
© 2016 - 2026 Red Hat, Inc.