Using Multiple Threads When Compiling the Kernel





Last Updated on 01/03/2011 by dboth

The book, Linux Kernel in a Nutshell, discusses the use of the -j option when compiling the kernel to specify the number of threads to use during the compile. It recommends using -jX where X, the number of threads, is set to twice the number of CPUs available. If -j is not specified, the default is for a single thread to be used. I have found that the recommendation of 2x the number of CPUs is too high. My own experiments show that X should be, at most, equal to the number of CPUs.

The following table shows the results of these tests which were run on an Intel single Quad Core at 2.5GHz with 6GB of RAM and no swapping taking place. The kernel being compiled was 2.6.35.10. The time command was used to determine the amount of real, user and system time spent during each compile.

Command make make -j2 make -j4 make -j6 make -j8
Real 53m53.702s 27m18.603s 15m59.833s 16m1.343s 16m4.474s
user 47m59.681s 48m9.712s 49m33.404s 50m4.645s 50m25.345s
System 6m23.531s 6m23.534s 6m37.396s 6m46.502s 6m48.929

Note that any number larger than the number of CPUs results in a longer compile time, although only slightly. There is clearly no advantage to specifying more threads than the total number of CPUs. However there is a significant advantage to specifying the -j option to be equal to the number of CPUs.





Leave a Reply