[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#976054: initramfs-tools: [RFC] Compress initramfs file with zstd



Package: initramfs-tools
Version: 0.139
Severity: normal
Tags: patch

Dear Maintainer,

Now initramfs files are compressed with gzip
But we can use other compression, i.e. LZO, LZ4 and ZSTD.
Then which one is the best?

* compression ratio
   ZSTD > GZIP > LZO > LZ4

* decompression speed
   LZ4 > LZO = ZSTD > GZIP

I suggest to choose ZSTD, instead of GZIP since
 - better compression ratio than current GZIP
 - also better decompresion speed than current GZIP


------------------------------------------------------------------------------
With gzip
------------------------------------------------------------------------------

$ file /boot/initrd.img-5.9.0-*
/boot/initrd.img-5.9.0-3-amd64: gzip compressed data, from Unix, original size modulo 2^32 197680640
/boot/initrd.img-5.9.0-4-amd64: gzip compressed data, from Unix, original size modulo 2^32 197594112

$ du -h /boot/initrd.img-5.9.0-*
59M     /boot/initrd.img-5.9.0-3-amd64
59M     /boot/initrd.img-5.9.0-4-amd64

------------------------------------------------------------------------------
With zstd
------------------------------------------------------------------------------

$ file /boot/initrd.img-5.9.0-*
/boot/initrd.img-5.9.0-3-amd64: Zstandard compressed data (v0.8+), Dictionary ID: None
/boot/initrd.img-5.9.0-4-amd64: Zstandard compressed data (v0.8+), Dictionary ID: None

$ du -h /boot/initrd.img-5.9.0-*
40M     /boot/initrd.img-5.9.0-3-amd64
40M     /boot/initrd.img-5.9.0-4-amd64
------------------------------------------------------------------------------

Yes, 59MB initramfs file becomes 40MB (2/3)! plus bonus, better decompression speed.


However, there's a problem to do so - zstd package's Priority is not standard one 
- it's "optional". 

> Package: gzip
> Version: 1.10-2
> Priority: required

> Package: zstd
> Version: 1.4.5+dfsg-4
> Priority: optional

It means there is not zstd package in every environment. And, just raise its Priority
means bloat minimal system size that is a problem we want to avoid.

Now initramfs-tools has a hack to avoid zstd (and other compression tools)
absence in mkinitramfs command.

> if ! command -v "${compress}" >/dev/null 2>&1; then
>         compress=gzip
>         echo "No ${compress} in ${PATH}, using gzip"
> fi

Set COMPRESS=zstd in /etc/initramfs/initramfs.conf and no zstd installed,
there's no problem.

> $ sudo update-initramfs -u
> update-initramfs: Generating /boot/initrd.img-5.9.0-4-amd64
> No zstd in /usr/bin:/sbin:/bin, using gzip

 (abobe message is patched with #971270)


So, just set default compression as zstd can brings better result for many users,
IMO (Not sure raising zstd package Priority (to standard) is required or not).
>From 78c4fe32a447b0dc46045f0c8a32a4b246691711 Mon Sep 17 00:00:00 2001
From: Hideki Yamane <henrich@debian.org>
Date: Sun, 29 Nov 2020 10:05:48 +0900
Subject: [PATCH] Use zstd as default compression for initramfs

---
 conf/initramfs.conf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/conf/initramfs.conf b/conf/initramfs.conf
index 01bdd85..a0c051b 100644
--- a/conf/initramfs.conf
+++ b/conf/initramfs.conf
@@ -41,7 +41,7 @@ KEYMAP=n
 # COMPRESS: [ gzip | bzip2 | lz4 | lzma | lzop | xz | zstd ]
 #
 
-COMPRESS=gzip
+COMPRESS=zstd
 
 #
 # DEVICE: ...
-- 
2.29.2


Reply to: