fs: filp_cachep can be static in fs/file_table.c
Subsystems (2)
PATCH 1/1 fs: filp_cachep can be static in fs/file_table.c
Hi Andrew
Please find two cleanups before patch re-submission to use SLAB_DESTROY_BY_RCU for "struct file".
Thank you
[PATCH] fs: filp_cachep can be static in fs/file_table.c
1) Documentation cleanup
Documentation/filesystems/files.txt was not updated when f_count became an atomic_long_t.atomic_long_inc_not_zero() is now used instead of atomic_inc_not_zero()
2) filp_cachep can be static to fs/file_table.c
Instead of creating the "filp" kmem_cache in vfs_caches_init(), we can do it a litle be later in files_init(), so that filp_cachep is static to fs/file_table.c
--- Documentation/filesystems/files.txt | 6 +++--- fs/dcache.c | 6 ------ fs/file_table.c | 10 +++++++++- include/linux/fdtable.h | 2 -- 4 files changed, 12 insertions(+), 12 deletions(-)
Documentation/filesystems/files.txt +3 -3
@@ -76,13 +76,13 @@ the fdtable structure - 5. Handling of the file structures is special. Since the look-up of the fd (fget()/fget_light()) are lock-free, it is possible that look-up may race with the last put() operation on the - file structure. This is avoided using atomic_inc_not_zero() + file structure. This is avoided using atomic_long_inc_not_zero() on ->f_count : rcu_read_lock(); file = fcheck_files(files, fd); if (file) { - if (atomic_inc_not_zero(&file->f_count)) + if (atomic_long_inc_not_zero(&file->f_count)) *fput_needed = 1; else /* Didn't get the reference, someone's freed */
@@ -92,7 +92,7 @@ the fdtable structure - .... return file; - atomic_inc_not_zero() detects if refcounts is already zero or + atomic_long_inc_not_zero() detects if refcounts is already zero or goes to zero during increment. If it does, we fail fget()/fget_light().
fs/dcache.c +0 -6
@@ -2313,9 +2313,6 @@ static void __init dcache_init(void)/* SLAB cache for __getname() consumers */ struct kmem_cache *names_cachep__read_mostly ; -/* SLAB cache for file structures */ -struct kmem_cache *filp_cachep__read_mostly ; -EXPORT_SYMBOL (d_genocide);void __init vfs_caches_init_early (void )
@@ -2337,9 +2334,6 @@ void __init vfs_caches_init(unsigned long mempages) names_cachep =kmem_cache_create ("names_cache" ,PATH_MAX ,0 ,SLAB_HWCACHE_ALIGN |SLAB_PANIC ,NULL ); - filp_cachep =kmem_cache_create ("filp" ,sizeof (struct file ),0 , -SLAB_HWCACHE_ALIGN |SLAB_PANIC ,NULL ); -dcache_init ();inode_init ();files_init (mempages);
fs/file_table.c +9 -1
@@ -32,6 +32,9 @@ struct files_stat_struct files_stat = {/* public. Not pretty! */ __cacheline_aligned_in_smp DEFINE_SPINLOCK (files_lock ); +/* SLAB cache for file structures */ +static struct kmem_cache *filp_cachep__read_mostly ; + static struct percpu_counter nr_files __cacheline_aligned_in_smp;static inline void file_free_rcu (struct rcu_head *head)
@@ -397,7 +400,12 @@ too_bad:void __init files_init (unsigned long mempages) {int n; -/* One file with associated inode and dcache is very roughly 1K. + + filp_cachep =kmem_cache_create ("filp" ,sizeof (struct file ),0 , +SLAB_HWCACHE_ALIGN |SLAB_PANIC ,NULL ); + +/* +* One file with associated inode and dcache is very roughly 1K. * Per default don't use more than 10% of our memory for files. */
include/linux/fdtable.h +0 -2
@@ -57,8 +57,6 @@ struct files_struct {#define files_fdtable (files) (rcu_dereference((files)->fdt)) -extern struct kmem_cache *filp_cachep; -struct file_operations ;struct vfsmount ;struct dentry ;
Quoted 15 lines · Eric Dumazet
Hi Andrew
Please find two cleanups before patch re-submission to use
SLAB_DESTROY_BY_RCUfor "struct file".Thank you
[PATCH] fs:
filp_cachepcan be static infs/file_table.c1) Documentation cleanup
Documentation/filesystems/files.txtwas not updated whenf_countbecame anatomic_long_t.atomic_long_inc_not_zero()is now used instead ofatomic_inc_not_zero()
Quoted 5 lines
2)
filp_cachepcan be static tofs/file_table.cInstead of creating the "filp"
kmem_cacheinvfs_caches_init(), we can do it a litle be later infiles_init(), so thatfilp_cachepis static tofs/file_table.c
Quoted 108 lines
Signed-off-by Eric Dumazet <[email protected]>--- Documentation/filesystems/files.txt | 6 +++--- fs/dcache.c | 6 ------ fs/file_table.c | 10 +++++++++- include/linux/fdtable.h | 2 -- 4 files changed, 12 insertions(+), 12 deletions(-)Documentation/filesystems/files.txt +3
-3@@ -76,13 +76,13 @@ the fdtable structure - 5. Handling of the file structures is special. Since the look-up of the fd (fget()/fget_light()) are lock-free, it is possible that look-up may race with the last put() operation on the - file structure. This is avoided using atomic_inc_not_zero() + file structure. This is avoided using atomic_long_inc_not_zero() on ->f_count : rcu_read_lock(); file = fcheck_files(files, fd); if (file) { - if (atomic_inc_not_zero(&file->f_count)) + if (atomic_long_inc_not_zero(&file->f_count)) *fput_needed = 1; else /* Didn't get the reference, someone's freed */@@ -92,7 +92,7 @@ the fdtable structure - return file; - atomic_inc_not_zero() detects if refcounts is already zero or + atomic_long_inc_not_zero() detects if refcounts is already zero or goes to zero during increment. If it does, we fail fget()/fget_light().fs/dcache.c +0
-6@@ -2313,9 +2313,6 @@ static void __init dcache_init(void)/* SLAB cache for __getname() consumers */ struct kmem_cache *names_cachep__read_mostly ; -/* SLAB cache for file structures */ -struct kmem_cache *filp_cachep__read_mostly ; -EXPORT_SYMBOL (d_genocide);void __init vfs_caches_init_early (void )@@ -2337,9 +2334,6 @@ void __init vfs_caches_init(unsigned long mempages) names_cachep =kmem_cache_create ("names_cache" ,PATH_MAX ,0 ,SLAB_HWCACHE_ALIGN |SLAB_PANIC ,NULL ); - filp_cachep =kmem_cache_create ("filp" ,sizeof (struct file ),0 , -SLAB_HWCACHE_ALIGN |SLAB_PANIC ,NULL ); -dcache_init ();inode_init ();files_init (mempages);fs/file_table.c +9
-1@@ -32,6 +32,9 @@ struct files_stat_struct files_stat = {/* public. Not pretty! */ __cacheline_aligned_in_smp DEFINE_SPINLOCK (files_lock ); +/* SLAB cache for file structures */ +static struct kmem_cache *filp_cachep__read_mostly ; + static struct percpu_counter nr_files __cacheline_aligned_in_smp;static inline void file_free_rcu (struct rcu_head *head)@@ -397,7 +400,12 @@ too_bad:void __init files_init (unsigned long mempages) {int n; -/* One file with associated inode and dcache is very roughly 1K. + + filp_cachep =kmem_cache_create ("filp" ,sizeof (struct file ),0 , +SLAB_HWCACHE_ALIGN |SLAB_PANIC ,NULL ); + +/* +* One file with associated inode and dcache is very roughly 1K. * Per default don't use more than 10% of our memory for files. */ include/linux/fdtable.h +0
-3@@ -57,8 +57,6 @@ struct files_struct {#define files_fdtable (files) (rcu_dereference((files)->fdt)) -extern struct kmem_cache *filp_cachep; -struct file_operations ;struct vfsmount ;struct dentry ; --To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/