aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Senozhatsky <[email protected]>2024-09-02 19:56:02 +0900
committerAndrew Morton <[email protected]>2024-09-09 16:39:09 -0700
commiteb826a01909a2d39660ed5a486ebc43e831254bc (patch)
treec5e4519331b70a243cb891410aacc7509e252901
parentf2bac7ad187d77e2a053d3cd04b158a06b683d26 (diff)
zram: recalculate zstd compression params once
zstd compression params depends on level, but are constant for a given instance of zstd compression backend. Calculate once (during ctx creation). Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Sergey Senozhatsky <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Nick Terrell <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
-rw-r--r--drivers/block/zram/backend_zstd.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/drivers/block/zram/backend_zstd.c b/drivers/block/zram/backend_zstd.c
index c356c5e6e503..7c6798f0c912 100644
--- a/drivers/block/zram/backend_zstd.c
+++ b/drivers/block/zram/backend_zstd.c
@@ -10,6 +10,7 @@
struct zstd_ctx {
zstd_cctx *cctx;
zstd_dctx *dctx;
+ zstd_parameters cprm;
void *cctx_mem;
void *dctx_mem;
s32 level;
@@ -40,6 +41,7 @@ static void *zstd_create(struct zcomp_params *params)
ctx->level = zstd_default_clevel();
prm = zstd_get_params(ctx->level, PAGE_SIZE);
+ ctx->cprm = zstd_get_params(ctx->level, PAGE_SIZE);
sz = zstd_cctx_workspace_bound(&prm.cParams);
ctx->cctx_mem = vzalloc(sz);
if (!ctx->cctx_mem)
@@ -69,11 +71,10 @@ static int zstd_compress(void *ctx, const unsigned char *src, size_t src_len,
unsigned char *dst, size_t *dst_len)
{
struct zstd_ctx *zctx = ctx;
- const zstd_parameters prm = zstd_get_params(zctx->level, PAGE_SIZE);
size_t ret;
ret = zstd_compress_cctx(zctx->cctx, dst, *dst_len,
- src, src_len, &prm);
+ src, src_len, &zctx->cprm);
if (zstd_is_error(ret))
return -EINVAL;
*dst_len = ret;