All of lore.kernel.org
 help / color / mirror / Atom feed
* [f2fs-dev] [RFC PATCH] f2fs:compress: introduce compress private data slab cache
@ 2021-10-28 11:24 Fengnan Chang
  2021-11-13  6:35 ` Chao Yu
       [not found] ` <AIIAWwDBE7sNmxjtkrk7dqq6.9.1636785352506.Hmail.changfengnan@vivo.com>
  0 siblings, 2 replies; 3+ messages in thread
From: Fengnan Chang @ 2021-10-28 11:24 UTC (permalink / raw)
  To: jaegeuk, chao, linux-f2fs-devel; +Cc: Fengnan Chang

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 <changfengnan@vivo.com>
---
 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);
+	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();
 }
-- 
2.32.0



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [f2fs-dev] [RFC PATCH] f2fs:compress: introduce compress private data slab cache
  2021-10-28 11:24 [f2fs-dev] [RFC PATCH] f2fs:compress: introduce compress private data slab cache Fengnan Chang
@ 2021-11-13  6:35 ` Chao Yu
       [not found] ` <AIIAWwDBE7sNmxjtkrk7dqq6.9.1636785352506.Hmail.changfengnan@vivo.com>
  1 sibling, 0 replies; 3+ messages in thread
From: Chao Yu @ 2021-11-13  6:35 UTC (permalink / raw)
  To: Fengnan Chang, jaegeuk, linux-f2fs-devel

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 <changfengnan@vivo.com>
> ---
>   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...

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
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [f2fs-dev] [RFC PATCH] f2fs:compress: introduce compress private data slab cache
       [not found] ` <AIIAWwDBE7sNmxjtkrk7dqq6.9.1636785352506.Hmail.changfengnan@vivo.com>
@ 2021-11-15  2:28   ` 常凤楠
  0 siblings, 0 replies; 3+ messages in thread
From: 常凤楠 @ 2021-11-15  2:28 UTC (permalink / raw)
  To: Chao Yu, jaegeuk, linux-f2fs-devel



> -----Original Message-----
> From: changfengnan@vivo.com <changfengnan@vivo.com> On Behalf Of
> Chao Yu
> Sent: Saturday, November 13, 2021 2:36 PM
> To: 常凤楠 <changfengnan@vivo.com>; jaegeuk@kernel.org;
> linux-f2fs-devel@lists.sourceforge.net
> 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 <changfengnan@vivo.com>
> > ---
> >   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
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-15  2:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-28 11:24 [f2fs-dev] [RFC PATCH] f2fs:compress: introduce compress private data slab cache Fengnan Chang
2021-11-13  6:35 ` Chao Yu
     [not found] ` <AIIAWwDBE7sNmxjtkrk7dqq6.9.1636785352506.Hmail.changfengnan@vivo.com>
2021-11-15  2:28   ` 常凤楠

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.