fs: use kmem_cache_create_rcu()
authorChristian Brauner <brauner@kernel.org>
Wed, 28 Aug 2024 10:56:25 +0000 (12:56 +0200)
committerChristian Brauner <brauner@kernel.org>
Thu, 29 Aug 2024 13:20:33 +0000 (15:20 +0200)
Switch to the new kmem_cache_create_rcu() helper which allows us to use
a custom free pointer offset avoiding the need to have an external free
pointer which would grow struct file behind our backs.

Link: https://lore.kernel.org/r/20240828-work-kmem_cache-rcu-v3-3-5460bc1f09f6@kernel.org
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/file_table.c
include/linux/fs.h

index fdf98709dde237757c06046717420d4d48aed19c..3ef558f27a1cd3ae35250860e9128d198f5c4d4f 100644 (file)
@@ -511,9 +511,9 @@ EXPORT_SYMBOL(__fput_sync);
 
 void __init files_init(void)
 {
-       filp_cachep = kmem_cache_create("filp", sizeof(struct file), 0,
-                               SLAB_TYPESAFE_BY_RCU | SLAB_HWCACHE_ALIGN |
-                               SLAB_PANIC | SLAB_ACCOUNT, NULL);
+       filp_cachep = kmem_cache_create_rcu("filp", sizeof(struct file),
+                               offsetof(struct file, f_freeptr),
+                               SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT);
        percpu_counter_init(&nr_files, 0, GFP_KERNEL);
 }
 
index af8bbd4eeb3a5f5e8b724f98811ed451426bdf13..58c91a52cad1c95a405be5f043d86b1742f0260b 100644 (file)
@@ -1011,6 +1011,7 @@ static inline int ra_has_index(struct file_ra_state *ra, pgoff_t index)
  * @f_task_work: task work entry point
  * @f_llist: work queue entrypoint
  * @f_ra: file's readahead state
+ * @f_freeptr: Pointer used by SLAB_TYPESAFE_BY_RCU file cache (don't touch.)
  */
 struct file {
        atomic_long_t                   f_count;
@@ -1042,6 +1043,7 @@ struct file {
                struct callback_head    f_task_work;
                struct llist_node       f_llist;
                struct file_ra_state    f_ra;
+               freeptr_t               f_freeptr;
        };
        /* --- cacheline 3 boundary (192 bytes) --- */
 } __randomize_layout