I am using Linux 3.18.25 on i5 (second gen) machine(dual boot windows and Linux). I am making some changes in kernel modules to get idea of the kernel code. The problem is, every time I compile my code using make command it takes 1 hour and 30 minutes approximately, even if I use make -j 4 command it takes almost same time. What should I do to compile the kernel code more quickly? Is there any other way to compile kernel other than using make or make -j 4 command?
2 Answers
It all depends on the machine you are using, in order for j4 to work you need at least 4 cores. otherwise the jobs will just wait for each other (this looks exctly as you describe). try and compile on a multicore machine instead (I know this is not very helpful, but from my expiriance compiling kernels there is not much else you can do).
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
good luck

- 1
- 1

- 96
- 1
- 9
-
I am using i5(second gen) machine. – Hamid Jan 25 '16 at 14:16
-
weird, that's a VERY log time for a kernel to compile on a processor like yours, did you check that multicore calculation work properly on it? – daTokenizer Jan 25 '16 at 14:18
Well I am not expert but from my experience:
- set -J parameter same as your processors if you have 8 then make it
8, you can check from 'cat /proc/cpuinfo
' - If its virtual machine make sure you have hyper enabled and
virtual machine is using more than one physical cpu core - Dont use toolchain and try to compile at the same target
architecture (i.e. if its amd64 then compile at amd 64 bit
machine)
**EDIT: (Update from Andy comment) Check ccache and how its used in kernel compilation: http://linuxdeveloper.blogspot.de/2012/05/using-ccache-to-speed-up-kernel.html
Additional note: Also make sure you squeeze your CPU enough https://askubuntu.com/questions/523640/how-i-can-disable-cpu-frequency-scaling-and-set-the-system-to-performance
-
1see the edit to my answer. there's a like to all those technics and more :) – daTokenizer Jan 25 '16 at 14:23
-
1
-
I am using Linux on dual boot. Could you please explain to me what do you mean by compile at the same target architecture ? – Hamid Jan 25 '16 at 14:32
-
1@HamidAli Lets say you have 2 machine one with ARM 32 bit cpu ( i.e. nvidia jetson tk1 or raspberry) and one amd 64 bit. If you want to create kernel for ARM and if you want to build this kernel in amd 64 bit machine it will take more time, but if you build ARM kernel on ARM machine you will have process more faster, at least this is what I have experienced. Google 'linux kernel cross-compilation' for more info – HRgiger Jan 25 '16 at 14:45
-
2
-
@AndyShevchenko thanks its very interesting and I was not aware, I have updated my answer – HRgiger Jan 26 '16 at 12:02