Linux News

A set of patches has been published that speed up the assembly of the Linux kernel by 50-80%

Share on Facebook Share on Twitter Pinterest LinkedIn Tumblr

Ingo Molnar ( by Ingo Molnar is ), a well-known Linux kernel developer and author of CFS Task Scheduler (Completely Fair Scheduler), proposed for discussion of Linux kernel development mailing list a series of patches, affecting more than half of all the files in the kernel source and provides an increase in the total rebuilding core speed 50-80% depending on the settings. The implemented optimization is remarkable in that it is associated with the addition of the largest set of changes in the history of kernel development – 2297 patches were proposed for inclusion at once, changing more than 25 thousand files (10 thousand header files in the directories “include /” and “arch / * / include / “and 15 thousand source files).

The performance gain is achieved by changing the method of handling header files. It is noted that over thirty years of kernel development, the state of header files has taken on a depressing form due to the presence of a large number of cross-dependencies between files. The restructuring of the header files took over a year and required a significant redesign of the hierarchy and dependencies. During the restructuring, work was done to separate the type definitions and APIs for different kernel subsystems.

Among the changes made are: separation of high-level header files from each other, exclusion of inline functions that bind header files, allocation of header files for types and APIs, provision of a separate assembly of header files (about 80 files had indirect dependencies that interfere with assembly, exposed through other header files), automatic addition of dependencies to “.h” and “.c” files, step-by-step optimization of header files, use of the “CONFIG_KALLSYMS_FAST = y” mode, selective consolidation of C files into assembly blocks to reduce the number of object files.

As a result, the work done made it possible to reduce the size of header files processed at the preprocessing stage by 1-2 orders of magnitude. For example, before optimization, using the “linux / gfp.h” header file resulted in the addition of 13543 lines of code and including 303 dependent header files, and after optimization the size was reduced to 181 lines and 26 dependent files. Or another example: when preprocessing the file “kernel / pid.c” without a patch, 94 thousand lines of code are connected, most of which is not used in pid.c. Splitting the header files allowed us to reduce the amount of processed code by three times, reducing the number of processed lines to 36 thousand.

When the kernel was completely rebuilt with the command “make -j96 vmlinux” on the test system, the application of patches showed a reduction in the build time of the v5.16-rc7 branch from 231.34 to 129.97 seconds (from 15.5 to 27.7 builds per hour), and also increased the efficiency of using CPU cores during assembly. With an incremental build, the optimization effect is even more noticeable: the time for rebuilding the kernel after making changes to the header files has decreased significantly (from 112% to 173%, depending on the header file being changed). Optimizations are currently only available for ARM64, MIPS, Sparc and x86 (32- and 64-bit) architectures.

Write A Comment