Proposed kbuild changes cut full kernel builds by up to 36%
Lorenzo Stoakes says caching, a faster dependency check, assembly module descriptors and less serial work also slash incremental and no-op rebuilds.
A set of kbuild changes posted by Lorenzo Stoakes would cut the time spent in the single-threaded tail of a Linux kernel build, with measured full allmodconfig builds as much as 36% faster, incremental rebuilds about 60% to 70% faster, and do-nothing rebuilds as much as about 90% faster.
On a two-socket AMD EPYC machine, an allmodconfig build with GCC fell from 188 seconds to 121 seconds. The same configuration on a 128-thread Threadripper dropped from about 344 seconds to 279 seconds with GCC, and from 343 seconds to 267 seconds with Clang. Incremental allmodconfig rebuilds on those machines fell from roughly 40 to 70 seconds to about 15 to 24 seconds. Stoakes reported gains on every machine he tried, including an eight-core Arm laptop.
The slowdown is not the compiler. Make repeatedly works out, for every object, whether it is built in or part of a module, and the cost grows with the square of the object count in a directory. Large trees such as the AMD GPU driver are hit hardest, and a rebuild where nothing has changed still pays that cost. Header dependency files, often more than a thousand lines each, are parsed by make even when almost nothing is stale. Stoakes replaces that repeated work with a one-time lookup and a small C helper that stats each dependency once and hands make only the targets that actually need attention.
Module packaging is the other large serial cost. An allmodconfig x86-64 tree builds more than 11,000 module descriptor files, each compiled as ordinary C with hundreds of headers, accounting for thousands of CPU seconds and more than a gigabyte of dependency files that later builds must reread. Emitting those descriptors as assembly, with the same section layout as the C version, removes that compile. The remaining module-final jobs are tiny, on the order of 22,000 of them, so they are batched, about 128 modules at a time, cutting a modules-only rebuild on the Threadripper from 28.9 seconds to 15.9 seconds.
modpost, which runs after vmlinux is linked and cannot be parallelised away, also stops rechecking the same section names on every relocation. With Rust enabled, the crates no longer have to finish before the rest of the tree starts, which Stoakes measured as an 11% faster clean defconfig build and about 19 seconds off a clean allmodconfig build on the Threadripper.
The numbers assume a recent kernel tree, parallel Rust compilation flags, and pigz installed, and they shift by a few seconds if two related module and objtool changes are absent. Stoakes says the resulting objects match the previous build.