LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] kbuild: allow setting zstd compression level for modules
@ 2021-04-09 13:28 torvic9
  2021-04-09 13:31 ` [PATCH 2/2] kbuild: allow setting zstd compression level for kernel torvic9
  0 siblings, 1 reply; 2+ messages in thread
From: torvic9 @ 2021-04-09 13:28 UTC (permalink / raw
  To: linux-kbuild@vger.kernel.org, masahiroy@kernel.org
  Cc: linux-kernel@vger.kernel.org, Piotr Górski

Zstd offers a very fine-grained control of compression ratios.
Add a Kconfig option that allows setting the desired compression
level for module compression.

Based on Masahiro's linux-kbuild.

Signed-off-by: Tor Vic <torvic9@mailbox.org>
Tested-by: Piotr Gorski <lucjan.lucjanov@gmail.com>
---
 init/Kconfig             | 8 ++++++++
 scripts/Makefile.modinst | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/init/Kconfig b/init/Kconfig
index b5744d32c..15bb02c24 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -2275,6 +2275,14 @@ config MODULE_COMPRESS_ZSTD
 
 endchoice
 
+config MODULE_COMPRESS_ZSTD_LEVEL
+    int "Compression level (1-19)"
+    depends on MODULE_COMPRESS_ZSTD
+    range 1 19
+    default 3
+    help
+        Compression level used by zstd for compressing modules.
+
 config MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS
 	bool "Allow loading of modules with missing namespace imports"
 	help
diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst
index ff9b09e4c..0a0db2278 100644
--- a/scripts/Makefile.modinst
+++ b/scripts/Makefile.modinst
@@ -97,7 +97,7 @@ quiet_cmd_gzip = GZIP    $@
 quiet_cmd_xz = XZ      $@
       cmd_xz = $(XZ) --lzma2=dict=2MiB -f $<
 quiet_cmd_zstd = ZSTD    $@
-      cmd_zstd = $(ZSTD) -T0 --rm -f -q $<
+      cmd_zstd = $(ZSTD) -$(CONFIG_MODULE_COMPRESS_ZSTD_LEVEL) -T0 --rm -f -q $<
 
 $(dst)/%.ko.gz: $(dst)/%.ko FORCE
 	$(call cmd,gzip)
-- 
2.31.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] kbuild: allow setting zstd compression level for kernel
  2021-04-09 13:28 [PATCH 1/2] kbuild: allow setting zstd compression level for modules torvic9
@ 2021-04-09 13:31 ` torvic9
  0 siblings, 0 replies; 2+ messages in thread
From: torvic9 @ 2021-04-09 13:31 UTC (permalink / raw
  To: linux-kbuild@vger.kernel.org, masahiroy@kernel.org
  Cc: linux-kernel@vger.kernel.org, Piotr Górski

In a similar way to the first patch in this series, add another Kconfig
option that allows setting the zstd compression level for the kernel
as well.
This enables users to choose either a compression level between 1 and 19,
or instead use the highest possible level (ultra-22).
Also add '-T0' parameter in both cases.

Signed-off-by: Tor Vic <torvic9@mailbox.org>
---
 arch/x86/boot/compressed/Makefile |  5 +++++
 init/Kconfig                      | 19 +++++++++++++++++++
 scripts/Makefile.lib              |  4 ++--
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index e0bc3988c..59ed10c61 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -130,8 +130,13 @@ $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
 	$(call if_changed,lzo)
 $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
 	$(call if_changed,lz4)
+ifdef CONFIG_KERNEL_ZSTD_ULTRA
 $(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE
 	$(call if_changed,zstd22)
+else
+$(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE
+	$(call if_changed,zstd)
+endif
 
 suffix-$(CONFIG_KERNEL_GZIP)	:= gz
 suffix-$(CONFIG_KERNEL_BZIP2)	:= bz2
diff --git a/init/Kconfig b/init/Kconfig
index 15bb02c24..1d3c5eebf 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -321,6 +321,25 @@ config KERNEL_UNCOMPRESSED
 
 endchoice
 
+menu "ZSTD compression options"
+    depends on KERNEL_ZSTD
+
+config KERNEL_ZSTD_LEVEL
+    int "Compression level (1-19)"
+    range 1 19
+    default 19
+    help
+        Choose a compression level for zstd kernel compression.
+        Default is 19.
+
+config KERNEL_ZSTD_LEVEL_ULTRA
+    bool "Ultra compression"
+    help
+        Selecting this overrides the chosen compression level and enables
+        the highest possible compression level for zstd (ultra-22).
+
+endmenu
+
 config DEFAULT_INIT
 	string "Default init path"
 	default ""
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index a4fbaf888..aa29b97fb 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -455,10 +455,10 @@ quiet_cmd_xzmisc = XZMISC  $@
 # be used because it would require zstd to allocate a 128 MB buffer.
 
 quiet_cmd_zstd = ZSTD    $@
-      cmd_zstd = { cat $(real-prereqs) | $(ZSTD) -19; $(size_append); } > $@
+      cmd_zstd = { cat $(real-prereqs) | $(ZSTD) -$(CONFIG_KERNEL_ZSTD_LEVEL) -T0; $(size_append); } > $@
 
 quiet_cmd_zstd22 = ZSTD22  $@
-      cmd_zstd22 = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@
+      cmd_zstd22 = { cat $(real-prereqs) | $(ZSTD) -22 --ultra -T0; $(size_append); } > $@
 
 # ASM offsets
 # ---------------------------------------------------------------------------
-- 
2.31.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-09 13:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-09 13:28 [PATCH 1/2] kbuild: allow setting zstd compression level for modules torvic9
2021-04-09 13:31 ` [PATCH 2/2] kbuild: allow setting zstd compression level for kernel torvic9

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).