Kbuild series cuts Linux kernel build times by up to 90%
Lorenzo Stoakes targets single-threaded bottlenecks in kallsyms, modpost, nm, and make dependency checks.
Lorenzo Stoakes has proposed a 21-patch overhaul of the Linux kernel build system that sharply reduces time spent in single-threaded bottlenecks after parallel compilation finishes.
On allmodconfig builds, full compiles ran up to 36% faster on a dual-socket EPYC machine and about 20% faster on a 64-core Threadripper, with both GCC and Clang. Incremental rebuilds after a one-file change dropped by roughly 60 to 70%. No-op builds, where make is run with nothing to do, improved by as much as about 90%. Stoakes reported gains on every machine tested, including an 8-core Apple M2.
Much of the win comes from work that sits on the serial tail of every vmlinux link. Kallsyms symbol compression no longer rescans every symbol for every token assignment, a path that previously burned half its runtime on large kernels. Its multi-megabyte assembly output was replaced with binary data pulled in via .incbin, cutting assemble time substantially. Kallsyms now reads the ELF image directly instead of round-tripping through nm and a large sed script, and nm itself skips sorting where order is irrelevant. Architectures that emit relocation tables do so only on the final link, not on intermediate trial links. Modpost caches section-mismatch results so it stops re-walking the same tables for every relocation, a change that alone trimmed several seconds from allmodconfig incremental builds.
On the make side, object membership in built-in versus module lists is cached to avoid quadratic cost in large directories, and a new depcheck helper replaces heavyweight parsing of thousand-line .cmd dependency files when little has changed. Repeated compiler and linker feature probes that used to fire on every make invocation were turned into one-time Kconfig options.
The measured numbers assume related earlier cleanups, pigz installed, and Rust build threads set explicitly. Image and System.map outputs remain equivalent; the stripped vmlinux differs only in program headers where .modinfo handling was corrected.