3030
3131#include <linux/atomic.h>
3232
33+ #include <asm/runtime-const.h>
34+
3335#include "internal.h"
3436
3537/* sysctl tunables... */
@@ -38,8 +40,10 @@ static struct files_stat_struct files_stat = {
3840};
3941
4042/* SLAB cache for file structures */
41- static struct kmem_cache * filp_cachep __ro_after_init ;
42- static struct kmem_cache * bfilp_cachep __ro_after_init ;
43+ static struct kmem_cache * __filp_cache __ro_after_init ;
44+ #define filp_cache runtime_const_ptr(__filp_cache)
45+ static struct kmem_cache * __bfilp_cache __ro_after_init ;
46+ #define bfilp_cache runtime_const_ptr(__bfilp_cache)
4347
4448static struct percpu_counter nr_files __cacheline_aligned_in_smp ;
4549
@@ -74,9 +78,9 @@ static inline void file_free(struct file *f)
7478 put_cred (f -> f_cred );
7579 if (unlikely (f -> f_mode & FMODE_BACKING )) {
7680 path_put (backing_file_user_path (f ));
77- kmem_cache_free (bfilp_cachep , backing_file (f ));
81+ kmem_cache_free (bfilp_cache , backing_file (f ));
7882 } else {
79- kmem_cache_free (filp_cachep , f );
83+ kmem_cache_free (filp_cache , f );
8084 }
8185}
8286
@@ -234,13 +238,13 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
234238 goto over ;
235239 }
236240
237- f = kmem_cache_alloc (filp_cachep , GFP_KERNEL );
241+ f = kmem_cache_alloc (filp_cache , GFP_KERNEL );
238242 if (unlikely (!f ))
239243 return ERR_PTR (- ENOMEM );
240244
241245 error = init_file (f , flags , cred );
242246 if (unlikely (error )) {
243- kmem_cache_free (filp_cachep , f );
247+ kmem_cache_free (filp_cache , f );
244248 return ERR_PTR (error );
245249 }
246250
@@ -268,13 +272,13 @@ struct file *alloc_empty_file_noaccount(int flags, const struct cred *cred)
268272 struct file * f ;
269273 int error ;
270274
271- f = kmem_cache_alloc (filp_cachep , GFP_KERNEL );
275+ f = kmem_cache_alloc (filp_cache , GFP_KERNEL );
272276 if (unlikely (!f ))
273277 return ERR_PTR (- ENOMEM );
274278
275279 error = init_file (f , flags , cred );
276280 if (unlikely (error )) {
277- kmem_cache_free (filp_cachep , f );
281+ kmem_cache_free (filp_cache , f );
278282 return ERR_PTR (error );
279283 }
280284
@@ -295,13 +299,13 @@ struct file *alloc_empty_backing_file(int flags, const struct cred *cred)
295299 struct backing_file * ff ;
296300 int error ;
297301
298- ff = kmem_cache_alloc (bfilp_cachep , GFP_KERNEL );
302+ ff = kmem_cache_alloc (bfilp_cache , GFP_KERNEL );
299303 if (unlikely (!ff ))
300304 return ERR_PTR (- ENOMEM );
301305
302306 error = init_file (& ff -> file , flags , cred );
303307 if (unlikely (error )) {
304- kmem_cache_free (bfilp_cachep , ff );
308+ kmem_cache_free (bfilp_cache , ff );
305309 return ERR_PTR (error );
306310 }
307311
@@ -593,14 +597,17 @@ void __init files_init(void)
593597 .freeptr_offset = offsetof(struct file , f_freeptr ),
594598 };
595599
596- filp_cachep = kmem_cache_create ("filp" , sizeof (struct file ), & args ,
600+ __filp_cache = kmem_cache_create ("filp" , sizeof (struct file ), & args ,
597601 SLAB_HWCACHE_ALIGN | SLAB_PANIC |
598602 SLAB_ACCOUNT | SLAB_TYPESAFE_BY_RCU );
603+ runtime_const_init (ptr , __filp_cache );
599604
600605 args .freeptr_offset = offsetof(struct backing_file , bf_freeptr );
601- bfilp_cachep = kmem_cache_create ("bfilp" , sizeof (struct backing_file ),
606+ __bfilp_cache = kmem_cache_create ("bfilp" , sizeof (struct backing_file ),
602607 & args , SLAB_HWCACHE_ALIGN | SLAB_PANIC |
603608 SLAB_ACCOUNT | SLAB_TYPESAFE_BY_RCU );
609+ runtime_const_init (ptr , __bfilp_cache );
610+
604611 percpu_counter_init (& nr_files , 0 , GFP_KERNEL );
605612}
606613
0 commit comments