Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to speed up Linux kernel compilation?

I have core i5 with 8gb RAM. I have VMware workstation 10.0.1 installed on my machine. I have fedora 20 Desktop Edition installed on VMware as guest OS.

I am working on Linux kernel source code v 3.14.1. I am developing an I/O scheduler for Linux kernel. After any modifications in code every time it takes around 1 hour and 30 minutes for compiling and installing the whole kernel code to see the changes.

Compilation and Installation commands: make menuconfig, make, make modules, make modules_install, make install

So my question is it possible to reduce 1 hour and 30 minutes time into only 10 to 15 minutes?

like image 622
momersaleem Avatar asked Apr 24 '14 20:04

momersaleem


People also ask

How long should it take to compile the Linux kernel?

The Linux kernel takes around 5 minutes (without modules) to build on an Intel Core i5 Jasper Lake mini PC with 16 GB RAM and a fast SSD based on our recent review of Beelink GTi 11 mini PC. Kernel developers may have to build for different targets and configurations, plus all modules so the build times may add up.

How much RAM is needed to compile a Linux kernel?

Compilation can often be parallelized. As for the hardware: Pick a SSD to store the OS and source files, this should reduce startup times (the time that is needed to read the sources into the filesystem cache). Pick at least 8 GB RAM, 16 GB or more is recommended.

How do I speed up Linux kernel development?

make -jn: The easier way to speed-up Linux kernel compilation is executing make with the option -j (jobs). This option specifies the number of parallel jobs that make will use to split the build process. Because the kernel Makefile have correct dependency information, one doesn’t have to use make’s default single process execution.

How to use ccache to speed up Linux kernel compile?

To use ccache to speedup Linux kernel compile, all I had to do was ‘yum install ccache’ on Fedora10 system. This automatically created all needed symlinks and PATH setting. After this do make O=build bzImage; make O=build modules as usual. First time you won’t notice any speed gain as ccache is simply building up its cache.

What is the average run-time of Linux kernel compilation?

Based on OpenBenchmarking.org data, the selected test / test configuration ( Timed Linux Kernel Compilation 5.14 - Time To Compile) has an average run-time of 20 minutes.

How long does it take to compile a kernel?

EDIT: as it turns out I lived a very protected life so far. kernel compilation usually takes between 1-2 hour - exactly what you see. BUT: there is still things you can do, and they are all listed here


2 Answers

Do not do make menuconfig for every change you make to the sources, because it will trigger a full compilation of everything, no matter how trivial your change is. This is only needed when the configuration option of the kernel changes, and that should sheldom happen during your development.

Just do:

make 

or if you prefer the parallel compilation:

make -j4 

or whatever number of concurrent tasks you fancy.

Then the make install, etc. may be needed for deploying the recently built binaries, of course.

Another trick is to configure the kernel to the minimum needed for your tests. I've found that for many tasks a UML compilation (User Mode Linux) is the fastest. You may also find useful make localmodconfig instead of make menuconfig to start with.

like image 138
rodrigo Avatar answered Sep 17 '22 14:09

rodrigo


  1. Use make parallel build with -j option
  2. Compile for the target architecture only, since otherwise make will build the kernel for every listed architecture.

i.e. for eg instead of running:

make 

run:

make ARCH=<your architecture> -jN 

where N is the no of cores on your machine (cat /proc/cpuinfo lists the no of cores). For eg, for i386 target and host machine with 4 cores (output of cat /proc/cpuinfo):

make ARCH=i386 -j4 

Similarly you can run the other make targets (modules, modules_install, install) with -jN flag.

Note: make does a check of the files modified and compiles only those files which have been modified so only the initial build should take time, subsequent builds will be faster.

like image 29
brokenfoot Avatar answered Sep 20 '22 14:09

brokenfoot