Skip to content

Commit e0dc87a

Browse files
dennisszhoukdave
authored andcommitted
btrfs: zstd use the passed through level instead of default
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. Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Dennis Zhou <dennis@kernel.org> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent d0ab62c commit e0dc87a

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

‎fs/btrfs/zstd.c‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
#define ZSTD_BTRFS_MAX_INPUT (1 << ZSTD_BTRFS_MAX_WINDOWLOG)
2222
#define ZSTD_BTRFS_DEFAULT_LEVEL 3
2323

24-
static ZSTD_parameters zstd_get_btrfs_parameters(size_t src_len)
24+
static ZSTD_parameters zstd_get_btrfs_parameters(unsigned int level,
25+
size_t src_len)
2526
{
26-
ZSTD_parameters params = ZSTD_getParams(ZSTD_BTRFS_DEFAULT_LEVEL,
27-
src_len, 0);
27+
ZSTD_parameters params = ZSTD_getParams(level, src_len, 0);
2828

2929
if (params.cParams.windowLog > ZSTD_BTRFS_MAX_WINDOWLOG)
3030
params.cParams.windowLog = ZSTD_BTRFS_MAX_WINDOWLOG;
@@ -36,6 +36,7 @@ struct workspace {
3636
void *mem;
3737
size_t size;
3838
char *buf;
39+
unsigned int req_level;
3940
struct list_head list;
4041
ZSTD_inBuffer in_buf;
4142
ZSTD_outBuffer out_buf;
@@ -55,7 +56,12 @@ static void zstd_cleanup_workspace_manager(void)
5556

5657
static struct list_head *zstd_get_workspace(unsigned int level)
5758
{
58-
return btrfs_get_workspace(&wsm, level);
59+
struct list_head *ws = btrfs_get_workspace(&wsm, level);
60+
struct workspace *workspace = list_entry(ws, struct workspace, list);
61+
62+
workspace->req_level = level;
63+
64+
return ws;
5965
}
6066

6167
static void zstd_put_workspace(struct list_head *ws)
@@ -75,7 +81,7 @@ static void zstd_free_workspace(struct list_head *ws)
7581
static struct list_head *zstd_alloc_workspace(unsigned int level)
7682
{
7783
ZSTD_parameters params =
78-
zstd_get_btrfs_parameters(ZSTD_BTRFS_MAX_INPUT);
84+
zstd_get_btrfs_parameters(level, ZSTD_BTRFS_MAX_INPUT);
7985
struct workspace *workspace;
8086

8187
workspace = kzalloc(sizeof(*workspace), GFP_KERNEL);
@@ -117,7 +123,8 @@ static int zstd_compress_pages(struct list_head *ws,
117123
unsigned long len = *total_out;
118124
const unsigned long nr_dest_pages = *out_pages;
119125
unsigned long max_out = nr_dest_pages * PAGE_SIZE;
120-
ZSTD_parameters params = zstd_get_btrfs_parameters(len);
126+
ZSTD_parameters params = zstd_get_btrfs_parameters(workspace->req_level,
127+
len);
121128

122129
*out_pages = 0;
123130
*total_out = 0;

0 commit comments

Comments
 (0)