Commit bbc3a460 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Fix zstd compress workspace size

zstd apparently lies about the size of the compression workspace it
requires; if we double it compression succeeds.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 3f3ae125
...@@ -931,7 +931,7 @@ struct bch_fs { ...@@ -931,7 +931,7 @@ struct bch_fs {
mempool_t compression_bounce[2]; mempool_t compression_bounce[2];
mempool_t compress_workspace[BCH_COMPRESSION_TYPE_NR]; mempool_t compress_workspace[BCH_COMPRESSION_TYPE_NR];
mempool_t decompress_workspace; mempool_t decompress_workspace;
ZSTD_parameters zstd_params; size_t zstd_workspace_size;
struct crypto_shash *sha256; struct crypto_shash *sha256;
struct crypto_sync_skcipher *chacha20; struct crypto_sync_skcipher *chacha20;
......
...@@ -354,8 +354,7 @@ static int attempt_compress(struct bch_fs *c, ...@@ -354,8 +354,7 @@ static int attempt_compress(struct bch_fs *c,
*/ */
unsigned level = min((compression.level * 3) / 2, zstd_max_clevel()); unsigned level = min((compression.level * 3) / 2, zstd_max_clevel());
ZSTD_parameters params = zstd_get_params(level, c->opts.encoded_extent_max); ZSTD_parameters params = zstd_get_params(level, c->opts.encoded_extent_max);
ZSTD_CCtx *ctx = zstd_init_cctx(workspace, ZSTD_CCtx *ctx = zstd_init_cctx(workspace, c->zstd_workspace_size);
zstd_cctx_workspace_bound(&params.cParams));
/* /*
* ZSTD requires that when we decompress we pass in the exact * ZSTD requires that when we decompress we pass in the exact
...@@ -371,7 +370,7 @@ static int attempt_compress(struct bch_fs *c, ...@@ -371,7 +370,7 @@ static int attempt_compress(struct bch_fs *c,
size_t len = zstd_compress_cctx(ctx, size_t len = zstd_compress_cctx(ctx,
dst + 4, dst_len - 4 - 7, dst + 4, dst_len - 4 - 7,
src, src_len, src, src_len,
&c->zstd_params); &params);
if (zstd_is_error(len)) if (zstd_is_error(len))
return 0; return 0;
...@@ -572,6 +571,13 @@ static int __bch2_fs_compress_init(struct bch_fs *c, u64 features) ...@@ -572,6 +571,13 @@ static int __bch2_fs_compress_init(struct bch_fs *c, u64 features)
size_t decompress_workspace_size = 0; size_t decompress_workspace_size = 0;
ZSTD_parameters params = zstd_get_params(zstd_max_clevel(), ZSTD_parameters params = zstd_get_params(zstd_max_clevel(),
c->opts.encoded_extent_max); c->opts.encoded_extent_max);
/*
* ZSTD is lying: if we allocate the size of the workspace it says it
* requires, it returns memory allocation errors
*/
c->zstd_workspace_size = zstd_cctx_workspace_bound(&params.cParams);
struct { struct {
unsigned feature; unsigned feature;
enum bch_compression_type type; enum bch_compression_type type;
...@@ -585,13 +591,11 @@ static int __bch2_fs_compress_init(struct bch_fs *c, u64 features) ...@@ -585,13 +591,11 @@ static int __bch2_fs_compress_init(struct bch_fs *c, u64 features)
zlib_deflate_workspacesize(MAX_WBITS, DEF_MEM_LEVEL), zlib_deflate_workspacesize(MAX_WBITS, DEF_MEM_LEVEL),
zlib_inflate_workspacesize(), }, zlib_inflate_workspacesize(), },
{ BCH_FEATURE_zstd, BCH_COMPRESSION_TYPE_zstd, { BCH_FEATURE_zstd, BCH_COMPRESSION_TYPE_zstd,
zstd_cctx_workspace_bound(&params.cParams), c->zstd_workspace_size,
zstd_dctx_workspace_bound() }, zstd_dctx_workspace_bound() },
}, *i; }, *i;
bool have_compressed = false; bool have_compressed = false;
c->zstd_params = params;
for (i = compression_types; for (i = compression_types;
i < compression_types + ARRAY_SIZE(compression_types); i < compression_types + ARRAY_SIZE(compression_types);
i++) i++)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment