linux-stable/drivers/block/zram/backend_lzo.c
Sergey Senozhatsky b8f03cb703 zram: move immutable comp params away from per-CPU context
Immutable params never change once comp has been allocated and setup, so
we don't need to store multiple copies of them in each per-CPU backend
context.  Move those to per-comp zcomp_params and pass it to backends
callbacks for requests execution.  Basically, this means parameters
sharing between different contexts.

Also introduce two new backends callbacks: setup_params() and
release_params().  First, we need to validate params in a driver-specific
way; second, driver may want to allocate its specific representation of
the params which is needed to execute requests.

Link: https://lkml.kernel.org/r/20240902105656.1383858-20-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>
2024-09-09 16:39:10 -07:00

60 lines
1.3 KiB
C

// SPDX-License-Identifier: GPL-2.0-or-later
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/lzo.h>
#include "backend_lzo.h"
static void lzo_release_params(struct zcomp_params *params)
{
}
static int lzo_setup_params(struct zcomp_params *params)
{
return 0;
}
static int lzo_create(struct zcomp_params *params, struct zcomp_ctx *ctx)
{
ctx->context = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);
if (!ctx->context)
return -ENOMEM;
return 0;
}
static void lzo_destroy(struct zcomp_ctx *ctx)
{
kfree(ctx->context);
}
static int lzo_compress(struct zcomp_params *params, struct zcomp_ctx *ctx,
struct zcomp_req *req)
{
int ret;
ret = lzo1x_1_compress(req->src, req->src_len, req->dst,
&req->dst_len, ctx->context);
return ret == LZO_E_OK ? 0 : ret;
}
static int lzo_decompress(struct zcomp_params *params, struct zcomp_ctx *ctx,
struct zcomp_req *req)
{
int ret;
ret = lzo1x_decompress_safe(req->src, req->src_len,
req->dst, &req->dst_len);
return ret == LZO_E_OK ? 0 : ret;
}
const struct zcomp_ops backend_lzo = {
.compress = lzo_compress,
.decompress = lzo_decompress,
.create_ctx = lzo_create,
.destroy_ctx = lzo_destroy,
.setup_params = lzo_setup_params,
.release_params = lzo_release_params,
.name = "lzo",
};