Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Sergey Senozhatsky and committed by
Andrew Morton
dc75a0d9 a5ade2e9

+28 -6
+6 -4
drivers/block/zram/backend_deflate.c
··· 8 8 #include "backend_deflate.h" 9 9 10 10 /* Use the same value as crypto API */ 11 - #define DEFLATE_DEF_WINBITS 11 11 + #define DEFLATE_DEF_WINBITS (-11) 12 12 #define DEFLATE_DEF_MEMLEVEL MAX_MEM_LEVEL 13 13 14 14 struct deflate_ctx { ··· 24 24 { 25 25 if (params->level == ZCOMP_PARAM_NOT_SET) 26 26 params->level = Z_DEFAULT_COMPRESSION; 27 + if (params->deflate.winbits == ZCOMP_PARAM_NOT_SET) 28 + params->deflate.winbits = DEFLATE_DEF_WINBITS; 27 29 28 30 return 0; 29 31 } ··· 59 57 return -ENOMEM; 60 58 61 59 ctx->context = zctx; 62 - sz = zlib_deflate_workspacesize(-DEFLATE_DEF_WINBITS, MAX_MEM_LEVEL); 60 + sz = zlib_deflate_workspacesize(params->deflate.winbits, MAX_MEM_LEVEL); 63 61 zctx->cctx.workspace = vzalloc(sz); 64 62 if (!zctx->cctx.workspace) 65 63 goto error; 66 64 67 65 ret = zlib_deflateInit2(&zctx->cctx, params->level, Z_DEFLATED, 68 - -DEFLATE_DEF_WINBITS, DEFLATE_DEF_MEMLEVEL, 66 + params->deflate.winbits, DEFLATE_DEF_MEMLEVEL, 69 67 Z_DEFAULT_STRATEGY); 70 68 if (ret != Z_OK) 71 69 goto error; ··· 75 73 if (!zctx->dctx.workspace) 76 74 goto error; 77 75 78 - ret = zlib_inflateInit2(&zctx->dctx, -DEFLATE_DEF_WINBITS); 76 + ret = zlib_inflateInit2(&zctx->dctx, params->deflate.winbits); 79 77 if (ret != Z_OK) 80 78 goto error; 81 79
+7
drivers/block/zram/zcomp.h
··· 7 7 8 8 #define ZCOMP_PARAM_NOT_SET INT_MIN 9 9 10 + struct deflate_params { 11 + s32 winbits; 12 + }; 13 + 10 14 /* 11 15 * Immutable driver (backend) parameters. The driver may attach private 12 16 * data to it (e.g. driver representation of the dictionary, etc.). ··· 21 17 void *dict; 22 18 size_t dict_sz; 23 19 s32 level; 20 + union { 21 + struct deflate_params deflate; 22 + }; 24 23 25 24 void *drv_data; 26 25 };
+15 -2
drivers/block/zram/zram_drv.c
··· 1277 1277 1278 1278 vfree(params->dict); 1279 1279 params->level = ZCOMP_PARAM_NOT_SET; 1280 + params->deflate.winbits = ZCOMP_PARAM_NOT_SET; 1280 1281 params->dict_sz = 0; 1281 1282 params->dict = NULL; 1282 1283 } 1283 1284 1284 1285 static int comp_params_store(struct zram *zram, u32 prio, s32 level, 1285 - const char *dict_path) 1286 + const char *dict_path, 1287 + struct deflate_params *deflate_params) 1286 1288 { 1287 1289 ssize_t sz = 0; 1288 1290 ··· 1302 1300 1303 1301 zram->params[prio].dict_sz = sz; 1304 1302 zram->params[prio].level = level; 1303 + zram->params[prio].deflate.winbits = deflate_params->winbits; 1305 1304 return 0; 1306 1305 } 1307 1306 ··· 1313 1310 { 1314 1311 s32 prio = ZRAM_PRIMARY_COMP, level = ZCOMP_PARAM_NOT_SET; 1315 1312 char *args, *param, *val, *algo = NULL, *dict_path = NULL; 1313 + struct deflate_params deflate_params; 1316 1314 struct zram *zram = dev_to_zram(dev); 1317 1315 int ret; 1316 + 1317 + deflate_params.winbits = ZCOMP_PARAM_NOT_SET; 1318 1318 1319 1319 args = skip_spaces(buf); 1320 1320 while (*args) { ··· 1349 1343 dict_path = val; 1350 1344 continue; 1351 1345 } 1346 + 1347 + if (!strcmp(param, "deflate.winbits")) { 1348 + ret = kstrtoint(val, 10, &deflate_params.winbits); 1349 + if (ret) 1350 + return ret; 1351 + continue; 1352 + } 1352 1353 } 1353 1354 1354 1355 /* Lookup priority by algorithm name */ ··· 1377 1364 if (prio < ZRAM_PRIMARY_COMP || prio >= ZRAM_MAX_COMPS) 1378 1365 return -EINVAL; 1379 1366 1380 - ret = comp_params_store(zram, prio, level, dict_path); 1367 + ret = comp_params_store(zram, prio, level, dict_path, &deflate_params); 1381 1368 return ret ? ret : len; 1382 1369 } 1383 1370