Published a set of patches that speed up the assembly of the Linux kernel by 50-80%

Ingo Molnar, well-known Linux kernel developer and author of the CFS (Completely Fair Scheduler) task scheduler, proposed a series of patches for discussion on the Linux kernel developers mailing list, affecting more than half of all files in the kernel sources and providing an increase in the speed of a full kernel rebuild by 50-80% depending on the settings. The implemented optimization is remarkable in that it involves 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 "include/" and "arch/*/include/" directories). ” and 15 thousand files with source texts).

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

Among the changes made: separating high-level header files from each other, eliminating inline functions linking header files, separating header files for types and APIs, providing separate assembly of header files (about 80 files had indirect dependencies that interfered with the 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 post-preprocessing stage by 1-2 orders of magnitude. For example, before optimization, the use of the "linux/gfp.h" header file resulted in 13543 lines of code and 303 dependent header files, but 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 included, most of which is not used in pid.c. Separation of header files made it possible to reduce the amount of processed code by a factor of three, reducing the number of processed lines to 36.

With a complete rebuild of the kernel with the β€œmake -j96 vmlinux” command 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 assemblies. With incremental builds, the effect of optimization is even more noticeable - the time to rebuild 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.

Source: opennet.ru

Add a comment