#include <linux/debugfs.h>
#include <linux/cpuhotplug.h>
#include <linux/part_stat.h>
+#include <linux/kernel_read_file.h>
#include "zram_drv.h"
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;
return 0;
}
{
struct zram *zram = dev_to_zram(dev);
char *args, *param, *val;
- char *alg = NULL;
+ char *alg = NULL, *dict_path = NULL;
s32 level = ZCOMP_PARAM_NO_LEVEL;
int ret;
return ret;
continue;
}
+
+ if (!strcmp(param, "dict")) {
+ dict_path = val;
+ continue;
+ }
}
if (!alg)
return -EINVAL;
- ret = comp_params_store(zram, ZRAM_PRIMARY_COMP, level);
+ ret = comp_params_store(zram, ZRAM_PRIMARY_COMP, level, dict_path);
if (!ret)
ret = __comp_algorithm_store(zram, ZRAM_PRIMARY_COMP, alg);
return ret ? ret : len;
struct zram *zram = dev_to_zram(dev);
int prio = ZRAM_SECONDARY_COMP;
char *args, *param, *val;
- char *alg = NULL;
+ char *alg = NULL, *dict_path = NULL;
s32 level = ZCOMP_PARAM_NO_LEVEL;
int ret;
return ret;
continue;
}
+
+ if (!strcmp(param, "dict")) {
+ dict_path = val;
+ continue;
+ }
}
if (!alg)
if (prio < ZRAM_SECONDARY_COMP || prio >= ZRAM_MAX_COMPS)
return -EINVAL;
- ret = comp_params_store(zram, prio, level);
+ ret = comp_params_store(zram, prio, level, dict_path);
if (!ret)
ret = __comp_algorithm_store(zram, prio, alg);
return ret ? ret : len;
zram_slot_unlock(zram, index);
}
-static void zram_reset_comp_params(struct zram *zram)
+static void zram_comp_params_reset(struct zram *zram)
{
u32 prio;
for (prio = 0; prio < ZRAM_MAX_COMPS; prio++) {
- struct zcomp_params *params = &zram->params[prio];
-
- vfree(params->dict);
- params->level = ZCOMP_PARAM_NO_LEVEL;
- params->dict_sz = 0;
- params->dict = NULL;
+ comp_params_reset(zram, prio);
}
}
zram->num_active_comps--;
}
- zram_reset_comp_params(zram);
+ zram_comp_params_reset(zram);
}
static void zram_reset_device(struct zram *zram)
if (ret)
goto out_cleanup_disk;
- zram_reset_comp_params(zram);
+ zram_comp_params_reset(zram);
comp_algorithm_set(zram, ZRAM_PRIMARY_COMP, default_compressor);
zram_debugfs_register(zram);