[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251029135538.658951-1-mjguzik@gmail.com>
Date: Wed, 29 Oct 2025 14:55:38 +0100
From: Mateusz Guzik <mjguzik@...il.com>
To: brauner@...nel.org
Cc: viro@...iv.linux.org.uk,
	jack@...e.cz,
	linux-kernel@...r.kernel.org,
	linux-fsdevel@...r.kernel.org,
	Mateusz Guzik <mjguzik@...il.com>
Subject: [WIP RFC PATCH] fs: hide names_cachep behind runtime_const machinery
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.
---
 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
Powered by blists - more mailing lists
 
