Commit dea77d7a authored by Sergey Senozhatsky's avatar Sergey Senozhatsky Committed by Andrew Morton

zram: add support for dict comp config

Handle dict=path algorithm param so that we can read a pre-trained
compression algorithm dictionary which we then pass to the backend
configuration.

Link: https://lkml.kernel.org/r/20240902105656.1383858-17-senozhatsky@chromium.orgSigned-off-by: default avatarSergey Senozhatsky <senozhatsky@chromium.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nick Terrell <terrelln@fb.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 4eac9321
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <linux/debugfs.h> #include <linux/debugfs.h>
#include <linux/cpuhotplug.h> #include <linux/cpuhotplug.h>
#include <linux/part_stat.h> #include <linux/part_stat.h>
#include <linux/kernel_read_file.h>
#include "zram_drv.h" #include "zram_drv.h"
...@@ -998,8 +999,34 @@ static int __comp_algorithm_store(struct zram *zram, u32 prio, const char *buf) ...@@ -998,8 +999,34 @@ static int __comp_algorithm_store(struct zram *zram, u32 prio, const char *buf)
return 0; return 0;
} }
static int comp_params_store(struct zram *zram, u32 prio, s32 level) static void comp_params_reset(struct zram *zram, u32 prio)
{ {
struct zcomp_params *params = &zram->params[prio];
vfree(params->dict);
params->level = ZCOMP_PARAM_NO_LEVEL;
params->dict_sz = 0;
params->dict = NULL;
}
static int comp_params_store(struct zram *zram, u32 prio, s32 level,
const char *dict_path)
{
ssize_t sz = 0;
comp_params_reset(zram, prio);
if (dict_path) {
sz = kernel_read_file_from_path(dict_path, 0,
&zram->params[prio].dict,
INT_MAX,
NULL,
READING_POLICY);
if (sz < 0)
return -EINVAL;
}
zram->params[prio].dict_sz = sz;
zram->params[prio].level = level; zram->params[prio].level = level;
return 0; return 0;
} }
...@@ -1010,7 +1037,7 @@ static ssize_t algorithm_params_store(struct device *dev, ...@@ -1010,7 +1037,7 @@ static ssize_t algorithm_params_store(struct device *dev,
size_t len) size_t len)
{ {
s32 prio = ZRAM_PRIMARY_COMP, level = ZCOMP_PARAM_NO_LEVEL; s32 prio = ZRAM_PRIMARY_COMP, level = ZCOMP_PARAM_NO_LEVEL;
char *args, *param, *val, *algo = NULL; char *args, *param, *val, *algo = NULL, *dict_path = NULL;
struct zram *zram = dev_to_zram(dev); struct zram *zram = dev_to_zram(dev);
int ret; int ret;
...@@ -1039,6 +1066,11 @@ static ssize_t algorithm_params_store(struct device *dev, ...@@ -1039,6 +1066,11 @@ static ssize_t algorithm_params_store(struct device *dev,
algo = val; algo = val;
continue; continue;
} }
if (!strcmp(param, "dict")) {
dict_path = val;
continue;
}
} }
/* Lookup priority by algorithm name */ /* Lookup priority by algorithm name */
...@@ -1060,7 +1092,7 @@ static ssize_t algorithm_params_store(struct device *dev, ...@@ -1060,7 +1092,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); ret = comp_params_store(zram, prio, level, dict_path);
return ret ? ret : len; return ret ? ret : len;
} }
...@@ -2050,12 +2082,7 @@ static void zram_comp_params_reset(struct zram *zram) ...@@ -2050,12 +2082,7 @@ static void zram_comp_params_reset(struct zram *zram)
u32 prio; u32 prio;
for (prio = ZRAM_PRIMARY_COMP; prio < ZRAM_MAX_COMPS; prio++) { for (prio = ZRAM_PRIMARY_COMP; prio < ZRAM_MAX_COMPS; prio++) {
struct zcomp_params *params = &zram->params[prio]; comp_params_reset(zram, prio);
vfree(params->dict);
params->level = ZCOMP_PARAM_NO_LEVEL;
params->dict_sz = 0;
params->dict = NULL;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment