Skip to content

Commit ea566e1

Browse files
committed
fs: use kmem_cache_create_rcu()
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/[email protected] Acked-by: Mike Rapoport (Microsoft) <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent d345bd2 commit ea566e1

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

fs/file_table.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,9 @@ EXPORT_SYMBOL(__fput_sync);
511511

512512
void __init files_init(void)
513513
{
514-
filp_cachep = kmem_cache_create("filp", sizeof(struct file), 0,
515-
SLAB_TYPESAFE_BY_RCU | SLAB_HWCACHE_ALIGN |
516-
SLAB_PANIC | SLAB_ACCOUNT, NULL);
514+
filp_cachep = kmem_cache_create_rcu("filp", sizeof(struct file),
515+
offsetof(struct file, f_freeptr),
516+
SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT);
517517
percpu_counter_init(&nr_files, 0, GFP_KERNEL);
518518
}
519519

include/linux/fs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,7 @@ static inline int ra_has_index(struct file_ra_state *ra, pgoff_t index)
10111011
* @f_task_work: task work entry point
10121012
* @f_llist: work queue entrypoint
10131013
* @f_ra: file's readahead state
1014+
* @f_freeptr: Pointer used by SLAB_TYPESAFE_BY_RCU file cache (don't touch.)
10141015
*/
10151016
struct file {
10161017
atomic_long_t f_count;
@@ -1042,6 +1043,7 @@ struct file {
10421043
struct callback_head f_task_work;
10431044
struct llist_node f_llist;
10441045
struct file_ra_state f_ra;
1046+
freeptr_t f_freeptr;
10451047
};
10461048
/* --- cacheline 3 boundary (192 bytes) --- */
10471049
} __randomize_layout

0 commit comments

Comments
 (0)