On Sat, Nov 29, 2025 at 6:01 PM Al Viro <[email protected]> wrote: > void __init filename_init(void) > { > - names_cachep = kmem_cache_create_usercopy("names_cache", PATH_MAX, 0, > - SLAB_HWCACHE_ALIGN|SLAB_PANIC, 0, PATH_MAX, NULL); > + names_cachep = kmem_cache_create_usercopy("names_cache", > sizeof(struct filename), 0, > + SLAB_HWCACHE_ALIGN|SLAB_PANIC, offsetof(struct > filename, iname), > + EMBEDDED_NAME_MAX, NULL); > } > [snip] > diff --git a/include/linux/fs.h b/include/linux/fs.h > index 59c5c67985ab..0b01adcfa425 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -2833,11 +2833,13 @@ extern struct kobject *fs_kobj; > > /* fs/open.c */ > struct audit_names; > + > +#define EMBEDDED_NAME_MAX 128 > struct filename { > const char *name; /* pointer to actual string */ > atomic_t refcnt; > struct audit_names *aname; > - const char iname[]; > + const char iname[EMBEDDED_NAME_MAX]; > }; > static_assert(offsetof(struct filename, iname) % sizeof(long) == 0); >
This makes sizeof struct filename 152 bytes. At the same time because of the SLAB_HWCACHE_ALIGN flag, the obj is going to take 192 bytes. I don't know what would be the nice way to handle this in Linux, but as is this is just failing to take advantage of memory which is going to get allocated anyway. Perhaps the macro could be bumped to 168 and the size checked with a static assert on 64 bit platforms? Or some magic based on reported cache line size.
