From: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
To: Rui Salvaterra <rsalvaterra@gmail.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
minchan@kernel.org, ngupta@vflare.org,
linux-kernel@vger.kernel.org, linux-block@vger.kernel.org
Subject: Re: [PATCH v3] zram: break the strict dependency from lzo
Date: Wed, 28 Oct 2020 19:19:34 +0900 [thread overview]
Message-ID: <20201028101934.GB48825@google.com> (raw)
In-Reply-To: <CALjTZvbf4qK6SHEe7OhkTC_o7kaY4oOKQ+kk-D2OUq_ULsYAqQ@mail.gmail.com>
Hi,
On (20/10/27 08:39), Rui Salvaterra wrote:
> Personally, I always use zram with zstd, and the only lzo dependency I
> have is zram. Disabling lzo saves me about 3 kiB in the final
> (xz-compressed) vmlinuz image. It's not much, for sure, but when your
> total storage is 4 MiB (and your RAM is 32 MiB), every bit counts. :)
Can the following work then?
Completely untested.
===8<===
diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig
index fe7a4b7d30cf..f93eed40e155 100644
--- a/drivers/block/zram/Kconfig
+++ b/drivers/block/zram/Kconfig
@@ -2,7 +2,7 @@
config ZRAM
tristate "Compressed RAM block device support"
depends on BLOCK && SYSFS && ZSMALLOC && CRYPTO
- select CRYPTO_LZO
+ depends on (CRYPTO_LZO || CRYPTO_LZ4 || CRYPTO_LZ4HC || CRYPTO_842 || CRYPTO_ZSTD)
help
Creates virtual block devices called /dev/zramX (X = 0, 1, ...).
Pages written to these disks are compressed and stored in memory
diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index 33e3b76c4fa9..98c7c46c9c3a 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -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 endup 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
diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h
index 40f6420f4b2e..f104be9eae9c 100644
--- a/drivers/block/zram/zcomp.h
+++ b/drivers/block/zram/zcomp.h
@@ -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);
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 1b697208d661..f02ee050c7bf 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -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);
next prev parent reply other threads:[~2020-10-28 22:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-26 8:51 [PATCH v3] zram: break the strict dependency from lzo Rui Salvaterra
2020-10-27 1:22 ` Sergey Senozhatsky
2020-10-27 8:39 ` Rui Salvaterra
2020-10-28 10:19 ` Sergey Senozhatsky [this message]
2020-10-28 11:25 ` Rui Salvaterra
2020-10-28 18:21 ` Sergey Senozhatsky
2020-10-28 23:11 ` Rui Salvaterra
2020-10-29 1:29 ` Sergey Senozhatsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201028101934.GB48825@google.com \
--to=sergey.senozhatsky.work@gmail.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=minchan@kernel.org \
--cc=ngupta@vflare.org \
--cc=rsalvaterra@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.