mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-05 22:28:00 +00:00
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>
This commit is contained in:
parent
92ee553036
commit
7bf4994304
5 changed files with 30 additions and 27 deletions
|
@ -742,9 +742,9 @@ static void heuristic_cleanup_workspace_manager(void)
|
||||||
btrfs_cleanup_workspace_manager(&heuristic_wsm);
|
btrfs_cleanup_workspace_manager(&heuristic_wsm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct list_head *heuristic_get_workspace(void)
|
static struct list_head *heuristic_get_workspace(unsigned int level)
|
||||||
{
|
{
|
||||||
return btrfs_get_workspace(&heuristic_wsm);
|
return btrfs_get_workspace(&heuristic_wsm, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void heuristic_put_workspace(struct list_head *ws)
|
static void heuristic_put_workspace(struct list_head *ws)
|
||||||
|
@ -764,7 +764,7 @@ static void free_heuristic_ws(struct list_head *ws)
|
||||||
kfree(workspace);
|
kfree(workspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct list_head *alloc_heuristic_ws(void)
|
static struct list_head *alloc_heuristic_ws(unsigned int level)
|
||||||
{
|
{
|
||||||
struct heuristic_ws *ws;
|
struct heuristic_ws *ws;
|
||||||
|
|
||||||
|
@ -824,7 +824,7 @@ void btrfs_init_workspace_manager(struct workspace_manager *wsm,
|
||||||
* Preallocate one workspace for each compression type so we can
|
* Preallocate one workspace for each compression type so we can
|
||||||
* guarantee forward progress in the worst case
|
* guarantee forward progress in the worst case
|
||||||
*/
|
*/
|
||||||
workspace = wsm->ops->alloc_workspace();
|
workspace = wsm->ops->alloc_workspace(0);
|
||||||
if (IS_ERR(workspace)) {
|
if (IS_ERR(workspace)) {
|
||||||
pr_warn(
|
pr_warn(
|
||||||
"BTRFS: cannot preallocate compression workspace, will try later\n");
|
"BTRFS: cannot preallocate compression workspace, will try later\n");
|
||||||
|
@ -853,7 +853,8 @@ void btrfs_cleanup_workspace_manager(struct workspace_manager *wsman)
|
||||||
* Preallocation makes a forward progress guarantees and we do not return
|
* Preallocation makes a forward progress guarantees and we do not return
|
||||||
* errors.
|
* errors.
|
||||||
*/
|
*/
|
||||||
struct list_head *btrfs_get_workspace(struct workspace_manager *wsm)
|
struct list_head *btrfs_get_workspace(struct workspace_manager *wsm,
|
||||||
|
unsigned int level)
|
||||||
{
|
{
|
||||||
struct list_head *workspace;
|
struct list_head *workspace;
|
||||||
int cpus = num_online_cpus();
|
int cpus = num_online_cpus();
|
||||||
|
@ -899,7 +900,7 @@ again:
|
||||||
* context of btrfs_compress_bio/btrfs_compress_pages
|
* context of btrfs_compress_bio/btrfs_compress_pages
|
||||||
*/
|
*/
|
||||||
nofs_flag = memalloc_nofs_save();
|
nofs_flag = memalloc_nofs_save();
|
||||||
workspace = wsm->ops->alloc_workspace();
|
workspace = wsm->ops->alloc_workspace(level);
|
||||||
memalloc_nofs_restore(nofs_flag);
|
memalloc_nofs_restore(nofs_flag);
|
||||||
|
|
||||||
if (IS_ERR(workspace)) {
|
if (IS_ERR(workspace)) {
|
||||||
|
@ -930,9 +931,9 @@ again:
|
||||||
return workspace;
|
return workspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct list_head *get_workspace(int type)
|
static struct list_head *get_workspace(int type, int level)
|
||||||
{
|
{
|
||||||
return btrfs_compress_op[type]->get_workspace();
|
return btrfs_compress_op[type]->get_workspace(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1003,12 +1004,13 @@ int btrfs_compress_pages(unsigned int type_level, struct address_space *mapping,
|
||||||
unsigned long *total_out)
|
unsigned long *total_out)
|
||||||
{
|
{
|
||||||
int type = btrfs_compress_type(type_level);
|
int type = btrfs_compress_type(type_level);
|
||||||
|
int level = btrfs_compress_level(type_level);
|
||||||
struct list_head *workspace;
|
struct list_head *workspace;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
workspace = get_workspace(type);
|
workspace = get_workspace(type, level);
|
||||||
|
|
||||||
btrfs_compress_op[type]->set_level(workspace, type_level);
|
btrfs_compress_op[type]->set_level(workspace, level);
|
||||||
ret = btrfs_compress_op[type]->compress_pages(workspace, mapping,
|
ret = btrfs_compress_op[type]->compress_pages(workspace, mapping,
|
||||||
start, pages,
|
start, pages,
|
||||||
out_pages,
|
out_pages,
|
||||||
|
@ -1037,7 +1039,7 @@ static int btrfs_decompress_bio(struct compressed_bio *cb)
|
||||||
int ret;
|
int ret;
|
||||||
int type = cb->compress_type;
|
int type = cb->compress_type;
|
||||||
|
|
||||||
workspace = get_workspace(type);
|
workspace = get_workspace(type, 0);
|
||||||
ret = btrfs_compress_op[type]->decompress_bio(workspace, cb);
|
ret = btrfs_compress_op[type]->decompress_bio(workspace, cb);
|
||||||
put_workspace(type, workspace);
|
put_workspace(type, workspace);
|
||||||
|
|
||||||
|
@ -1055,13 +1057,12 @@ int btrfs_decompress(int type, unsigned char *data_in, struct page *dest_page,
|
||||||
struct list_head *workspace;
|
struct list_head *workspace;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
workspace = get_workspace(type);
|
workspace = get_workspace(type, 0);
|
||||||
|
|
||||||
ret = btrfs_compress_op[type]->decompress(workspace, data_in,
|
ret = btrfs_compress_op[type]->decompress(workspace, data_in,
|
||||||
dest_page, start_byte,
|
dest_page, start_byte,
|
||||||
srclen, destlen);
|
srclen, destlen);
|
||||||
|
|
||||||
put_workspace(type, workspace);
|
put_workspace(type, workspace);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1489,7 +1490,7 @@ static void heuristic_collect_sample(struct inode *inode, u64 start, u64 end,
|
||||||
*/
|
*/
|
||||||
int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end)
|
int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end)
|
||||||
{
|
{
|
||||||
struct list_head *ws_list = get_workspace(0);
|
struct list_head *ws_list = get_workspace(0, 0);
|
||||||
struct heuristic_ws *ws;
|
struct heuristic_ws *ws;
|
||||||
u32 i;
|
u32 i;
|
||||||
u8 byte;
|
u8 byte;
|
||||||
|
|
|
@ -121,7 +121,8 @@ struct workspace_manager {
|
||||||
|
|
||||||
void btrfs_init_workspace_manager(struct workspace_manager *wsm,
|
void btrfs_init_workspace_manager(struct workspace_manager *wsm,
|
||||||
const struct btrfs_compress_op *ops);
|
const struct btrfs_compress_op *ops);
|
||||||
struct list_head *btrfs_get_workspace(struct workspace_manager *wsm);
|
struct list_head *btrfs_get_workspace(struct workspace_manager *wsm,
|
||||||
|
unsigned int level);
|
||||||
void btrfs_put_workspace(struct workspace_manager *wsm, struct list_head *ws);
|
void btrfs_put_workspace(struct workspace_manager *wsm, struct list_head *ws);
|
||||||
void btrfs_cleanup_workspace_manager(struct workspace_manager *wsm);
|
void btrfs_cleanup_workspace_manager(struct workspace_manager *wsm);
|
||||||
|
|
||||||
|
@ -130,11 +131,11 @@ struct btrfs_compress_op {
|
||||||
|
|
||||||
void (*cleanup_workspace_manager)(void);
|
void (*cleanup_workspace_manager)(void);
|
||||||
|
|
||||||
struct list_head *(*get_workspace)(void);
|
struct list_head *(*get_workspace)(unsigned int level);
|
||||||
|
|
||||||
void (*put_workspace)(struct list_head *ws);
|
void (*put_workspace)(struct list_head *ws);
|
||||||
|
|
||||||
struct list_head *(*alloc_workspace)(void);
|
struct list_head *(*alloc_workspace)(unsigned int level);
|
||||||
|
|
||||||
void (*free_workspace)(struct list_head *workspace);
|
void (*free_workspace)(struct list_head *workspace);
|
||||||
|
|
||||||
|
|
|
@ -73,9 +73,9 @@ static void lzo_cleanup_workspace_manager(void)
|
||||||
btrfs_cleanup_workspace_manager(&wsm);
|
btrfs_cleanup_workspace_manager(&wsm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct list_head *lzo_get_workspace(void)
|
static struct list_head *lzo_get_workspace(unsigned int level)
|
||||||
{
|
{
|
||||||
return btrfs_get_workspace(&wsm);
|
return btrfs_get_workspace(&wsm, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lzo_put_workspace(struct list_head *ws)
|
static void lzo_put_workspace(struct list_head *ws)
|
||||||
|
@ -93,7 +93,7 @@ static void lzo_free_workspace(struct list_head *ws)
|
||||||
kfree(workspace);
|
kfree(workspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct list_head *lzo_alloc_workspace(void)
|
static struct list_head *lzo_alloc_workspace(unsigned int level)
|
||||||
{
|
{
|
||||||
struct workspace *workspace;
|
struct workspace *workspace;
|
||||||
|
|
||||||
|
|
|
@ -39,9 +39,9 @@ static void zlib_cleanup_workspace_manager(void)
|
||||||
btrfs_cleanup_workspace_manager(&wsm);
|
btrfs_cleanup_workspace_manager(&wsm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct list_head *zlib_get_workspace(void)
|
static struct list_head *zlib_get_workspace(unsigned int level)
|
||||||
{
|
{
|
||||||
return btrfs_get_workspace(&wsm);
|
return btrfs_get_workspace(&wsm, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void zlib_put_workspace(struct list_head *ws)
|
static void zlib_put_workspace(struct list_head *ws)
|
||||||
|
@ -58,7 +58,7 @@ static void zlib_free_workspace(struct list_head *ws)
|
||||||
kfree(workspace);
|
kfree(workspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct list_head *zlib_alloc_workspace(void)
|
static struct list_head *zlib_alloc_workspace(unsigned int level)
|
||||||
{
|
{
|
||||||
struct workspace *workspace;
|
struct workspace *workspace;
|
||||||
int workspacesize;
|
int workspacesize;
|
||||||
|
@ -70,6 +70,7 @@ static struct list_head *zlib_alloc_workspace(void)
|
||||||
workspacesize = max(zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL),
|
workspacesize = max(zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL),
|
||||||
zlib_inflate_workspacesize());
|
zlib_inflate_workspacesize());
|
||||||
workspace->strm.workspace = kvmalloc(workspacesize, GFP_KERNEL);
|
workspace->strm.workspace = kvmalloc(workspacesize, GFP_KERNEL);
|
||||||
|
workspace->level = level;
|
||||||
workspace->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
|
workspace->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
|
||||||
if (!workspace->strm.workspace || !workspace->buf)
|
if (!workspace->strm.workspace || !workspace->buf)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
|
@ -53,9 +53,9 @@ static void zstd_cleanup_workspace_manager(void)
|
||||||
btrfs_cleanup_workspace_manager(&wsm);
|
btrfs_cleanup_workspace_manager(&wsm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct list_head *zstd_get_workspace(void)
|
static struct list_head *zstd_get_workspace(unsigned int level)
|
||||||
{
|
{
|
||||||
return btrfs_get_workspace(&wsm);
|
return btrfs_get_workspace(&wsm, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void zstd_put_workspace(struct list_head *ws)
|
static void zstd_put_workspace(struct list_head *ws)
|
||||||
|
@ -72,7 +72,7 @@ static void zstd_free_workspace(struct list_head *ws)
|
||||||
kfree(workspace);
|
kfree(workspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct list_head *zstd_alloc_workspace(void)
|
static struct list_head *zstd_alloc_workspace(unsigned int level)
|
||||||
{
|
{
|
||||||
ZSTD_parameters params =
|
ZSTD_parameters params =
|
||||||
zstd_get_btrfs_parameters(ZSTD_BTRFS_MAX_INPUT);
|
zstd_get_btrfs_parameters(ZSTD_BTRFS_MAX_INPUT);
|
||||||
|
|
Loading…
Add table
Reference in a new issue