mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 20:54:03 +02:00
zram: support deflate-specific params
Introduce support of algorithm specific parameters in algorithm_params device attribute. The expected format is algorithm.param=value. For starters, add support for deflate.winbits parameter. Link: https://lkml.kernel.org/r/20250514024825.1745489-3-senozhatsky@chromium.org Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com> Cc: Minchan Kim <minchan@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
a5ade2e9fa
commit
dc75a0d93b
|
|
@ -8,7 +8,7 @@
|
||||||
#include "backend_deflate.h"
|
#include "backend_deflate.h"
|
||||||
|
|
||||||
/* Use the same value as crypto API */
|
/* Use the same value as crypto API */
|
||||||
#define DEFLATE_DEF_WINBITS 11
|
#define DEFLATE_DEF_WINBITS (-11)
|
||||||
#define DEFLATE_DEF_MEMLEVEL MAX_MEM_LEVEL
|
#define DEFLATE_DEF_MEMLEVEL MAX_MEM_LEVEL
|
||||||
|
|
||||||
struct deflate_ctx {
|
struct deflate_ctx {
|
||||||
|
|
@ -24,6 +24,8 @@ static int deflate_setup_params(struct zcomp_params *params)
|
||||||
{
|
{
|
||||||
if (params->level == ZCOMP_PARAM_NOT_SET)
|
if (params->level == ZCOMP_PARAM_NOT_SET)
|
||||||
params->level = Z_DEFAULT_COMPRESSION;
|
params->level = Z_DEFAULT_COMPRESSION;
|
||||||
|
if (params->deflate.winbits == ZCOMP_PARAM_NOT_SET)
|
||||||
|
params->deflate.winbits = DEFLATE_DEF_WINBITS;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -57,13 +59,13 @@ static int deflate_create(struct zcomp_params *params, struct zcomp_ctx *ctx)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
ctx->context = zctx;
|
ctx->context = zctx;
|
||||||
sz = zlib_deflate_workspacesize(-DEFLATE_DEF_WINBITS, MAX_MEM_LEVEL);
|
sz = zlib_deflate_workspacesize(params->deflate.winbits, MAX_MEM_LEVEL);
|
||||||
zctx->cctx.workspace = vzalloc(sz);
|
zctx->cctx.workspace = vzalloc(sz);
|
||||||
if (!zctx->cctx.workspace)
|
if (!zctx->cctx.workspace)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
ret = zlib_deflateInit2(&zctx->cctx, params->level, Z_DEFLATED,
|
ret = zlib_deflateInit2(&zctx->cctx, params->level, Z_DEFLATED,
|
||||||
-DEFLATE_DEF_WINBITS, DEFLATE_DEF_MEMLEVEL,
|
params->deflate.winbits, DEFLATE_DEF_MEMLEVEL,
|
||||||
Z_DEFAULT_STRATEGY);
|
Z_DEFAULT_STRATEGY);
|
||||||
if (ret != Z_OK)
|
if (ret != Z_OK)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
@ -73,7 +75,7 @@ static int deflate_create(struct zcomp_params *params, struct zcomp_ctx *ctx)
|
||||||
if (!zctx->dctx.workspace)
|
if (!zctx->dctx.workspace)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
ret = zlib_inflateInit2(&zctx->dctx, -DEFLATE_DEF_WINBITS);
|
ret = zlib_inflateInit2(&zctx->dctx, params->deflate.winbits);
|
||||||
if (ret != Z_OK)
|
if (ret != Z_OK)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,10 @@
|
||||||
|
|
||||||
#define ZCOMP_PARAM_NOT_SET INT_MIN
|
#define ZCOMP_PARAM_NOT_SET INT_MIN
|
||||||
|
|
||||||
|
struct deflate_params {
|
||||||
|
s32 winbits;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Immutable driver (backend) parameters. The driver may attach private
|
* Immutable driver (backend) parameters. The driver may attach private
|
||||||
* data to it (e.g. driver representation of the dictionary, etc.).
|
* data to it (e.g. driver representation of the dictionary, etc.).
|
||||||
|
|
@ -17,6 +21,9 @@ struct zcomp_params {
|
||||||
void *dict;
|
void *dict;
|
||||||
size_t dict_sz;
|
size_t dict_sz;
|
||||||
s32 level;
|
s32 level;
|
||||||
|
union {
|
||||||
|
struct deflate_params deflate;
|
||||||
|
};
|
||||||
|
|
||||||
void *drv_data;
|
void *drv_data;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1277,12 +1277,14 @@ static void comp_params_reset(struct zram *zram, u32 prio)
|
||||||
|
|
||||||
vfree(params->dict);
|
vfree(params->dict);
|
||||||
params->level = ZCOMP_PARAM_NOT_SET;
|
params->level = ZCOMP_PARAM_NOT_SET;
|
||||||
|
params->deflate.winbits = ZCOMP_PARAM_NOT_SET;
|
||||||
params->dict_sz = 0;
|
params->dict_sz = 0;
|
||||||
params->dict = NULL;
|
params->dict = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int comp_params_store(struct zram *zram, u32 prio, s32 level,
|
static int comp_params_store(struct zram *zram, u32 prio, s32 level,
|
||||||
const char *dict_path)
|
const char *dict_path,
|
||||||
|
struct deflate_params *deflate_params)
|
||||||
{
|
{
|
||||||
ssize_t sz = 0;
|
ssize_t sz = 0;
|
||||||
|
|
||||||
|
|
@ -1300,6 +1302,7 @@ static int comp_params_store(struct zram *zram, u32 prio, s32 level,
|
||||||
|
|
||||||
zram->params[prio].dict_sz = sz;
|
zram->params[prio].dict_sz = sz;
|
||||||
zram->params[prio].level = level;
|
zram->params[prio].level = level;
|
||||||
|
zram->params[prio].deflate.winbits = deflate_params->winbits;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1310,9 +1313,12 @@ static ssize_t algorithm_params_store(struct device *dev,
|
||||||
{
|
{
|
||||||
s32 prio = ZRAM_PRIMARY_COMP, level = ZCOMP_PARAM_NOT_SET;
|
s32 prio = ZRAM_PRIMARY_COMP, level = ZCOMP_PARAM_NOT_SET;
|
||||||
char *args, *param, *val, *algo = NULL, *dict_path = NULL;
|
char *args, *param, *val, *algo = NULL, *dict_path = NULL;
|
||||||
|
struct deflate_params deflate_params;
|
||||||
struct zram *zram = dev_to_zram(dev);
|
struct zram *zram = dev_to_zram(dev);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
deflate_params.winbits = ZCOMP_PARAM_NOT_SET;
|
||||||
|
|
||||||
args = skip_spaces(buf);
|
args = skip_spaces(buf);
|
||||||
while (*args) {
|
while (*args) {
|
||||||
args = next_arg(args, ¶m, &val);
|
args = next_arg(args, ¶m, &val);
|
||||||
|
|
@ -1343,6 +1349,13 @@ static ssize_t algorithm_params_store(struct device *dev,
|
||||||
dict_path = val;
|
dict_path = val;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!strcmp(param, "deflate.winbits")) {
|
||||||
|
ret = kstrtoint(val, 10, &deflate_params.winbits);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Lookup priority by algorithm name */
|
/* Lookup priority by algorithm name */
|
||||||
|
|
@ -1364,7 +1377,7 @@ static ssize_t algorithm_params_store(struct device *dev,
|
||||||
if (prio < ZRAM_PRIMARY_COMP || prio >= ZRAM_MAX_COMPS)
|
if (prio < ZRAM_PRIMARY_COMP || prio >= ZRAM_MAX_COMPS)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
ret = comp_params_store(zram, prio, level, dict_path);
|
ret = comp_params_store(zram, prio, level, dict_path, &deflate_params);
|
||||||
return ret ? ret : len;
|
return ret ? ret : len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user