Skip to content

mkinitramfs: Do not store intermediate main cpio archive

Storing the intermediate main cpio archive in a temporary file is not needed. The intermediate cpio archive can be directly piped into the compressor command. This reduces the execution time a bit and reduces the risk of the temporary directory (normally in /var/tmp) to run out of space.

Benchmarks

Benchmark on my desktop machine with an AMD Ryzen 7 5700G in a tmpfs chroot with Debian unstable on 2024-06-03. initramfs-tools 0.143:

$ schroot-wrapper -p initramfs-tools=0.143,initramfs-tools-core=0.143,linux-image-generic,firmware-linux,zstd,cryptsetup-initramfs,lvm2,kbd,mdadm,ntfs-3g,plymouth,console-setup,hyperfine -u root -c unstable
(unstable)root@desktop:~# hyperfine "update-initramfs -u"
Benchmark 1: update-initramfs -u
  Time (mean ± σ):     11.255 s ±  0.026 s    [User: 12.467 s, System: 5.728 s]
  Range (min … max):   11.194 s … 11.282 s    10 runs
(unstable)root@desktop:~# ls -l /boot/initrd.img-*
-rw-r--r-- 2 root root 67758475 Jun  3 10:54 /boot/initrd.img-6.8.12-amd64

This commit is significant faster and the generated initrd is roughly the same size:

$ schroot-wrapper -p ../initramfs-tools_0.143_all.deb,../initramfs-tools-core_0.143_all.deb,linux-image-generic,firmware-linux,zstd,cryptsetup-initramfs,lvm2,kbd,mdadm,ntfs-3g,plymouth,console-setup,hyperfine -u root -c unstable
(unstable)root@desktop:~# hyperfine "update-initramfs -u"
Benchmark 1: update-initramfs -u
  Time (mean ± σ):     10.283 s ±  0.029 s    [User: 11.620 s, System: 5.785 s]
  Range (min … max):   10.230 s … 10.335 s    10 runs
(unstable)root@desktop:~# ls -l /boot/initrd.img-*
-rw-r--r-- 1 root root 67757960 Jun  3 10:53 /boot/initrd.img-6.8.12-amd64

Benchmark on a Raspberry Pi Zero 2W with Debian unstable on 2024-06-03 and COMPRESSLEVEL=1 set in /etc/initramfs-tools/conf.d/compress.conf due to the low memory. initramfs-tools 0.143:

$ schroot-wrapper -p initramfs-tools=0.143,initramfs-tools-core=0.143,linux-image-generic,firmware-linux,zstd,cryptsetup-initramfs,lvm2,kbd,mdadm,ntfs-3g,plymouth,console-setup,hyperfine -u root -c unstable
(unstable)root@zero2w:~# hyperfine -r 10 "update-initramfs -u"
Benchmark 1: update-initramfs -u
  Time (mean ± σ):     206.167 s ±  4.261 s    [User: 53.232 s, System: 112.503 s]
  Range (min … max):   199.821 s … 210.960 s    10 runs
(unstable)root@zero2w:~# ls -l /boot/initrd.img-*
-rw-r--r-- 1 root root 83542031 Jun  3 12:13 /boot/initrd.img-6.8.12-arm64

Same result here. This commit is significant faster and the generated initrd is roughly the same size:

$ schroot-wrapper -p ./initramfs-tools_0.143_all.deb,./initramfs-tools-core_0.143_all.deb,linux-image-generic,firmware-linux,zstd,cryptsetup-initramfs,lvm2,kbd,mdadm,ntfs-3g,plymouth,console-setup,hyperfine -u root -c unstable
(unstable)root@zero2w:~# ls -l /boot/initrd.img-*
-rw-r--r-- 1 root root 83540544 Jun  3 11:26 /boot/initrd.img-6.8.12-arm64
(unstable)root@zero2w:~# hyperfine -r 10 "update-initramfs -u"
Benchmark 1: update-initramfs -u
  Time (mean ± σ):     175.592 s ±  5.514 s    [User: 54.224 s, System: 112.979 s]
  Range (min … max):   166.502 s … 182.111 s    10 runs
Edited by Benjamin Drung

Merge request reports

Loading