]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Speed up kernel modules initrd generation if no excludes were specified 2465/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 6 Mar 2024 12:01:35 +0000 (13:01 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 6 Mar 2024 13:31:25 +0000 (14:31 +0100)
If no excludes were specified, we can just glob all modules and firmware
without going via modinfo. We can only do this if no firmware was installed
as otherwise we end up copying firmware into the initrd that's not depended
on by any kernel modules.

mkosi/kmod.py

index abe7a830574083e8cb18ef0d3502c687e46e2a44..06dfed6182c76c5510697d4063e6c59cec638fa9 100644 (file)
@@ -159,10 +159,18 @@ def gen_required_kernel_modules(
     sandbox: SandboxProtocol = nosandbox,
 ) -> Iterator[Path]:
     modulesd = root / "usr/lib/modules" / kver
-    modules = filter_kernel_modules(root, kver, include=include, exclude=exclude, host=host)
 
-    names = [module_path_to_name(m) for m in modules]
-    mods, firmware = resolve_module_dependencies(root, kver, names, sandbox=sandbox)
+    # There is firmware in /usr/lib/firmware that is not depended on by any modules so if any firmware was installed
+    # we have to take the slow path to make sure we don't copy firmware into the initrd that is not depended on by any
+    # kernel modules.
+    if exclude or not (root / "usr/lib/firmware").glob("*"):
+        modules = filter_kernel_modules(root, kver, include=include, exclude=exclude, host=host)
+        names = [module_path_to_name(m) for m in modules]
+        mods, firmware = resolve_module_dependencies(root, kver, names, sandbox=sandbox)
+    else:
+        logging.debug("No modules excluded and no firmware installed, using kernel modules generation fast path")
+        mods = set((modulesd / "kernel").rglob("*.ko*"))
+        firmware = set()
 
     yield modulesd.parent
     yield modulesd