f2fs: use kmem_cache pool during inline xattr lookups
PATCH v2 1/1 f2fs: use kmem_cache pool during inline xattr lookups
It's been observed that kzalloc() on lookup_all_xattrs() are called millions of times on Android, quickly becoming the top abuser of slub memory allocator.
Use a dedicated kmem cache pool for xattr lookups to mitigate this.
---
v2:
- avoid compile warning in f2fs_destroy_xattr_caches().
fs/f2fs/f2fs.h | 3 +++ fs/f2fs/super.c | 10 ++++++++- fs/f2fs/xattr.c | 54 ++++++++++++++++++++++++++++++++++++++++++++----- fs/f2fs/xattr.h | 4 ++++ 4 files changed, 65 insertions(+), 6 deletions(-)
fs/f2fs/f2fs.h +3 -0
@@ -1486,6 +1486,9 @@ struct f2fs_sb_info {__u32 s_chksum_seed;struct workqueue_struct *post_read_wq;/* post read workqueue */ + +struct kmem_cache *inline_xattr_slab;/* inline xattr entry */ +unsigned int inline_xattr_slab_size;/* default inline xattr slab size */ };struct f2fs_private_dio {
fs/f2fs/super.c +9 -1
@@ -1201,6 +1201,7 @@ static void f2fs_put_super(struct super_block *sb)kvfree (sbi->raw_super);destroy_device_list (sbi); +f2fs_destroy_xattr_caches (sbi);mempool_destroy (sbi->write_io_dummy);#ifdef CONFIG_QUOTA for (i =0 ; i <MAXQUOTAS ; i++)
@@ -3457,12 +3458,17 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) } } +/* init per sbi slab cache */ + err =f2fs_init_xattr_caches (sbi); +if (err) + goto free_io_dummy; +/* get an inode for meta space */ sbi->meta_inode =f2fs_iget (sb,F2FS_META_INO (sbi));if (IS_ERR (sbi->meta_inode)) {f2fs_err (sbi,"Failed to read F2FS meta data inode" ); err =PTR_ERR (sbi->meta_inode); - goto free_io_dummy; + goto free_xattr_cache; } err =f2fs_get_valid_checkpoint (sbi);
@@ -3735,6 +3741,8 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)make_bad_inode (sbi->meta_inode);iput (sbi->meta_inode); sbi->meta_inode =NULL ; +free_xattr_cache: +f2fs_destroy_xattr_caches (sbi); free_io_dummy:mempool_destroy (sbi->write_io_dummy); free_percpu:
fs/f2fs/xattr.c +49 -5
99 lines not on this page · raw message
fs/f2fs/xattr.h +4 -0
@@ -131,6 +131,8 @@ extern int f2fs_setxattr(struct inode *, int, const char *,extern int f2fs_getxattr (struct inode *,int ,const char *,void *,size_t ,struct page *);extern ssize_t f2fs_listxattr (struct dentry *,char *,size_t ); +extern int f2fs_init_xattr_caches (struct f2fs_sb_info *); +extern void f2fs_destroy_xattr_caches (struct f2fs_sb_info *);#else #define f2fs_xattr_handlers NULL
@@ -151,6 +153,8 @@ static inline ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, {return -EOPNOTSUPP ; } +static int f2fs_init_xattr_caches (struct f2fs_sb_info *sbi) {return 0 ; } +static void f2fs_destroy_xattr_caches (struct f2fs_sb_info *sbi) { }#endif #ifdef CONFIG_F2FS_FS_SECURITY
Signature · 1 line
2.18.0.rc1
Hi Chao.
I got the time around to test this patch.
The v2 patch seems to work just fine, and the code looks good.
fs/f2fs/xattr.c line 28
Quoted 11 lines · Chao Yu
fs/f2fs/xattr.c +3
-0@@ -23,6 +23,25 @@#include "xattr.h" #include "segment.h" +static void *xattr_alloc (struct f2fs_sb_info *sbi,int size,bool *is_inline) +{ + *is_inline = (size == sbi->inline_xattr_slab_size);
Would it be meaningless to change this to the following code? if (likely(size == sbi->inline_xattr_slab_size))
*is_inline = true;
else
*is_inline = false;The above statement seems to be only false during the initial mount and the rest(millions) seems to be always true.
Thanks.
Hi Ju Hyung,
Quoted 4 lines · Ju Hyung Park
Hi Chao.
I got the time around to test this patch.
The v2 patch seems to work just fine, and the code looks good.
Thanks a lot for the review and test.
Quoted 16 lines · Chao Yu
fs/f2fs/xattr.c line 28
Quoted 11 lines
fs/f2fs/xattr.c +3
-0@@ -23,6 +23,25 @@#include "xattr.h" #include "segment.h" +static void *xattr_alloc (struct f2fs_sb_info *sbi,int size,bool *is_inline) +{ + *is_inline = (size == sbi->inline_xattr_slab_size);Would it be meaningless to change this to the following code? if (
likely(size == sbi->inline_xattr_slab_size))
Quoted 3 lines
*is_inline = true;
else
*is_inline = false;Yup, I guess it's very rare that user will change inline xattr size via remount, so I'm okay with this change.
Jaegeuk,
Could you please help to update the patch in your git tree directly?
Thanks,
Quoted 7 lines
The above statement seems to be only false during the initial mount and the rest(millions) seems to be always true.
Thanks.
.
Jaegeuk Kim
maintainerQuoted 30 lines · Chao Yu
Hi Ju Hyung,
Quoted 4 lines · Ju Hyung Park
Hi Chao.
I got the time around to test this patch.
The v2 patch seems to work just fine, and the code looks good.Thanks a lot for the review and test.
Quoted 16 lines · Chao Yu
fs/f2fs/xattr.c line 28
Quoted 11 lines
fs/f2fs/xattr.c +3
-0@@ -23,6 +23,25 @@#include "xattr.h" #include "segment.h" +static void *xattr_alloc (struct f2fs_sb_info *sbi,int size,bool *is_inline) +{ + *is_inline = (size == sbi->inline_xattr_slab_size);Would it be meaningless to change this to the following code? if (
likely(size == sbi->inline_xattr_slab_size))Quoted 3 lines
*is_inline = true; else *is_inline = false;
Quoted 2 lines
Yup, I guess it's very rare that user will change inline xattr size via remount, so I'm okay with this change.
Applied like this. Thanks,
26 static void *xattr_alloc(struct f2fs_sb_info *sbi, int size, bool *is_inline) 27 {
28 if (likely(size == sbi->inline_xattr_slab_size)) {
29 *is_inline = true;
30 return kmem_cache_zalloc(sbi->inline_xattr_slab, GFP_NOFS);
31 } 32 *is_inline = false; 33 return f2fs_kzalloc(sbi, size, GFP_NOFS);
34 }
Quoted 14 lines
Jaegeuk,
Could you please help to update the patch in your git tree directly?
Thanks,
Quoted 7 lines
The above statement seems to be only false during the initial mount and the rest(millions) seems to be always true.
Thanks.
.