Skip to content

Commit dbf2763

Browse files
sergey-senozhatskyakpm00
authored andcommitted
zram: pass estimated src size hint to zstd
zram works with PAGE_SIZE buffers, so we always know exact size of the source buffer and hence can pass estimated_src_size to zstd_get_params(). This hint on x86_64, for example, reduces the size of the work memory buffer from 1303520 bytes down to 90080 bytes. Given that compression streams are per-CPU that's quite some memory saving. Link: https://lkml.kernel.org/r/20240902105656.1383858-10-senozhatsky@chromium.org Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> Cc: Minchan Kim <minchan@kernel.org> Cc: Nick Terrell <terrelln@fb.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 73e7d81 commit dbf2763

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/block/zram/backend_zstd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static void *zstd_create(void)
3535
return NULL;
3636

3737
ctx->level = zstd_default_clevel();
38-
params = zstd_get_params(ctx->level, 0);
38+
params = zstd_get_params(ctx->level, PAGE_SIZE);
3939
sz = zstd_cctx_workspace_bound(&params.cParams);
4040
ctx->cctx_mem = vzalloc(sz);
4141
if (!ctx->cctx_mem)
@@ -65,7 +65,7 @@ static int zstd_compress(void *ctx, const unsigned char *src, size_t src_len,
6565
unsigned char *dst, size_t *dst_len)
6666
{
6767
struct zstd_ctx *zctx = ctx;
68-
const zstd_parameters params = zstd_get_params(zctx->level, 0);
68+
const zstd_parameters params = zstd_get_params(zctx->level, PAGE_SIZE);
6969
size_t ret;
7070

7171
ret = zstd_compress_cctx(zctx->cctx, dst, *dst_len,

0 commit comments

Comments
 (0)