Posts Speeding Up Linux Kernel Builds with Compiler Cache (Ccache)
Speeding Up Linux Kernel Builds with Compiler Cache (Ccache)
Cancel

Speeding Up Linux Kernel Builds with Compiler Cache (Ccache)

Preview Image

This article will focus on how to set up and build Linux kernel compilation time faster than usual using Cache (Compiler Cache). Normally, it takes about 30mins to compile the Linux kernel on my laptop with a low CPU. That makes it very inconvenient. This problem can be solved with Ccache. Compiling with Ccache speeds up to 3-5 mins.

What is Ccache?

Ccache (Compiler Cache) is used to speed up compilation time when compiling C, C ++, Objective-C and Objective-C ++ code.

Installation and Setup Ccache

First of all, you need to have the Ccache package installed on your GNU/Linux machine.

If you want to check the Ccache version you have installed:

1
ccache --version

You can install on Debian-based Linux system if not already installed Ccache:

1
sudo apt install ccache

Specify the maximum size of the cache cache.

For example:

1
ccache -M 32

Screenshot

To view your current ccache statistics, type the ccache -s command.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
zawzaw@ubuntu-linux:~/Linux-kernel/linux-stable$ ccache -s
cache directory                     /home/zawzaw/.cache
primary config                      /home/zawzaw/.cache/ccache.conf
secondary config      (readonly)    /etc/ccache.conf
stats updated                       Fri Jul 26 15:53:23 2019
stats zeroed                        Fri Jul 26 15:02:19 2019
cache hit (direct)                  5139
cache hit (preprocessed)              24
cache miss                          2488
cache hit rate                     67.48 %
called for preprocessing              87
unsupported code directive            14
no input file                        804
cleanups performed                     0
files in cache                     80206
cache size                           2.5 GB
max cache size                      32.0 GB

Building Linux Kernel with Ccache

Navigate to the Linux kernel source directory and clean the output files first.

1
make clean && make mrproper

Screenshot

The next step is to configure the kernel before compiling the Linux kernel. I used the default configuration as an example.

1
make defconfig

Screenshot

To compile the Linux kernel with Ccache, you will need to add the CC="ccache gcc" option with the make command.

1
make CC="ccache gcc" -j$(nproc --all)

If you want to know the exact compilation time result, you need to use the time command.

1
time make CC="ccache gcc" -j$(nproc --all)

Screenshot Screenshot

Final compilation time:

1
2
3
real     4m18.145s
user     5m20.449s
sys      3m50.917s
This post is licensed under CC BY 4.0 by the author.
Table of Contents

Building the Pure Android from Source Code

Make Build System in Android OS

Comments powered by Disqus.