[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251031174220.43458-4-mjguzik@gmail.com>
Date: Fri, 31 Oct 2025 18:42:20 +0100
From: Mateusz Guzik <mjguzik@...il.com>
To: torvalds@...ux-foundation.org
Cc: brauner@...nel.org,
viro@...iv.linux.org.uk,
jack@...e.cz,
linux-kernel@...r.kernel.org,
linux-fsdevel@...r.kernel.org,
tglx@...utronix.de,
pfalcato@...e.de,
Mateusz Guzik <mjguzik@...il.com>
Subject: [PATCH 3/3] fs: hide names_cachep behind runtime access machinery
The var is used twice for every path lookup, while the cache is
initialized early and stays valid for the duration.
Signed-off-by: Mateusz Guzik <mjguzik@...il.com>
---
fs/dcache.c | 1 +
include/asm-generic/vmlinux.lds.h | 3 ++-
include/linux/fs.h | 17 +++++++++++++++--
3 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/fs/dcache.c b/fs/dcache.c
index de3e4e9777ea..1afef6cf16b7 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -3259,6 +3259,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/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index dcdbd962abd6..c7d85c80111c 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -939,7 +939,8 @@
#define RUNTIME_CONST_VARIABLES \
RUNTIME_CONST(shift, d_hash_shift) \
- RUNTIME_CONST(ptr, dentry_hashtable)
+ RUNTIME_CONST(ptr, dentry_hashtable) \
+ RUNTIME_CONST(ptr, names_cachep)
/* Alignment must be consistent with (kunit_suite *) in include/kunit/test.h */
#define KUNIT_TABLE() \
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 947d7958eb72..bf0606ace221 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -50,6 +50,10 @@
#include <linux/unicode.h>
#include <asm/byteorder.h>
+#ifndef MODULE
+#include <asm/runtime-const-accessors.h>
+#endif
+
#include <uapi/linux/fs.h>
struct backing_dev_info;
@@ -3044,8 +3048,17 @@ 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))
+/*
+ * XXX The runtime_const machinery does not support modules at the moment.
+ */
+#ifdef MODULE
+#define __names_cachep_accessor names_cachep
+#else
+#define __names_cachep_accessor runtime_const_ptr(names_cachep)
+#endif
+
+#define __getname() kmem_cache_alloc(__names_cachep_accessor, GFP_KERNEL)
+#define __putname(name) kmem_cache_free(__names_cachep_accessor, (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