From 816e9dd752f18f2258fdd50128d36c277eeb5ff4 Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Fri, 11 Aug 2023 21:10:23 +0200 Subject: [PATCH] Use dracut-install in manual_add_modules I sprinkled mkinitramfs with "date -Ins" to see where most time is spent. I ran the [1] test case in a chroot on my laptop. mkinitramfs took 18.3 seconds. The most time consuming parts: * 10.13 s (51.4%) auto_add_modules * 7.20 s (36.5%) run_scripts_optional /usr/share/initramfs-tools/hooks * 1.27 s (6.4%) final { cat; cpio; cpio|compress } > $outfile The remaining 1.11 seconds are spread over the remaining parts. Following hooks in /usr/share/initramfs-tools/hooks took the longest: * 4.56s (63.3%) framebuffer * 0.87s (12.1%) plymouth * 0.81s (11.3%) cryptroot * 0.23s (3.2%) lvm2 * 0.18s (2.5%) udev * 0.17s (2.4%) mdadm The remaining 0.38 seconds are spread over the remaining dozen of hooks. The framebuffer hook just calls copy_modules_dir and manual_add_modules multiple times. auto_add_modules calls copy_modules_dir multiple times and manual_add_modules. copy_modules_dir calls find and then manual_add_modules. So most time will be spent in manual_add_modules. This function calls modprobe on the modules, copies the modules, and add_firmware on the firmwares from a "modinfo -F firmware" call. Replacing manual_add_modules by a call to /usr/lib/dracut/dracut-install speeds up the initramfs building significantly. In the chroot on my laptop the mkinitramfs execution reduces from 18.3 seconds to 11.0 (40% reduction). [1] schroot-wrapper -c mantic -u root --ppa bdrung/ppa -p \ linux-image-generic,initramfs-tools,zstd,busybox-initramfs,cryptsetup-initramfs,isc-dhcp-client,kbd,lvm2,mdadm,ntfs-3g,plymouth,plymouth-theme-spinner LP: #2031185 Signed-off-by: Benjamin Drung --- debian/control | 2 +- hook-functions | 42 +++++++----------------------------------- 2 files changed, 8 insertions(+), 36 deletions(-) diff --git a/debian/control b/debian/control index 1d9a5d4..200ea67 100644 --- a/debian/control +++ b/debian/control @@ -29,7 +29,7 @@ Package: initramfs-tools-core Architecture: all Multi-Arch: foreign Recommends: zstd -Depends: ${busybox:Depends}, initramfs-tools-bin (= ${binary:Version}), klibc-utils (>= 2.0.4-8~), cpio (>= 2.12), kmod, udev, coreutils (>= 8.24), logsave | e2fsprogs (<< 1.45.3-1~), ${misc:Depends} +Depends: ${busybox:Depends}, initramfs-tools-bin (= ${binary:Version}), dracut-core, klibc-utils (>= 2.0.4-8~), cpio (>= 2.12), kmod, udev, coreutils (>= 8.24), logsave | e2fsprogs (<< 1.45.3-1~), ${misc:Depends} Suggests: bash-completion Breaks: initramfs-tools (<< 0.121~), ${busybox:Breaks} Replaces: initramfs-tools (<< 0.121~) diff --git a/hook-functions b/hook-functions index fee8aab..a642b1f 100644 --- a/hook-functions +++ b/hook-functions @@ -85,47 +85,19 @@ add_firmware() # Add dependent modules + eventual firmware manual_add_modules() { - local prefix kmod options firmware + local dracut_verbose if [ $# -eq 0 ]; then return fi - # modprobe --ignore-install inhibits processing of 'install' - # configuration lines, so that instead we will see 'insmod - # module.ko' as we want. However it also means that 'softdep' - # configuration lines and embedded softdep information is not - # processed. So we run twice, with and without this option. - # shellcheck disable=SC2034 - { /sbin/modprobe --all --set-version="${version?}" --ignore-install --quiet --show-depends "$@"; - /sbin/modprobe --all --set-version="${version}" --quiet --show-depends "$@"; } | - while read -r prefix kmod options ; do - if [ "${prefix}" != "insmod" ]; then - continue - fi + if [ "${verbose?}" = "y" ]; then + dracut_verbose=-v + fi - copy_file module "${kmod}" || continue - - # Add required firmware - for firmware in $(modinfo -k "${version}" -F firmware "${kmod}"); do - # Only print warning for missing fw of loaded module - # or forced loaded module - if ! add_firmware "$firmware"; then - # Only warn about missing firmware if - # /proc/modules exists - if [ ! -e /proc/modules ] ; then - continue - fi - - kmod_modname="${kmod##*/}" - kmod_modname="${kmod_modname%%.*}" - if grep -q "^$kmod_modname\\>" /proc/modules "${CONFDIR}/modules"; then - echo "W: Possible missing firmware /lib/firmware/${firmware} for module ${kmod_modname}" >&2 - fi - continue - fi - done - done + /usr/lib/dracut/dracut-install -D "$DESTDIR" --kerneldir "/lib/modules/${version?}" \ + --firmwaredirs "/lib/firmware/updates/${version?}:/lib/firmware/updates:/lib/firmware/${version?}:/lib/firmware" \ + ${dracut_verbose-} -o -m "$@" } # manual_add_modules() takes care of adding firmware for things that were built -- 2.39.2