Skip to content

Commit 93a65e6

Browse files
zswap: break the strict dependency from lz4
From the beginning, the zswap block device has always required CRYPTO_LZ4 to be enabled, since lz4 is hardcoded as the default compression algorithm. As a consequence, when a different compression algorithm is hardcoded and the respective CRYPTO_<algo> is not enabled, zswap would not be used therefore causing an issue when swap is needed. This patch removes the hardcoded lz4 dependency and allows the user to select the default compression algorithm for zswap at build time. The previous behaviour is kept, as the default compression algorithm is still lz4. This patch was inspired by [1]. [1]: torvalds/linux@3d711a3 Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
1 parent 9cb7082 commit 93a65e6

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

mm/Kconfig

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ config MEM_SOFT_DIRTY
571571
config ZSWAP
572572
bool "Compressed cache for swap pages (EXPERIMENTAL)"
573573
depends on FRONTSWAP && CRYPTO=y
574-
select CRYPTO_LZ4
574+
depends on CRYPTO_LZ4 || CRYPTO_ZSTD || CRYPTO_LZO
575575
select ZPOOL
576576
select BTREE
577577
default n
@@ -589,6 +589,31 @@ config ZSWAP
589589
they have not be fully explored on the large set of potential
590590
configurations and workloads that exist.
591591

592+
choice
593+
prompt "Default zswap compressor"
594+
default ZSWAP_DEF_COMP_LZ4
595+
depends on ZSWAP
596+
597+
config ZSWAP_DEF_COMP_LZ4
598+
bool "lz4"
599+
depends on CRYPTO_LZ4
600+
601+
config ZSWAP_DEF_COMP_ZSTD
602+
bool "zstd"
603+
depends on CRYPTO_ZSTD
604+
605+
config ZSWAP_DEF_COMP_LZO
606+
bool "lzo"
607+
depends on CRYPTO_LZO
608+
609+
endchoice
610+
611+
config ZSWAP_DEF_COMP
612+
string
613+
default "lzo" if ZSWAP_DEF_COMP_LZO
614+
default "zstd" if ZSWAP_DEF_COMP_ZSTD
615+
default "lz4" if ZSWAP_DEF_COMP_LZ4
616+
592617
config ZPOOL
593618
tristate "Common API for compressed memory storage"
594619
default n

mm/zswap.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ static const struct kernel_param_ops zswap_enabled_param_ops = {
8585
module_param_cb(enabled, &zswap_enabled_param_ops, &zswap_enabled, 0644);
8686

8787
/* Crypto compressor to use */
88-
#define ZSWAP_COMPRESSOR_DEFAULT "lz4"
89-
static char *zswap_compressor = ZSWAP_COMPRESSOR_DEFAULT;
88+
static char *zswap_compressor = CONFIG_ZSWAP_DEF_COMP;
9089
static int zswap_compressor_param_set(const char *,
9190
const struct kernel_param *);
9291
static const struct kernel_param_ops zswap_compressor_param_ops = {
@@ -513,11 +512,11 @@ static __init struct zswap_pool *__zswap_pool_create_fallback(void)
513512
bool has_comp, has_zpool;
514513

515514
has_comp = crypto_has_comp(zswap_compressor, 0, 0);
516-
if (!has_comp && strcmp(zswap_compressor, ZSWAP_COMPRESSOR_DEFAULT)) {
515+
if (!has_comp && strcmp(zswap_compressor, CONFIG_ZSWAP_DEF_COMP)) {
517516
pr_err("compressor %s not available, using default %s\n",
518-
zswap_compressor, ZSWAP_COMPRESSOR_DEFAULT);
517+
zswap_compressor, CONFIG_ZSWAP_DEF_COMP);
519518
param_free_charp(&zswap_compressor);
520-
zswap_compressor = ZSWAP_COMPRESSOR_DEFAULT;
519+
zswap_compressor = CONFIG_ZSWAP_DEF_COMP;
521520
has_comp = crypto_has_comp(zswap_compressor, 0, 0);
522521
}
523522
if (!has_comp) {

0 commit comments

Comments
 (0)