Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Debian Kernel (http://www.linux-archive.org/debian-kernel/)
-   -   Bug#652525: Make initramfs-tools faster by avoiding forks in the per-module hot path (http://www.linux-archive.org/debian-kernel/611390-bug-652525-make-initramfs-tools-faster-avoiding-forks-per-module-hot-path.html)

Josh Triplett 12-18-2011 07:00 AM

Bug#652525: Make initramfs-tools faster by avoiding forks in the per-module hot path
 
On Sat, Dec 17, 2011 at 10:37:29PM -0800, Josh Triplett wrote:
> 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.

I implemented this addition, making manual_add_modules take multiple
arguments, and it provided another significant performance improvement:

~$ time sudo update-initramfs -u
update-initramfs: Generating /boot/initrd.img-3.1.0-1-amd64

real 0m18.763s
user 0m14.569s
sys 0m0.720s

The difference between the original and patched versions in terms of
executed programs:

~$ grep -c 'execve' /tmp/update-initramfs.orig.strace
6355
~$ grep -c 'execve' /tmp/update-initramfs.patched.strace
2153

And more specifically the calls to modprobe:

~$ grep -c 'execve.*modprobe' /tmp/update-initramfs.orig.strace
549
~$ grep -c 'execve.*modprobe' /tmp/update-initramfs.patched.strace
34

Implementing full batching would reduce the modprobe calls down to 1,
but 34 still represents a significant improvement with relatively little
effort.

Patch attached. (This subsumes the original patch.)

- Josh Triplett


All times are GMT. The time now is 11:33 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.