Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fs: hide file and bfile caches behind runtime const machinery

s/cachep/cache/ for consistency with namei and dentry caches.

Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
Link: https://patch.msgid.link/20260328173728.3388070-1-mjguzik@gmail.com
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Mateusz Guzik and committed by
Christian Brauner
1f1651d6 18f2e0ea

+23 -14
+1 -1
fs/file.c
··· 200 200 /* 201 201 * Check if the allocation size would exceed INT_MAX. kvmalloc_array() 202 202 * and kvmalloc() will warn if the allocation size is greater than 203 - * INT_MAX, as filp_cachep objects are not __GFP_NOWARN. 203 + * INT_MAX, as filp_cache objects are not __GFP_NOWARN. 204 204 * 205 205 * This can happen when sysctl_nr_open is set to a very high value and 206 206 * a process tries to use a file descriptor near that limit. For example,
+19 -12
fs/file_table.c
··· 30 30 31 31 #include <linux/atomic.h> 32 32 33 + #include <asm/runtime-const.h> 34 + 33 35 #include "internal.h" 34 36 35 37 /* sysctl tunables... */ ··· 40 38 }; 41 39 42 40 /* SLAB cache for file structures */ 43 - static struct kmem_cache *filp_cachep __ro_after_init; 44 - static struct kmem_cache *bfilp_cachep __ro_after_init; 41 + static struct kmem_cache *__filp_cache __ro_after_init; 42 + #define filp_cache runtime_const_ptr(__filp_cache) 43 + static struct kmem_cache *__bfilp_cache __ro_after_init; 44 + #define bfilp_cache runtime_const_ptr(__bfilp_cache) 45 45 46 46 static struct percpu_counter nr_files __cacheline_aligned_in_smp; 47 47 ··· 78 74 put_cred(f->f_cred); 79 75 if (unlikely(f->f_mode & FMODE_BACKING)) { 80 76 path_put(backing_file_user_path(f)); 81 - kmem_cache_free(bfilp_cachep, backing_file(f)); 77 + kmem_cache_free(bfilp_cache, backing_file(f)); 82 78 } else { 83 - kmem_cache_free(filp_cachep, f); 79 + kmem_cache_free(filp_cache, f); 84 80 } 85 81 } 86 82 ··· 238 234 goto over; 239 235 } 240 236 241 - f = kmem_cache_alloc(filp_cachep, GFP_KERNEL); 237 + f = kmem_cache_alloc(filp_cache, GFP_KERNEL); 242 238 if (unlikely(!f)) 243 239 return ERR_PTR(-ENOMEM); 244 240 245 241 error = init_file(f, flags, cred); 246 242 if (unlikely(error)) { 247 - kmem_cache_free(filp_cachep, f); 243 + kmem_cache_free(filp_cache, f); 248 244 return ERR_PTR(error); 249 245 } 250 246 ··· 272 268 struct file *f; 273 269 int error; 274 270 275 - f = kmem_cache_alloc(filp_cachep, GFP_KERNEL); 271 + f = kmem_cache_alloc(filp_cache, GFP_KERNEL); 276 272 if (unlikely(!f)) 277 273 return ERR_PTR(-ENOMEM); 278 274 279 275 error = init_file(f, flags, cred); 280 276 if (unlikely(error)) { 281 - kmem_cache_free(filp_cachep, f); 277 + kmem_cache_free(filp_cache, f); 282 278 return ERR_PTR(error); 283 279 } 284 280 ··· 299 295 struct backing_file *ff; 300 296 int error; 301 297 302 - ff = kmem_cache_alloc(bfilp_cachep, GFP_KERNEL); 298 + ff = kmem_cache_alloc(bfilp_cache, GFP_KERNEL); 303 299 if (unlikely(!ff)) 304 300 return ERR_PTR(-ENOMEM); 305 301 306 302 error = init_file(&ff->file, flags, cred); 307 303 if (unlikely(error)) { 308 - kmem_cache_free(bfilp_cachep, ff); 304 + kmem_cache_free(bfilp_cache, ff); 309 305 return ERR_PTR(error); 310 306 } 311 307 ··· 597 593 .freeptr_offset = offsetof(struct file, f_freeptr), 598 594 }; 599 595 600 - filp_cachep = kmem_cache_create("filp", sizeof(struct file), &args, 596 + __filp_cache = kmem_cache_create("filp", sizeof(struct file), &args, 601 597 SLAB_HWCACHE_ALIGN | SLAB_PANIC | 602 598 SLAB_ACCOUNT | SLAB_TYPESAFE_BY_RCU); 599 + runtime_const_init(ptr, __filp_cache); 603 600 604 601 args.freeptr_offset = offsetof(struct backing_file, bf_freeptr); 605 - bfilp_cachep = kmem_cache_create("bfilp", sizeof(struct backing_file), 602 + __bfilp_cache = kmem_cache_create("bfilp", sizeof(struct backing_file), 606 603 &args, SLAB_HWCACHE_ALIGN | SLAB_PANIC | 607 604 SLAB_ACCOUNT | SLAB_TYPESAFE_BY_RCU); 605 + runtime_const_init(ptr, __bfilp_cache); 606 + 608 607 percpu_counter_init(&nr_files, 0, GFP_KERNEL); 609 608 } 610 609
+3 -1
include/asm-generic/vmlinux.lds.h
··· 973 973 RUNTIME_CONST(shift, d_hash_shift) \ 974 974 RUNTIME_CONST(ptr, dentry_hashtable) \ 975 975 RUNTIME_CONST(ptr, __dentry_cache) \ 976 - RUNTIME_CONST(ptr, __names_cache) 976 + RUNTIME_CONST(ptr, __names_cache) \ 977 + RUNTIME_CONST(ptr, __filp_cache) \ 978 + RUNTIME_CONST(ptr, __bfilp_cache) 977 979 978 980 /* Alignment must be consistent with (kunit_suite *) in include/kunit/test.h */ 979 981 #define KUNIT_TABLE() \