Skip to content

Commit

Permalink
Merge pull request #2465 from DaanDeMeyer/kmod
Browse files Browse the repository at this point in the history
Speed up kernel modules initrd generation if no excludes were specified
  • Loading branch information
behrmann authored Mar 6, 2024
2 parents 69afbf5 + 0963257 commit 165008b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mkosi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3626,7 +3626,7 @@ def bold(s: Any) -> str:
Kernel Command Line: {line_join_list(config.kernel_command_line)}
Kernel Modules Include: {line_join_list(config.kernel_modules_include)}
Kernel Modules Exclude: {line_join_list(config.kernel_modules_exclude)}
Kernel Modules Include Host: {yes_no(config.kernel_modules_initrd_include_host)}
Kernel Modules Include Host: {yes_no(config.kernel_modules_include_host)}
Kernel Modules Initrd: {yes_no(config.kernel_modules_initrd)}
Kernel Modules Initrd Include: {line_join_list(config.kernel_modules_initrd_include)}
Expand Down
16 changes: 12 additions & 4 deletions mkosi/kmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def resolve_module_dependencies(
"""
modulesd = Path("usr/lib/modules") / kver
builtin = set(module_path_to_name(Path(m)) for m in (root / modulesd / "modules.builtin").read_text().splitlines())
allmodules = set((root / modulesd / "kernel").glob("**/*.ko*"))
allmodules = set((root / modulesd / "kernel").rglob("*.ko*"))
nametofile = {module_path_to_name(m): m for m in allmodules}

log_step("Running modinfo to fetch kernel module dependencies")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 165008b

Please sign in to comment.