]> www.infradead.org Git - users/willy/xarray.git/commitdiff
zram: recalculate zstd compression params once
authorSergey Senozhatsky <senozhatsky@chromium.org>
Mon, 2 Sep 2024 10:56:02 +0000 (19:56 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 9 Sep 2024 23:39:09 +0000 (16:39 -0700)
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/20240902105656.1383858-15-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>
drivers/block/zram/backend_zstd.c

index c356c5e6e503e99443fd2425ad8bdfa5817b6384..7c6798f0c912b5b01d65499688567479330244ac 100644 (file)
@@ -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;