fs: hide names_cachep behind runtime_const machinery
RFC PATCH 1/1 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(-)
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/linux/fs.h +3 -2
@@ -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)
Signature · 1 line
2.34.1
Quoted 5 lines · Mateusz Guzik
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.
Quoted 8 lines
I verified this boots on x86-64.
The problem is that when building I get the following:
ld: warning: orphan sectionruntime_ptr_names_cachep' fromvmlinux.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.
Quoted 36 lines
--- fs/dcache.c | 1 + include/linux/fs.h | 5 +++-- 2 files changed, 4 insertions(+), 2 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/linux/fs.h +3
-3@@ -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