Hideki Yamane 742c8ee507 Use zstd as default compression for initramfs
Now initramfs files are compressed with gzip
But we can use another 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 choosing ZSTD, instead of GZIP since
 - better compression ratio than current GZIP
 - also better decompression 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

(above message is patched with #971270)

So, just set default compression as zstd can bring a better result for many users,
IMO (Not sure raising zstd package Priority (to standard) is required or not).
2020-11-30 20:10:33 +09:00
..