Skip to contentSkip to conversation

zram: break the strict dependency from lzo

PATCH Superseded Rui Salvaterra 3 participants 6 messages Oct 28, 2020 – Nov 14, 2020

Subsystems (2)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 zram: break the strict dependency from lzo

There's nothing special about zram and lzo. It works just fine without it, so as long as at least one of the other supported compression algorithms is selected.

---
v4: incorporate Sergey's feedback and fix a small typo.
v3: fix the default selection when lzo isn't present. Rebase against 5.10-rc1.
v2: fix the dependency on CRYPTO.

 drivers/block/zram/Kconfig    |  6 +++++-
 drivers/block/zram/zcomp.c    | 17 +++++++++++++++++
 drivers/block/zram/zcomp.h    |  1 +
 drivers/block/zram/zram_drv.c |  5 +++--
 4 files changed, 26 insertions(+), 3 deletions(-)
drivers/block/zram/Kconfig +5 -1
index fe7a4b7d30cf..141ce0ebad06 100644
@@ -2,7 +2,6 @@
 config ZRAM
 	tristate "Compressed RAM block device support"
 	depends on BLOCK && SYSFS && ZSMALLOC && CRYPTO
-	select CRYPTO_LZO
 	help
 	  Creates virtual block devices called /dev/zramX (X = 0, 1, ...).
 	  Pages written to these disks are compressed and stored in memory
@@ -14,6 +13,11 @@ config ZRAM
 
 	  See Documentation/admin-guide/blockdev/zram.rst for more information.
 
+config ZRAM_AUTOSEL_ALGO
+	def_bool y
+	depends on ZRAM && !(CRYPTO_LZ4 || CRYPTO_LZ4HC || CRYPTO_842 || CRYPTO_ZSTD)
+	select CRYPTO_LZO
+
 config ZRAM_WRITEBACK
        bool "Write back incompressible or idle page to backing device"
        depends on ZRAM
drivers/block/zram/zcomp.c +17 -0
index 33e3b76c4fa9..4fad177c78c4 100644
@@ -15,8 +15,10 @@
 #include "zcomp.h"
 
 static const char * const backends[] = {
+#if IS_ENABLED(CONFIG_CRYPTO_LZO)
 	"lzo",
 	"lzo-rle",
+#endif
 #if IS_ENABLED(CONFIG_CRYPTO_LZ4)
 	"lz4",
 #endif
@@ -202,6 +204,21 @@ void zcomp_destroy(struct zcomp *comp)
 	kfree(comp);
 }
 
+const char *default_compressor(void)
+{
+	/*
+	 * Pick the first available one (there should be at least one).
+	 *
+	 * In theory, we can drop all the ifdefs from backends[] and
+	 * just iterate backends array doing crypto_has_comp(comp, 0, 0)
+	 * for each entry and return the first one which is recognized by
+	 * crypto. But crypto_has_comp() modprobes compression drivers,
+	 * so we may end up with extra loaded drivers, when the 'default'
+	 * compressor is not what zram is configured to use.
+	 */
+	return backends[0];
+}
+
 /*
  * search available compressors for requested algorithm.
  * allocate new zcomp and initialize it. return compressing
drivers/block/zram/zcomp.h +1 -0
index 40f6420f4b2e..f104be9eae9c 100644
@@ -27,6 +27,7 @@ int zcomp_cpu_dead(unsigned int cpu, struct hlist_node *node);
 ssize_t zcomp_available_show(const char *comp, char *buf);
 bool zcomp_available_algorithm(const char *comp);
 
+const char *default_compressor(void);
 struct zcomp *zcomp_create(const char *comp);
 void zcomp_destroy(struct zcomp *comp);
 
drivers/block/zram/zram_drv.c +3 -2
index 1b697208d661..f02ee050c7bf 100644
@@ -42,7 +42,6 @@ static DEFINE_IDR(zram_index_idr);
 static DEFINE_MUTEX(zram_index_mutex);
 
 static int zram_major;
-static const char *default_compressor = "lzo-rle";
 
 /* Module params (documentation at end) */
 static unsigned int num_devices = 1;
@@ -1960,7 +1959,9 @@ static int zram_add(void)
 	blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, zram->disk->queue);
 	device_add_disk(NULL, zram->disk, zram_disk_attr_groups);
 
-	strlcpy(zram->compressor, default_compressor, sizeof(zram->compressor));
+	strlcpy(zram->compressor,
+		default_compressor(),
+		sizeof(zram->compressor));
 
 	zram_debugfs_register(zram);
 	pr_info("Added device: %s\n", zram->disk->disk_name);
Signature · 1 line
2.29.1
#1 lore raw

Cc-ing Andrew

message-id: [email protected]

Quoted 6 lines · Rui Salvaterra

There's nothing special about zram and lzo. It works just fine without it, so as long as at least one of the other supported compression algorithms is selected.

Minchan, I'm fine with the change.

Two things from my side:

1) The commit message, probably, can be a bit more informative. Something like this?

ZRAM always enables CRYPTO_LZO because lzo-rle is the hardcoded fallback compression algorithm, which means that on systems where ZRAM always use, for instance, CRYPTO_ZSTD lzo kernel module becomes unneeded. This patch removes the hardcoded lzo-lre dependency, instead ZRAM picks the first supported CRYPTO compression algorithm, should it be ZSTD or LZ4, etc; and only forcibly enables CRYPTO_LZO (previous behaviour) if none of the alternative algorithms were selected.

2) The ZRAM_AUTOSEL_ALGO allows to deselect CRYPTO_LZO only if CRYPTO_LZ4/CRYPTO_LZ4HC/CRYPTO_842/CRYPTO_ZSTD are compiled in (=y). If any of the algorithms is selected as a module (=m) then CRYPTO_LZO is selected as the default algorithm. Apparently depends on !(CONFIG_FOO) means depends on !(CONFIG_FOO=y).

It appears that the below change fixes it, but it looks a bit ugly.

---

drivers/block/zram/Kconfig +1 -1
index 141ce0ebad06..f2fd34de9200 100644
@@ -15,7 +15,7 @@ config ZRAM
 
 config ZRAM_AUTOSEL_ALGO
 	def_bool y
-	depends on ZRAM && !(CRYPTO_LZ4 || CRYPTO_LZ4HC || CRYPTO_842 || CRYPTO_ZSTD)
+	depends on ZRAM && !(CRYPTO_LZ4=m || CRYPTO_LZ4HC=m || CRYPTO_842=m || CRYPTO_ZSTD=m || CRYPTO_LZ4=y || CRYPTO_LZ4HC=y || CRYPTO_842=y || CRYPTO_ZSTD=y)
 	select CRYPTO_LZO
 
 config ZRAM_WRITEBACK

---

	-ss
maintainer
#2 lore raw

Hi Sergey and Rui,

Quoted 11 lines · Sergey Senozhatsky

Cc-ing Andrew

message-id: [email protected]

Quoted 6 lines · Rui Salvaterra

There's nothing special about zram and lzo. It works just fine without it, so as long as at least one of the other supported compression algorithms is selected.

Sorry for the late. I am still looking for the time to look into this patch.

I totally agree with the motivation of Rui. Before that, just a dumb question.

Can't we just provide choice/endchoice in Kconfig to select default comp algorithm from admin?

Quoted 43 lines

Minchan, I'm fine with the change.

Two things from my side:

1) The commit message, probably, can be a bit more informative. Something like this?

ZRAM always enables CRYPTO_LZO because lzo-rle is the hardcoded fallback compression algorithm, which means that on systems where ZRAM always use, for instance, CRYPTO_ZSTD lzo kernel module becomes unneeded. This patch removes the hardcoded lzo-lre dependency, instead ZRAM picks the first supported CRYPTO compression algorithm, should it be ZSTD or LZ4, etc; and only forcibly enables CRYPTO_LZO (previous behaviour) if none of the alternative algorithms were selected.

2) The ZRAM_AUTOSEL_ALGO allows to deselect CRYPTO_LZO only if CRYPTO_LZ4/CRYPTO_LZ4HC/CRYPTO_842/CRYPTO_ZSTD are compiled in (=y). If any of the algorithms is selected as a module (=m) then CRYPTO_LZO is selected as the default algorithm. Apparently depends on !(CONFIG_FOO) means depends on !(CONFIG_FOO=y).

It appears that the below change fixes it, but it looks a bit ugly.

---

drivers/block/zram/Kconfig +1 -2
index 141ce0ebad06..f2fd34de9200 100644
@@ -15,7 +15,7 @@ config ZRAM
 
 config ZRAM_AUTOSEL_ALGO
 	def_bool y
-	depends on ZRAM && !(CRYPTO_LZ4 || CRYPTO_LZ4HC || CRYPTO_842 || CRYPTO_ZSTD)
+	depends on ZRAM && !(CRYPTO_LZ4=m || CRYPTO_LZ4HC=m || CRYPTO_842=m || CRYPTO_ZSTD=m || CRYPTO_LZ4=y || CRYPTO_LZ4HC=y || CRYPTO_842=y || CRYPTO_ZSTD=y)
 	select CRYPTO_LZO
 
 config ZRAM_WRITEBACK
---
	-ss
#3 lore raw

Hi, Minchan,

Quoted 3 lines · Minchan Kim

Can't we just provide choice/endchoice in Kconfig to select default comp algorithm from admin?

I'm fine with whatever you guys decide, just let me know what works best for everyone.

Thanks,
Rui

maintainer
#4 lore raw
Quoted 9 lines · Rui Salvaterra

Hi, Minchan,

Quoted 3 lines · Minchan Kim

Can't we just provide choice/endchoice in Kconfig to select default comp algorithm from admin?

I'm fine with whatever you guys decide, just let me know what works best for everyone.

Thanks. Sergey, if you don't mined, I'd like to approach more explict way to select default compressor algorithm in Kconfig.

Do you have any suggestion?

Thank you.

#5 lore raw
Quoted 8 lines · Minchan Kim
Quoted 7 lines · Rui Salvaterra

Hi, Minchan,

Quoted 3 lines · Minchan Kim

Can't we just provide choice/endchoice in Kconfig to select default comp algorithm from admin?

Quoted 7 lines
Quoted 2 lines

I'm fine with whatever you guys decide, just let me know what works best for everyone.

Thanks. Sergey, if you don't mined, I'd like to approach more explict way to select default compressor algorithm in Kconfig.

Do you have any suggestion?

No objections. Some people tend to dislike new Kconfig options, but we probably can live with that.

	-ss