Skip to content

Commit 7bf4994

Browse files
dennisszhoukdave
authored andcommitted
btrfs: plumb level through the compression interface
Zlib compression supports multiple levels, but doesn't require changing in how a workspace itself is created and managed. Zstd introduces a different memory requirement such that higher levels of compression require more memory. This requires changes in how the alloc()/get() methods work for zstd. This pach plumbs compression level through the interface as a parameter in preparation for zstd compression levels. This gives the compression types opportunity to create/manage based on the compression level. Reviewed-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Josef Bacik <josef@toxicpanda.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 92ee553 commit 7bf4994

5 files changed

Lines changed: 30 additions & 27 deletions

File tree

‎fs/btrfs/compression.c‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -742,9 +742,9 @@ static void heuristic_cleanup_workspace_manager(void)
742742
btrfs_cleanup_workspace_manager(&heuristic_wsm);
743743
}
744744

745-
static struct list_head *heuristic_get_workspace(void)
745+
static struct list_head *heuristic_get_workspace(unsigned int level)
746746
{
747-
return btrfs_get_workspace(&heuristic_wsm);
747+
return btrfs_get_workspace(&heuristic_wsm, level);
748748
}
749749

750750
static void heuristic_put_workspace(struct list_head *ws)
@@ -764,7 +764,7 @@ static void free_heuristic_ws(struct list_head *ws)
764764
kfree(workspace);
765765
}
766766

767-
static struct list_head *alloc_heuristic_ws(void)
767+
static struct list_head *alloc_heuristic_ws(unsigned int level)
768768
{
769769
struct heuristic_ws *ws;
770770

@@ -824,7 +824,7 @@ void btrfs_init_workspace_manager(struct workspace_manager *wsm,
824824
* Preallocate one workspace for each compression type so we can
825825
* guarantee forward progress in the worst case
826826
*/
827-
workspace = wsm->ops->alloc_workspace();
827+
workspace = wsm->ops->alloc_workspace(0);
828828
if (IS_ERR(workspace)) {
829829
pr_warn(
830830
"BTRFS: cannot preallocate compression workspace, will try later\n");
@@ -853,7 +853,8 @@ void btrfs_cleanup_workspace_manager(struct workspace_manager *wsman)
853853
* Preallocation makes a forward progress guarantees and we do not return
854854
* errors.
855855
*/
856-
struct list_head *btrfs_get_workspace(struct workspace_manager *wsm)
856+
struct list_head *btrfs_get_workspace(struct workspace_manager *wsm,
857+
unsigned int level)
857858
{
858859
struct list_head *workspace;
859860
int cpus = num_online_cpus();
@@ -899,7 +900,7 @@ struct list_head *btrfs_get_workspace(struct workspace_manager *wsm)
899900
* context of btrfs_compress_bio/btrfs_compress_pages
900901
*/
901902
nofs_flag = memalloc_nofs_save();
902-
workspace = wsm->ops->alloc_workspace();
903+
workspace = wsm->ops->alloc_workspace(level);
903904
memalloc_nofs_restore(nofs_flag);
904905

905906
if (IS_ERR(workspace)) {
@@ -930,9 +931,9 @@ struct list_head *btrfs_get_workspace(struct workspace_manager *wsm)
930931
return workspace;
931932
}
932933

933-
static struct list_head *get_workspace(int type)
934+
static struct list_head *get_workspace(int type, int level)
934935
{
935-
return btrfs_compress_op[type]->get_workspace();
936+
return btrfs_compress_op[type]->get_workspace(level);
936937
}
937938

938939
/*
@@ -1003,12 +1004,13 @@ int btrfs_compress_pages(unsigned int type_level, struct address_space *mapping,
10031004
unsigned long *total_out)
10041005
{
10051006
int type = btrfs_compress_type(type_level);
1007+
int level = btrfs_compress_level(type_level);
10061008
struct list_head *workspace;
10071009
int ret;
10081010

1009-
workspace = get_workspace(type);
1011+
workspace = get_workspace(type, level);
10101012

1011-
btrfs_compress_op[type]->set_level(workspace, type_level);
1013+
btrfs_compress_op[type]->set_level(workspace, level);
10121014
ret = btrfs_compress_op[type]->compress_pages(workspace, mapping,
10131015
start, pages,
10141016
out_pages,
@@ -1037,7 +1039,7 @@ static int btrfs_decompress_bio(struct compressed_bio *cb)
10371039
int ret;
10381040
int type = cb->compress_type;
10391041

1040-
workspace = get_workspace(type);
1042+
workspace = get_workspace(type, 0);
10411043
ret = btrfs_compress_op[type]->decompress_bio(workspace, cb);
10421044
put_workspace(type, workspace);
10431045

@@ -1055,13 +1057,12 @@ int btrfs_decompress(int type, unsigned char *data_in, struct page *dest_page,
10551057
struct list_head *workspace;
10561058
int ret;
10571059

1058-
workspace = get_workspace(type);
1059-
1060+
workspace = get_workspace(type, 0);
10601061
ret = btrfs_compress_op[type]->decompress(workspace, data_in,
10611062
dest_page, start_byte,
10621063
srclen, destlen);
1063-
10641064
put_workspace(type, workspace);
1065+
10651066
return ret;
10661067
}
10671068

@@ -1489,7 +1490,7 @@ static void heuristic_collect_sample(struct inode *inode, u64 start, u64 end,
14891490
*/
14901491
int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end)
14911492
{
1492-
struct list_head *ws_list = get_workspace(0);
1493+
struct list_head *ws_list = get_workspace(0, 0);
14931494
struct heuristic_ws *ws;
14941495
u32 i;
14951496
u8 byte;

‎fs/btrfs/compression.h‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ struct workspace_manager {
121121

122122
void btrfs_init_workspace_manager(struct workspace_manager *wsm,
123123
const struct btrfs_compress_op *ops);
124-
struct list_head *btrfs_get_workspace(struct workspace_manager *wsm);
124+
struct list_head *btrfs_get_workspace(struct workspace_manager *wsm,
125+
unsigned int level);
125126
void btrfs_put_workspace(struct workspace_manager *wsm, struct list_head *ws);
126127
void btrfs_cleanup_workspace_manager(struct workspace_manager *wsm);
127128

@@ -130,11 +131,11 @@ struct btrfs_compress_op {
130131

131132
void (*cleanup_workspace_manager)(void);
132133

133-
struct list_head *(*get_workspace)(void);
134+
struct list_head *(*get_workspace)(unsigned int level);
134135

135136
void (*put_workspace)(struct list_head *ws);
136137

137-
struct list_head *(*alloc_workspace)(void);
138+
struct list_head *(*alloc_workspace)(unsigned int level);
138139

139140
void (*free_workspace)(struct list_head *workspace);
140141

‎fs/btrfs/lzo.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ static void lzo_cleanup_workspace_manager(void)
7373
btrfs_cleanup_workspace_manager(&wsm);
7474
}
7575

76-
static struct list_head *lzo_get_workspace(void)
76+
static struct list_head *lzo_get_workspace(unsigned int level)
7777
{
78-
return btrfs_get_workspace(&wsm);
78+
return btrfs_get_workspace(&wsm, level);
7979
}
8080

8181
static void lzo_put_workspace(struct list_head *ws)
@@ -93,7 +93,7 @@ static void lzo_free_workspace(struct list_head *ws)
9393
kfree(workspace);
9494
}
9595

96-
static struct list_head *lzo_alloc_workspace(void)
96+
static struct list_head *lzo_alloc_workspace(unsigned int level)
9797
{
9898
struct workspace *workspace;
9999

‎fs/btrfs/zlib.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ static void zlib_cleanup_workspace_manager(void)
3939
btrfs_cleanup_workspace_manager(&wsm);
4040
}
4141

42-
static struct list_head *zlib_get_workspace(void)
42+
static struct list_head *zlib_get_workspace(unsigned int level)
4343
{
44-
return btrfs_get_workspace(&wsm);
44+
return btrfs_get_workspace(&wsm, level);
4545
}
4646

4747
static void zlib_put_workspace(struct list_head *ws)
@@ -58,7 +58,7 @@ static void zlib_free_workspace(struct list_head *ws)
5858
kfree(workspace);
5959
}
6060

61-
static struct list_head *zlib_alloc_workspace(void)
61+
static struct list_head *zlib_alloc_workspace(unsigned int level)
6262
{
6363
struct workspace *workspace;
6464
int workspacesize;
@@ -70,6 +70,7 @@ static struct list_head *zlib_alloc_workspace(void)
7070
workspacesize = max(zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL),
7171
zlib_inflate_workspacesize());
7272
workspace->strm.workspace = kvmalloc(workspacesize, GFP_KERNEL);
73+
workspace->level = level;
7374
workspace->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
7475
if (!workspace->strm.workspace || !workspace->buf)
7576
goto fail;

‎fs/btrfs/zstd.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ static void zstd_cleanup_workspace_manager(void)
5353
btrfs_cleanup_workspace_manager(&wsm);
5454
}
5555

56-
static struct list_head *zstd_get_workspace(void)
56+
static struct list_head *zstd_get_workspace(unsigned int level)
5757
{
58-
return btrfs_get_workspace(&wsm);
58+
return btrfs_get_workspace(&wsm, level);
5959
}
6060

6161
static void zstd_put_workspace(struct list_head *ws)
@@ -72,7 +72,7 @@ static void zstd_free_workspace(struct list_head *ws)
7272
kfree(workspace);
7373
}
7474

75-
static struct list_head *zstd_alloc_workspace(void)
75+
static struct list_head *zstd_alloc_workspace(unsigned int level)
7676
{
7777
ZSTD_parameters params =
7878
zstd_get_btrfs_parameters(ZSTD_BTRFS_MAX_INPUT);

0 commit comments

Comments
 (0)