> -----Original Message-----
> From: [email protected] <[email protected]> On Behalf Of
> Chao Yu
> Sent: Saturday, November 13, 2021 2:36 PM
> To: 常凤楠 <[email protected]>; [email protected];
> [email protected]
> Subject: Re: [RFC PATCH] f2fs:compress: introduce compress private data
> slab cache
> 
> On 2021/10/28 19:24, Fengnan Chang wrote:
> > Add "f2fs_lzo_compress_private" and "f2fs_lz4_compress_private" slab
> > cache, to speed up memory allocation when init compress ctx.
> > No slab cache is added to zstd as the private data for zstd is related
> > to mount option, and too big.
> >
> > Signed-off-by: Fengnan Chang <[email protected]>
> > ---
> >   fs/f2fs/compress.c | 45
> ++++++++++++++++++++++++++++++++++++++++-----
> >   1 file changed, 40 insertions(+), 5 deletions(-)
> >
> > diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index
> > 7588e4e817b8..4a8a4858d358 100644
> > --- a/fs/f2fs/compress.c
> > +++ b/fs/f2fs/compress.c
> > @@ -171,10 +171,11 @@ void f2fs_compress_ctx_add_page(struct
> compress_ctx *cc, struct page *page)
> >   }
> >
> >   #ifdef CONFIG_F2FS_FS_LZO
> > +static struct kmem_cache *lzo_compress_private_slab;
> >   static int lzo_init_compress_ctx(struct compress_ctx *cc)
> >   {
> > -   cc->private = f2fs_kvmalloc(F2FS_I_SB(cc->inode),
> > -                           LZO1X_MEM_COMPRESS, GFP_NOFS);
> > +   cc->private = f2fs_kmem_cache_alloc(lzo_compress_private_slab,
> > +                   GFP_F2FS_ZERO, false, F2FS_I_SB(cc->inode));
> >     if (!cc->private)
> >             return -ENOMEM;
> >
> > @@ -184,7 +185,7 @@ static int lzo_init_compress_ctx(struct
> > compress_ctx *cc)
> >
> >   static void lzo_destroy_compress_ctx(struct compress_ctx *cc)
> >   {
> > -   kvfree(cc->private);
> > +   kmem_cache_free(lzo_compress_private_slab, cc->private);
> >     cc->private = NULL;
> >   }
> >
> > @@ -234,6 +235,7 @@ static const struct f2fs_compress_ops
> f2fs_lzo_ops = {
> >   #endif
> >
> >   #ifdef CONFIG_F2FS_FS_LZ4
> > +static struct kmem_cache *lz4_compress_private_slab;
> >   static int lz4_init_compress_ctx(struct compress_ctx *cc)
> >   {
> >     unsigned int size = LZ4_MEM_COMPRESS; @@ -243,7 +245,8 @@
> static
> > int lz4_init_compress_ctx(struct compress_ctx *cc)
> >             size = LZ4HC_MEM_COMPRESS;
> >   #endif
> >
> > -   cc->private = f2fs_kvmalloc(F2FS_I_SB(cc->inode), size, GFP_NOFS);
> 
> The size could be LZ4HC_MEM_COMPRESS rather than
> LZ4_MEM_COMPRESS if we enable lz4hc algorithm, so they should never
> share the same lz4_compress_private_slab slab cache.
> 
> Other concern is I'm not sure whether there is any side-effect if we
> introduce slab cache which has such large object size...


Yes, I have this concern too, but in my test, with slab cache indeed be 
faster...

> 
> Thanks,
> 
> > +   cc->private = f2fs_kmem_cache_alloc(lz4_compress_private_slab,
> > +                   GFP_F2FS_ZERO, false, F2FS_I_SB(cc->inode));
> >     if (!cc->private)
> >             return -ENOMEM;
> >
> > @@ -258,7 +261,7 @@ static int lz4_init_compress_ctx(struct
> > compress_ctx *cc)
> >
> >   static void lz4_destroy_compress_ctx(struct compress_ctx *cc)
> >   {
> > -   kvfree(cc->private);
> > +   kmem_cache_free(lz4_compress_private_slab, cc->private);
> >     cc->private = NULL;
> >   }
> >
> > @@ -1944,6 +1947,32 @@ void f2fs_destroy_page_array_cache(struct
> f2fs_sb_info *sbi)
> >   {
> >     kmem_cache_destroy(sbi->page_array_slab);
> >   }
> > +static int __init f2fs_init_compress_private_cache(void)
> > +{
> > +#ifdef CONFIG_F2FS_FS_LZ4
> > +   lz4_compress_private_slab =
> f2fs_kmem_cache_create("f2fs_lz4_compress_private",
> > +                                   LZ4_MEM_COMPRESS);
> > +   if (!lz4_compress_private_slab)
> > +           return -ENOMEM;
> > +#endif
> > +#ifdef CONFIG_F2FS_FS_LZO
> > +   lzo_compress_private_slab =
> f2fs_kmem_cache_create("f2fs_lzo_compress_private",
> > +                                   LZO1X_MEM_COMPRESS);
> > +   if (!lzo_compress_private_slab)
> > +           return -ENOMEM;
> > +#endif
> > +   return 0;
> > +}
> > +
> > +static void f2fs_destroy_compress_private_cache(void)
> > +{
> > +#ifdef CONFIG_F2FS_FS_LZ4
> > +   kmem_cache_destroy(lz4_compress_private_slab);
> > +#endif
> > +#ifdef CONFIG_F2FS_FS_LZO
> > +   kmem_cache_destroy(lzo_compress_private_slab);
> > +#endif
> > +}
> >
> >   static int __init f2fs_init_cic_cache(void)
> >   {
> > @@ -1983,7 +2012,12 @@ int __init f2fs_init_compress_cache(void)
> >     err = f2fs_init_dic_cache();
> >     if (err)
> >             goto free_cic;
> > +   err = f2fs_init_compress_private_cache();
> > +   if (err)
> > +           goto free_dic;
> >     return 0;
> > +free_dic:
> > +   f2fs_destroy_dic_cache();
> >   free_cic:
> >     f2fs_destroy_cic_cache();
> >   out:
> > @@ -1994,4 +2028,5 @@ void f2fs_destroy_compress_cache(void)
> >   {
> >     f2fs_destroy_dic_cache();
> >     f2fs_destroy_cic_cache();
> > +   f2fs_destroy_compress_private_cache();
> >   }
> >

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to