Re: [WIP RFC PATCH] fs: hide names_cachep behind runtime_const machinery

From: Mateusz Guzik

Date: Wed Oct 29 2025 - 11:08:54 EST


On Wed, Oct 29, 2025 at 2:55 PM Mateusz Guzik <mjguzik@xxxxxxxxx> wrote:
>
> All path lookups end up allocating and freeing a buffer. The namei cache
> is created and at boot time and remains constant, meaning there is no
> reason to spend a cacheline to load the pointer.
>
> I verified this boots on x86-64.
>
> The problem is that when building I get the following:
> ld: warning: orphan section `runtime_ptr_names_cachep' from `vmlinux.o' being placed in section `runtime_ptr_names_cachep'
>
> I don't know what's up with that yet, but I will sort it out. Before I
> put any effort into it I need to know if the idea looks fine.
>

The good news is that Pedro Falcato stepped in and found a spot I
failed to add the var to, this clears up the warning.

However, after further testing I found that kernel modules are not
being patched. I'll be sending a v2 with some more commentary.

> ---
> fs/dcache.c | 1 +
> include/linux/fs.h | 5 +++--
> 2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/fs/dcache.c b/fs/dcache.c
> index 035cccbc9276..786d09798313 100644
> --- a/fs/dcache.c
> +++ b/fs/dcache.c
> @@ -3265,6 +3265,7 @@ void __init vfs_caches_init(void)
> {
> names_cachep = kmem_cache_create_usercopy("names_cache", PATH_MAX, 0,
> SLAB_HWCACHE_ALIGN|SLAB_PANIC, 0, PATH_MAX, NULL);
> + runtime_const_init(ptr, names_cachep);
>
> dcache_init();
> inode_init();
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 68c4a59ec8fb..08ea27340309 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -2960,8 +2960,9 @@ extern void __init vfs_caches_init(void);
>
> extern struct kmem_cache *names_cachep;
>
> -#define __getname() kmem_cache_alloc(names_cachep, GFP_KERNEL)
> -#define __putname(name) kmem_cache_free(names_cachep, (void *)(name))
> +#define __const_names_cachep runtime_const_ptr(names_cachep)
> +#define __getname() kmem_cache_alloc(__const_names_cachep, GFP_KERNEL)
> +#define __putname(name) kmem_cache_free(__const_names_cachep, (void *)(name))
>
> extern struct super_block *blockdev_superblock;
> static inline bool sb_is_blkdev_sb(struct super_block *sb)
> --
> 2.34.1
>