All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Chao Yu <yuchao0@huawei.com>
Cc: jaegeuk@kernel.org, linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH] f2fs: compress: support zstd compress algorithm
Date: Mon, 2 Mar 2020 09:50:14 -0800	[thread overview]
Message-ID: <20200302175014.GA98133@gmail.com> (raw)
In-Reply-To: <20200228111456.11311-1-yuchao0@huawei.com>

On Fri, Feb 28, 2020 at 07:14:56PM +0800, Chao Yu wrote:
> Add zstd compress algorithm support, use "compress_algorithm=zstd"
> mountoption to enable it.
> 
> Signed-off-by: Chao Yu <yuchao0@huawei.com>
> ---
>  Documentation/filesystems/f2fs.txt |   4 +-
>  fs/f2fs/Kconfig                    |   9 ++
>  fs/f2fs/compress.c                 | 151 +++++++++++++++++++++++++++++
>  fs/f2fs/f2fs.h                     |   2 +
>  fs/f2fs/super.c                    |   7 ++
>  include/trace/events/f2fs.h        |   3 +-
>  6 files changed, 173 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/filesystems/f2fs.txt b/Documentation/filesystems/f2fs.txt
> index 4eb3e2ddd00e..b1a66cf0e967 100644
> --- a/Documentation/filesystems/f2fs.txt
> +++ b/Documentation/filesystems/f2fs.txt
> @@ -235,8 +235,8 @@ checkpoint=%s[:%u[%]]     Set to "disable" to turn off checkpointing. Set to "en
>                         hide up to all remaining free space. The actual space that
>                         would be unusable can be viewed at /sys/fs/f2fs/<disk>/unusable
>                         This space is reclaimed once checkpoint=enable.
> -compress_algorithm=%s  Control compress algorithm, currently f2fs supports "lzo"
> -                       and "lz4" algorithm.
> +compress_algorithm=%s  Control compress algorithm, currently f2fs supports "lzo",
> +                       "lz4" and "zstd" algorithm.
>  compress_log_size=%u   Support configuring compress cluster size, the size will
>                         be 4KB * (1 << %u), 16KB is minimum size, also it's
>                         default size.
> diff --git a/fs/f2fs/Kconfig b/fs/f2fs/Kconfig
> index f0faada30f30..bb68d21e1f8c 100644
> --- a/fs/f2fs/Kconfig
> +++ b/fs/f2fs/Kconfig
> @@ -118,3 +118,12 @@ config F2FS_FS_LZ4
>  	default y
>  	help
>  	  Support LZ4 compress algorithm, if unsure, say Y.
> +
> +config F2FS_FS_ZSTD
> +	bool "ZSTD compression support"
> +	depends on F2FS_FS_COMPRESSION
> +	select ZSTD_COMPRESS
> +	select ZSTD_DECOMPRESS
> +	default y
> +	help
> +	  Support ZSTD compress algorithm, if unsure, say Y.
> diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
> index bd3ea01db448..c8e1175eaf4e 100644
> --- a/fs/f2fs/compress.c
> +++ b/fs/f2fs/compress.c
> @@ -11,6 +11,7 @@
>  #include <linux/backing-dev.h>
>  #include <linux/lzo.h>
>  #include <linux/lz4.h>
> +#include <linux/zstd.h>
>  
>  #include "f2fs.h"
>  #include "node.h"
> @@ -291,6 +292,151 @@ static const struct f2fs_compress_ops f2fs_lz4_ops = {
>  };
>  #endif
>  
> +#ifdef CONFIG_F2FS_FS_ZSTD
> +#define F2FS_ZSTD_DEFAULT_CLEVEL	1
> +
> +static int zstd_init_compress_ctx(struct compress_ctx *cc)
> +{
> +	return 0;
> +}
> +
> +static void zstd_destroy_compress_ctx(struct compress_ctx *cc)
> +{
> +}
> +
> +static int zstd_compress_pages(struct compress_ctx *cc)
> +{
> +	ZSTD_parameters params;
> +	ZSTD_CStream *stream;
> +	ZSTD_inBuffer inbuf;
> +	ZSTD_outBuffer outbuf;
> +	void *workspace;
> +	unsigned int workspace_size;
> +	int src_size = cc->rlen;
> +	int dst_size = src_size - PAGE_SIZE - COMPRESS_HEADER_SIZE;
> +	int ret;
> +
> +	params = ZSTD_getParams(F2FS_ZSTD_DEFAULT_CLEVEL, src_size, 0);
> +	workspace_size = ZSTD_CStreamWorkspaceBound(params.cParams);
> +
> +	workspace = f2fs_kvmalloc(F2FS_I_SB(cc->inode),
> +					workspace_size, GFP_NOFS);
> +	if (!workspace)
> +		return -ENOMEM;
> +
> +	stream = ZSTD_initCStream(params, 0,
> +					workspace, workspace_size);

Why is this allocating the memory for every compression operation, instead of
ahead of time in ->init_compress_ctx()?

- Eric


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

WARNING: multiple messages have this Message-ID (diff)
From: Eric Biggers <ebiggers@kernel.org>
To: Chao Yu <yuchao0@huawei.com>
Cc: jaegeuk@kernel.org, linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [PATCH] f2fs: compress: support zstd compress algorithm
Date: Mon, 2 Mar 2020 09:50:14 -0800	[thread overview]
Message-ID: <20200302175014.GA98133@gmail.com> (raw)
In-Reply-To: <20200228111456.11311-1-yuchao0@huawei.com>

On Fri, Feb 28, 2020 at 07:14:56PM +0800, Chao Yu wrote:
> Add zstd compress algorithm support, use "compress_algorithm=zstd"
> mountoption to enable it.
> 
> Signed-off-by: Chao Yu <yuchao0@huawei.com>
> ---
>  Documentation/filesystems/f2fs.txt |   4 +-
>  fs/f2fs/Kconfig                    |   9 ++
>  fs/f2fs/compress.c                 | 151 +++++++++++++++++++++++++++++
>  fs/f2fs/f2fs.h                     |   2 +
>  fs/f2fs/super.c                    |   7 ++
>  include/trace/events/f2fs.h        |   3 +-
>  6 files changed, 173 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/filesystems/f2fs.txt b/Documentation/filesystems/f2fs.txt
> index 4eb3e2ddd00e..b1a66cf0e967 100644
> --- a/Documentation/filesystems/f2fs.txt
> +++ b/Documentation/filesystems/f2fs.txt
> @@ -235,8 +235,8 @@ checkpoint=%s[:%u[%]]     Set to "disable" to turn off checkpointing. Set to "en
>                         hide up to all remaining free space. The actual space that
>                         would be unusable can be viewed at /sys/fs/f2fs/<disk>/unusable
>                         This space is reclaimed once checkpoint=enable.
> -compress_algorithm=%s  Control compress algorithm, currently f2fs supports "lzo"
> -                       and "lz4" algorithm.
> +compress_algorithm=%s  Control compress algorithm, currently f2fs supports "lzo",
> +                       "lz4" and "zstd" algorithm.
>  compress_log_size=%u   Support configuring compress cluster size, the size will
>                         be 4KB * (1 << %u), 16KB is minimum size, also it's
>                         default size.
> diff --git a/fs/f2fs/Kconfig b/fs/f2fs/Kconfig
> index f0faada30f30..bb68d21e1f8c 100644
> --- a/fs/f2fs/Kconfig
> +++ b/fs/f2fs/Kconfig
> @@ -118,3 +118,12 @@ config F2FS_FS_LZ4
>  	default y
>  	help
>  	  Support LZ4 compress algorithm, if unsure, say Y.
> +
> +config F2FS_FS_ZSTD
> +	bool "ZSTD compression support"
> +	depends on F2FS_FS_COMPRESSION
> +	select ZSTD_COMPRESS
> +	select ZSTD_DECOMPRESS
> +	default y
> +	help
> +	  Support ZSTD compress algorithm, if unsure, say Y.
> diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
> index bd3ea01db448..c8e1175eaf4e 100644
> --- a/fs/f2fs/compress.c
> +++ b/fs/f2fs/compress.c
> @@ -11,6 +11,7 @@
>  #include <linux/backing-dev.h>
>  #include <linux/lzo.h>
>  #include <linux/lz4.h>
> +#include <linux/zstd.h>
>  
>  #include "f2fs.h"
>  #include "node.h"
> @@ -291,6 +292,151 @@ static const struct f2fs_compress_ops f2fs_lz4_ops = {
>  };
>  #endif
>  
> +#ifdef CONFIG_F2FS_FS_ZSTD
> +#define F2FS_ZSTD_DEFAULT_CLEVEL	1
> +
> +static int zstd_init_compress_ctx(struct compress_ctx *cc)
> +{
> +	return 0;
> +}
> +
> +static void zstd_destroy_compress_ctx(struct compress_ctx *cc)
> +{
> +}
> +
> +static int zstd_compress_pages(struct compress_ctx *cc)
> +{
> +	ZSTD_parameters params;
> +	ZSTD_CStream *stream;
> +	ZSTD_inBuffer inbuf;
> +	ZSTD_outBuffer outbuf;
> +	void *workspace;
> +	unsigned int workspace_size;
> +	int src_size = cc->rlen;
> +	int dst_size = src_size - PAGE_SIZE - COMPRESS_HEADER_SIZE;
> +	int ret;
> +
> +	params = ZSTD_getParams(F2FS_ZSTD_DEFAULT_CLEVEL, src_size, 0);
> +	workspace_size = ZSTD_CStreamWorkspaceBound(params.cParams);
> +
> +	workspace = f2fs_kvmalloc(F2FS_I_SB(cc->inode),
> +					workspace_size, GFP_NOFS);
> +	if (!workspace)
> +		return -ENOMEM;
> +
> +	stream = ZSTD_initCStream(params, 0,
> +					workspace, workspace_size);

Why is this allocating the memory for every compression operation, instead of
ahead of time in ->init_compress_ctx()?

- Eric

  reply	other threads:[~2020-03-02 17:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-28 11:14 [f2fs-dev] [PATCH] f2fs: compress: support zstd compress algorithm Chao Yu
2020-02-28 11:14 ` Chao Yu
2020-03-02 17:50 ` Eric Biggers [this message]
2020-03-02 17:50   ` Eric Biggers
2020-03-03  1:50   ` [f2fs-dev] " Chao Yu
2020-03-03  1:50     ` Chao Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200302175014.GA98133@gmail.com \
    --to=ebiggers@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yuchao0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.