The patch titled Subject: zram: add support for dict comp config has been added to the -mm mm-unstable branch. Its filename is zram-add-support-for-dict-comp-config.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/zram-add-support-for-dict-comp-config.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx> Subject: zram: add support for dict comp config Date: Fri, 12 Jul 2024 14:18:27 +0900 Handle dict=path 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/20240712051850.484318-17-senozhatsky@xxxxxxxxxxxx Signed-off-by: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx> Cc: Minchan Kim <minchan@xxxxxxxxxx> Cc: Nhat Pham <nphamcs@xxxxxxxxx> Cc: Nick Terrell <terrelln@xxxxxx> Cc: Nitin Gupta <ngupta@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- drivers/block/zram/zram_drv.c | 60 ++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 14 deletions(-) --- a/drivers/block/zram/zram_drv.c~zram-add-support-for-dict-comp-config +++ a/drivers/block/zram/zram_drv.c @@ -33,6 +33,7 @@ #include <linux/debugfs.h> #include <linux/cpuhotplug.h> #include <linux/part_stat.h> +#include <linux/kernel_read_file.h> #include "zram_drv.h" @@ -998,8 +999,34 @@ static int __comp_algorithm_store(struct 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; } @@ -1020,7 +1047,7 @@ static ssize_t comp_algorithm_store(stru { 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; @@ -1048,12 +1075,17 @@ static ssize_t comp_algorithm_store(stru 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; @@ -1087,7 +1119,7 @@ static ssize_t recomp_algorithm_store(st 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; @@ -1116,6 +1148,11 @@ static ssize_t recomp_algorithm_store(st return ret; continue; } + + if (!strcmp(param, "dict")) { + dict_path = val; + continue; + } } if (!alg) @@ -1124,7 +1161,7 @@ static ssize_t recomp_algorithm_store(st 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; @@ -2029,17 +2066,12 @@ static void zram_slot_free_notify(struct 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); } } @@ -2057,7 +2089,7 @@ static void zram_destroy_comps(struct zr zram->num_active_comps--; } - zram_reset_comp_params(zram); + zram_comp_params_reset(zram); } static void zram_reset_device(struct zram *zram) @@ -2321,7 +2353,7 @@ static int zram_add(void) 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); _ Patches currently in -mm which might be from senozhatsky@xxxxxxxxxxxx are lib-zstd-export-api-needed-for-dictionary-support.patch lib-lz4hc-export-lz4_resetstreamhc-symbol.patch lib-zstd-fix-null-deref-in-zstd_createcdict_advanced2.patch zram-introduce-custom-comp-backends-api.patch zram-add-lzo-and-lzorle-compression-backends-support.patch zram-add-lz4-compression-backend-support.patch zram-add-lz4hc-compression-backend-support.patch zram-add-zstd-compression-backend-support.patch zram-pass-estimated-src-size-hint-to-zstd.patch zram-add-zlib-compression-backend-support.patch zram-add-842-compression-backend-support.patch zram-check-that-backends-array-has-at-least-one-backend.patch zram-introduce-zcomp_params-structure.patch zram-recalculate-zstd-compression-params-once.patch zram-extend-comp_algorithm-attr-write-handling.patch zram-add-support-for-dict-comp-config.patch zram-introduce-zcomp_req-structure.patch zram-introduce-zcomp_ctx-structure.patch zram-move-immutable-comp-params-away-from-per-cpu-context.patch zram-add-dictionary-support-to-lz4.patch zram-add-dictionary-support-to-lz4hc.patch zram-add-dictionary-support-to-zstd-backend.patch documentation-zram-add-documentation-for-algorithm-parameters.patch