From: Mateusz Guzik <mjguzik@gmail.com>
To: brauner@kernel.org
Cc: viro@zeniv.linux.org.uk, jack@suse.cz,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
torvalds@linux-foundation.org, pfalcato@suse.de,
Mateusz Guzik <mjguzik@gmail.com>
Subject: [PATCH v2] fs: hide names_cachep behind runtime access machinery
Date: Thu, 30 Oct 2025 09:59:45 +0100 [thread overview]
Message-ID: <20251030085949.787504-1-mjguzik@gmail.com> (raw)
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@gmail.com>
---
ACHTUNG WARNING POZOR UWAGA Блять: I did some testing and ifdef MODULE
seems to work, but perhaps someone with build-fu could chime in? I
verified with a hello world module that this fine, but maybe I missed a
case.
v2:
- ifdef on module usage -- the runtime thing does *not* work with modules
- patch up the section warn, thanks to Pedro for spotting what's up with
the problem
Linus cc'ed as he added the runtime thing + dcache usage in the first place.
The machinery does not support kernel modules and I have no interest in
spending time to extend it.
I tried to add a compilation time warn should someone compile a module
with it, but there is no shared header so I decided to forego doing it.
Should someone(tm) make this work for modules I'm not going to protest.
Absent that, vast majority of actual usage is coming from core kernel,
which *is* getting the new treatment and I don't think the ifdef is
particularly nasty.
fs/dcache.c | 1 +
include/asm-generic/vmlinux.lds.h | 3 ++-
include/linux/fs.h | 13 +++++++++++--
3 files changed, 14 insertions(+), 3 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/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 68c4a59ec8fb..1095aff77a89 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2960,8 +2960,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 names_cachep
+#else
+#define __names_cachep runtime_const_ptr(names_cachep)
+#endif
+
+#define __getname() kmem_cache_alloc(__names_cachep, GFP_KERNEL)
+#define __putname(name) kmem_cache_free(__names_cachep, (void *)(name))
extern struct super_block *blockdev_superblock;
static inline bool sb_is_blkdev_sb(struct super_block *sb)
--
2.34.1
next reply other threads:[~2025-10-30 9:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-30 8:59 Mateusz Guzik [this message]
2025-10-30 10:34 ` [PATCH v2] fs: hide names_cachep behind runtime access machinery kernel test robot
2025-10-30 10:34 ` kernel test robot
2025-10-30 10:34 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251030085949.787504-1-mjguzik@gmail.com \
--to=mjguzik@gmail.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pfalcato@suse.de \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).