Bug#652525: Takes excessively long time to generate initramfs
Package: initramfs-tools
Version: 0.99
Severity: normal
File: /usr/sbin/update-initramfs
In the last few versions of initramfs-tools, update-initramfs started
taking an excessively long time to generate the initramfs:
~$ time sudo update-initramfs -u
update-initramfs: Generating /boot/initrd.img-3.1.0-1-amd64
real 0m26.197s
user 0m14.785s
sys 0m1.196s
This results in a long delay every time I upgrade either a kernel or any
package with an update-initramfs hook.
As far as I can tell, a large part of this processing time seems to
consist of the per-module processing for the ~500 kernel modules copied
into the initramfs, forking off a pile of programs for each one. I
tried optimizing the per-module hot path to eliminate as many forks as
possible, and managed to speed it up considerably:
~$ time sudo update-initramfs -u
update-initramfs: Generating /boot/initrd.img-3.1.0-1-amd64
real 0m21.385s
user 0m14.393s
sys 0m0.740s
I've attached a patch implementing these optimizations.
A few other possible improvements:
- Generate a list of modules and processing them all in batch at the
end of update-initramfs, to allow calling modprobe and modinfo only
once. Likely to make a huge difference.
- In the absence of the above, make manual_add_modules take a list of
modules and process them all, and make the various hooks pass a list
of modules to manual_add_modules rather than calling it repeatedly.
- Avoid using copy_exec for firmware binaries, to avoid running ldd on
them.
- Cache the contents of /proc/modules and ${CONFDIR}/modules, and
eliminating the call to grep via more magic shell variable tricks.
- Rewrite the whole thing in something less glacial than shell; perhaps
something with bindings to the new libkmod. Or, at least rewrite the
hot paths, and use the shell only to string pieces together.
-- /etc/kernel-img.conf
# Kernel image management overrides
# See kernel-img.conf(5) for details
do_symlinks = no
do_bootloader = no
do_initrd = yes
link_in_boot = no
Kernel: Linux 3.1.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=C.UTF-8, LC_CTYPE=C.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages initramfs-tools depends on:
ii cpio 2.11-7
ii findutils 4.4.2-1+b1
ii klibc-utils 1.5.25-1
ii module-init-tools 3.16-1
ii udev 175-3
Versions of packages initramfs-tools recommends:
ii busybox 1:1.19.3-5
Versions of packages initramfs-tools suggests:
ii bash-completion 1:1.3-1