@@ -354,8 +354,7 @@ static int attempt_compress(struct bch_fs *c,
354354 */
355355 unsigned level = min ((compression .level * 3 ) / 2 , zstd_max_clevel ());
356356 ZSTD_parameters params = zstd_get_params (level , c -> opts .encoded_extent_max );
357- ZSTD_CCtx * ctx = zstd_init_cctx (workspace ,
358- zstd_cctx_workspace_bound (& params .cParams ));
357+ ZSTD_CCtx * ctx = zstd_init_cctx (workspace , c -> zstd_workspace_size );
359358
360359 /*
361360 * ZSTD requires that when we decompress we pass in the exact
@@ -371,7 +370,7 @@ static int attempt_compress(struct bch_fs *c,
371370 size_t len = zstd_compress_cctx (ctx ,
372371 dst + 4 , dst_len - 4 - 7 ,
373372 src , src_len ,
374- & c -> zstd_params );
373+ & params );
375374 if (zstd_is_error (len ))
376375 return 0 ;
377376
@@ -572,6 +571,13 @@ static int __bch2_fs_compress_init(struct bch_fs *c, u64 features)
572571 size_t decompress_workspace_size = 0 ;
573572 ZSTD_parameters params = zstd_get_params (zstd_max_clevel (),
574573 c -> opts .encoded_extent_max );
574+
575+ /*
576+ * ZSTD is lying: if we allocate the size of the workspace it says it
577+ * requires, it returns memory allocation errors
578+ */
579+ c -> zstd_workspace_size = zstd_cctx_workspace_bound (& params .cParams );
580+
575581 struct {
576582 unsigned feature ;
577583 enum bch_compression_type type ;
@@ -585,13 +591,11 @@ static int __bch2_fs_compress_init(struct bch_fs *c, u64 features)
585591 zlib_deflate_workspacesize (MAX_WBITS , DEF_MEM_LEVEL ),
586592 zlib_inflate_workspacesize (), },
587593 { BCH_FEATURE_zstd , BCH_COMPRESSION_TYPE_zstd ,
588- zstd_cctx_workspace_bound ( & params . cParams ) ,
594+ c -> zstd_workspace_size ,
589595 zstd_dctx_workspace_bound () },
590596 }, * i ;
591597 bool have_compressed = false;
592598
593- c -> zstd_params = params ;
594-
595599 for (i = compression_types ;
596600 i < compression_types + ARRAY_SIZE (compression_types );
597601 i ++ )
0 commit comments