diff mbox series

[10/11] btrfs: zstd use the passed through level instead of default

Message ID 20190128212437.11597-11-dennis@kernel.org (mailing list archive)
State New, archived
Headers show
Series btrfs: add zstd compression level support | expand

Commit Message

Dennis Zhou Jan. 28, 2019, 9:24 p.m. UTC
Zstd currently only supports the default level of compression. This
patch switches to using the level passed in for btrfs zstd
configuration.

Zstd workspaces now keep track of the requested level as this can differ
from the size of the workspace.

Signed-off-by: Dennis Zhou <dennis@kernel.org>
---
 fs/btrfs/zstd.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

Comments

Nikolay Borisov Jan. 29, 2019, 8:15 a.m. UTC | #1
On 28.01.19 г. 23:24 ч., Dennis Zhou wrote:
> Zstd currently only supports the default level of compression. This
> patch switches to using the level passed in for btrfs zstd
> configuration.
> 
> Zstd workspaces now keep track of the requested level as this can differ
> from the size of the workspace.
> 
> Signed-off-by: Dennis Zhou <dennis@kernel.org>

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

> ---
>  fs/btrfs/zstd.c | 19 +++++++++++++------
>  1 file changed, 13 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c
> index 43f3be755b8c..a951d4fe77f7 100644
> --- a/fs/btrfs/zstd.c
> +++ b/fs/btrfs/zstd.c
> @@ -21,10 +21,10 @@
>  #define ZSTD_BTRFS_MAX_INPUT (1 << ZSTD_BTRFS_MAX_WINDOWLOG)
>  #define ZSTD_BTRFS_DEFAULT_LEVEL 3
>  
> -static ZSTD_parameters zstd_get_btrfs_parameters(size_t src_len)
> +static ZSTD_parameters zstd_get_btrfs_parameters(unsigned int level,
> +						 size_t src_len)
>  {
> -	ZSTD_parameters params = ZSTD_getParams(ZSTD_BTRFS_DEFAULT_LEVEL,
> -						src_len, 0);
> +	ZSTD_parameters params = ZSTD_getParams(level, src_len, 0);
>  
>  	if (params.cParams.windowLog > ZSTD_BTRFS_MAX_WINDOWLOG)
>  		params.cParams.windowLog = ZSTD_BTRFS_MAX_WINDOWLOG;
> @@ -36,6 +36,7 @@ struct workspace {
>  	void *mem;
>  	size_t size;
>  	char *buf;
> +	unsigned int req_level;
>  	struct list_head list;
>  	ZSTD_inBuffer in_buf;
>  	ZSTD_outBuffer out_buf;
> @@ -55,7 +56,12 @@ static void zstd_cleanup_workspace_manager(void)
>  
>  static struct list_head *zstd_get_workspace(unsigned int level)
>  {
> -	return btrfs_get_workspace(&wsm, level);
> +	struct list_head *ws = btrfs_get_workspace(&wsm, level);
> +	struct workspace *workspace = list_entry(ws, struct workspace, list);
> +
> +	workspace->req_level = level;
> +
> +	return ws;
>  }
>  
>  static void zstd_put_workspace(struct list_head *ws)
> @@ -75,7 +81,7 @@ static void zstd_free_workspace(struct list_head *ws)
>  static struct list_head *zstd_alloc_workspace(unsigned int level)
>  {
>  	ZSTD_parameters params =
> -			zstd_get_btrfs_parameters(ZSTD_BTRFS_MAX_INPUT);
> +			zstd_get_btrfs_parameters(level, ZSTD_BTRFS_MAX_INPUT);
>  	struct workspace *workspace;
>  
>  	workspace = kzalloc(sizeof(*workspace), GFP_KERNEL);
> @@ -117,7 +123,8 @@ static int zstd_compress_pages(struct list_head *ws,
>  	unsigned long len = *total_out;
>  	const unsigned long nr_dest_pages = *out_pages;
>  	unsigned long max_out = nr_dest_pages * PAGE_SIZE;
> -	ZSTD_parameters params = zstd_get_btrfs_parameters(len);
> +	ZSTD_parameters params = zstd_get_btrfs_parameters(workspace->req_level,
> +							   len);
>  
>  	*out_pages = 0;
>  	*total_out = 0;
>
diff mbox series

Patch

diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c
index 43f3be755b8c..a951d4fe77f7 100644
--- a/fs/btrfs/zstd.c
+++ b/fs/btrfs/zstd.c
@@ -21,10 +21,10 @@ 
 #define ZSTD_BTRFS_MAX_INPUT (1 << ZSTD_BTRFS_MAX_WINDOWLOG)
 #define ZSTD_BTRFS_DEFAULT_LEVEL 3
 
-static ZSTD_parameters zstd_get_btrfs_parameters(size_t src_len)
+static ZSTD_parameters zstd_get_btrfs_parameters(unsigned int level,
+						 size_t src_len)
 {
-	ZSTD_parameters params = ZSTD_getParams(ZSTD_BTRFS_DEFAULT_LEVEL,
-						src_len, 0);
+	ZSTD_parameters params = ZSTD_getParams(level, src_len, 0);
 
 	if (params.cParams.windowLog > ZSTD_BTRFS_MAX_WINDOWLOG)
 		params.cParams.windowLog = ZSTD_BTRFS_MAX_WINDOWLOG;
@@ -36,6 +36,7 @@  struct workspace {
 	void *mem;
 	size_t size;
 	char *buf;
+	unsigned int req_level;
 	struct list_head list;
 	ZSTD_inBuffer in_buf;
 	ZSTD_outBuffer out_buf;
@@ -55,7 +56,12 @@  static void zstd_cleanup_workspace_manager(void)
 
 static struct list_head *zstd_get_workspace(unsigned int level)
 {
-	return btrfs_get_workspace(&wsm, level);
+	struct list_head *ws = btrfs_get_workspace(&wsm, level);
+	struct workspace *workspace = list_entry(ws, struct workspace, list);
+
+	workspace->req_level = level;
+
+	return ws;
 }
 
 static void zstd_put_workspace(struct list_head *ws)
@@ -75,7 +81,7 @@  static void zstd_free_workspace(struct list_head *ws)
 static struct list_head *zstd_alloc_workspace(unsigned int level)
 {
 	ZSTD_parameters params =
-			zstd_get_btrfs_parameters(ZSTD_BTRFS_MAX_INPUT);
+			zstd_get_btrfs_parameters(level, ZSTD_BTRFS_MAX_INPUT);
 	struct workspace *workspace;
 
 	workspace = kzalloc(sizeof(*workspace), GFP_KERNEL);
@@ -117,7 +123,8 @@  static int zstd_compress_pages(struct list_head *ws,
 	unsigned long len = *total_out;
 	const unsigned long nr_dest_pages = *out_pages;
 	unsigned long max_out = nr_dest_pages * PAGE_SIZE;
-	ZSTD_parameters params = zstd_get_btrfs_parameters(len);
+	ZSTD_parameters params = zstd_get_btrfs_parameters(workspace->req_level,
+							   len);
 
 	*out_pages = 0;
 	*total_out = 0;