d4a4eb
From 7ee74e539dba61c3765afe34426b085eff0de027 Mon Sep 17 00:00:00 2001
d4a4eb
From: Kairui Song <kasong@redhat.com>
d4a4eb
Date: Thu, 21 Feb 2019 13:18:37 +0800
d4a4eb
Subject: [PATCH] dracut: let module handling function accept optional path
d4a4eb
 option
d4a4eb
d4a4eb
Let the caller pass in the module path instead of try to find the module
d4a4eb
path everytime. This helps optimize the overall runtime.
d4a4eb
d4a4eb
Test results (3 rounds) on Fedora 30 in KVM VM with 8 CPUs, 2G memory, HDD:
d4a4eb
d4a4eb
    $ time ./dracut.sh --local --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode 'strict' -o 'plymouth dash resume ifcfg' --mount '/dev/mapper/fedora-root /sysroot xfs defaults' --no-hostonly-default-device -f initramfs.img
d4a4eb
    Before the commit:
d4a4eb
    real    0m11.782s  |  real    0m11.505s  |  real    0m11.958s
d4a4eb
    user    0m9.169s   |  user    0m9.218s   |  user    0m9.327s
d4a4eb
    sys     0m10.839s  |  sys     0m10.829s  |  sys     0m10.925s
d4a4eb
d4a4eb
    After this commit:
d4a4eb
    real    0m9.866s  |  real    0m9.580s  |  real    0m9.638s
d4a4eb
    user    0m9.048s  |  user    0m9.142s  |  user    0m9.120s
d4a4eb
    sys     0m7.411s  |  sys     0m7.775s  |  sys     0m7.745s
d4a4eb
d4a4eb
Test result of building a ordinary image:
d4a4eb
d4a4eb
    $ time ./dracut.sh --local --quiet -f initramfs.img
d4a4eb
    Before the commit:
d4a4eb
    real    0m34.697s  |  real    0m34.371s  |  real    0m35.122s
d4a4eb
    user    0m27.608s  |  user    0m27.524s  |  user    0m27.705s
d4a4eb
    sys     0m22.341s  |  sys     0m22.032s  |  sys     0m22.246s
d4a4eb
d4a4eb
    After the commit:
d4a4eb
    real    0m31.914s  |  real    0m31.006  |  real    0m31.289ss
d4a4eb
    user    0m27.315s  |  user    0m27.324  |  user    0m27.290ss
d4a4eb
    sys     0m19.051s  |  sys     0m18.916  |  sys     0m19.022ss
d4a4eb
d4a4eb
This will have an ~2s speed up.
d4a4eb
d4a4eb
Signed-off-by: Kairui Song <kasong@redhat.com>
d4a4eb
(cherry picked from commit 5916d31b24ad9eb21fd376929a96c459813315a1)
d4a4eb
d4a4eb
Cherry-picked from: 5916d31b
d4a4eb
Resolves: #1734047
d4a4eb
---
d4a4eb
 dracut-init.sh | 4 ++++
d4a4eb
 dracut.sh      | 8 ++++----
d4a4eb
 2 files changed, 8 insertions(+), 4 deletions(-)
d4a4eb
d4a4eb
diff --git a/dracut-init.sh b/dracut-init.sh
d4a4eb
index b1ac9966..ab07cabf 100644
d4a4eb
--- a/dracut-init.sh
d4a4eb
+++ b/dracut-init.sh
d4a4eb
@@ -154,6 +154,10 @@ dracut_no_switch_root() {
d4a4eb
     >"$initdir/lib/dracut/no-switch-root"
d4a4eb
 }
d4a4eb
 
d4a4eb
+dracut_module_path() {
d4a4eb
+    echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; }
d4a4eb
+}
d4a4eb
+
d4a4eb
 if ! [[ $DRACUT_INSTALL ]]; then
d4a4eb
     DRACUT_INSTALL=$(find_binary dracut-install)
d4a4eb
 fi
d4a4eb
diff --git a/dracut.sh b/dracut.sh
d4a4eb
index 8144a16e..f270af76 100755
d4a4eb
--- a/dracut.sh
d4a4eb
+++ b/dracut.sh
d4a4eb
@@ -1373,7 +1373,7 @@ do_print_cmdline()
d4a4eb
     for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
d4a4eb
         _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
d4a4eb
         [[ ${_mods_to_print[$_d_mod]} ]] || continue
d4a4eb
-        module_cmdline "$_d_mod"
d4a4eb
+        module_cmdline "$_d_mod" "$moddir"
d4a4eb
     done
d4a4eb
     unset moddir
d4a4eb
 }
d4a4eb
@@ -1454,14 +1454,14 @@ for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
d4a4eb
         dinfo "*** Including module: $_d_mod ***"
d4a4eb
     fi
d4a4eb
     if [[ $kernel_only == yes ]]; then
d4a4eb
-        module_installkernel "$_d_mod" || {
d4a4eb
+        module_installkernel "$_d_mod" "$moddir" || {
d4a4eb
             dfatal "installkernel failed in module $_d_mod"
d4a4eb
             exit 1
d4a4eb
         }
d4a4eb
     else
d4a4eb
-        module_install "$_d_mod"
d4a4eb
+        module_install "$_d_mod" "$moddir"
d4a4eb
         if [[ $no_kernel != yes ]]; then
d4a4eb
-            module_installkernel "$_d_mod" || {
d4a4eb
+            module_installkernel "$_d_mod" "$moddir" || {
d4a4eb
                 dfatal "installkernel failed in module $_d_mod"
d4a4eb
                 exit 1
d4a4eb
             }
d4a4eb