fs: hide names_cachep behind runtime access machinery
Subsystems (2)
PATCH v3 1/1 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.
---
ACHTUNG WARNING POZOR UWAGA Блять: the namei cache can be used by modules while the runtime machinery does not work with them. I did some testing and ifdef MODULE seems to work around the probnlem, but perhaps someone with build-fu could chime in? I verified with a hello world module that this works fine, but maybe I missed a case.
v3:
- fix compilation failure on longarch as reported by kernel test robot, used their repro script to confirm
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.
Per the above 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 drop the matter.
Should someone(tm) make this work for modules I'm not going to protest.
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(-)
fs/dcache.c +1 -0
@@ -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 ();
include/asm-generic/vmlinux.lds.h +2 -1
@@ -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 () \
include/linux/fs.h +11 -2
@@ -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)
Signature · 7 lines
2.34.1 fs/dcache.c | 3 +-- include/asm-generic/vmlinux.lds.h | 3 ++- include/linux/fs.h | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-)
fs/dcache.c +1 -2
@@ -35,8 +35,6 @@#include "internal.h" #include "mount.h" -#include <asm/runtime-const.h> -/* * Usage: * dcache->d_inode->i_lock protects:
@@ -3265,6 +3263,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 ();
include/asm-generic/vmlinux.lds.h +2 -1
@@ -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 () \
include/linux/fs.h +13 -2
@@ -50,6 +50,8 @@#include <linux/unicode.h> #include <asm/byteorder.h> +#include <asm/runtime-const.h> +#include <uapi/linux/fs.h> struct backing_dev_info ;
@@ -2960,8 +2962,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)
Signature · 1 line
2.34.1