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?

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.


You do not need to run make menuconfig again every time you make a change — it is only needed once to create the kernel .config file. (Or possibly again if you edit Kconfig files to add or modify configuration options, but this certainly shouldn't be happening often.)

So long as your .config is left alone, running make should only recompile files that you changed. There are a few files that must be compiled every time, but the vast majority are not.


  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.


make -j will make use of all available CPUs.


ccache should be able to dramatically speed up your compile times. It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again. Your first compilation with ccache will be slower since it needs to populate the cache, but subsequent builds should be much faster.

If you don't want to fuss with ccache configurations you can just run it like so to compile the kernel:

ccache make

Perhaps in addition to the previous suggestions, using ccache software (https://ccache.samba.org/) and a compilation directory on SSD drive should drastically decrease the compilation time.


If you have suffitient RAM and you wont be using your machine while the kernel is being built u can spawn a large number of concurrent jobs. But make sure your RAM is sufficient otherwise your system will hang and crash.


Perhaps in addition to the previous suggestions, while using ccache, you might want to unset CONFIG_GCC_PLUGINS (if it was set) otherwise you may get a lot of cache misses, as seen in this example.


Need Your Help

Django: implementing JOIN using Django ORM?

django django-models join django-queryset django-orm

I have a Q&amp;A type of site built in Django with the following models:

Getting the computer to realise 360 degrees = 0 degrees, rotating a gun turret

algorithm

I'm making a game and in it is a computer controlled gun turret.