Gentoo: speedup your compilations (1)

Hi all,

this is supposed to be some kind of tutorial series that tries to focus into the only disadvantage that gentoo has. The wasted cpu cycles due to constant compiling. And constant compiling means less productivity and of course more energy consumption. The last one is quite critical now days for home users or for operators owning a dedicated server in a datacenter with some power management rules.

The solutions for these so far that I have thought of are two (if you have something else on your mind please be my guest and comment in order to add it in the series)

  1. ccache
  2. distcc
  3. combination of the above


I will cover the first firstly since one error I encountered and consider it as a bug, isn’t! Still it may confuse you by letting you know that you are running a ccache where in fact you aren’t(I had a pretty nice talk with a guy in #gentoo-bugs at irc://irc.freenode.net and his reasoning was that it shouldn’t be considered as bug but should be clarified in the documentation). Secondly since most people dont have a small server farm(sic) in order to distribute the jobs it isn’t as important.

What is ccache? From its man page it is clearly stated that:

ccache is a compiler cache. It acts as a caching pre-processor to C/C++ compilers, using the -E compiler switch and a hash to detect when a compilation can be satisfied from cache. This often results in a 5 to 10 times speedup in common compilations.

In my systems my personal feeling with simple tests (two identical machines that the one has ccache and the other doesn’t) are less than 2 times for new files (obviously!). There are cases (usual cases for the everyday gentoo user) that ccache is really handy and offers great speedup. For instance you compiled the world forgeting to set the jpg USE flag on the /etc/make.conf. To make things right you have to recompile every single ebuild incorporates the jpg flag… But since jpg is just a minor flag in most cases our system has to recompile only the files (notice the difference between file and ebuild) that are “enabled” by that particular flag. Using ccache and compiling vlc twice while changing only one USE flag speeded up the compilation time 35 times in my athlon64 system compared to a system without the ccache.

How to use it: Firstly you have to install it :-P

Do it by emerge ccache (ccache at the point doesn’t have any USE flags so go ‘n’ grab it). Since your CHOST should be in your /etc/make.conf hit a emerge --info|grep CHOST;cat /etc/make.conf | grep CHOST You should see the same line twice! Afterwards hit a ccache-config --install-links WHATEVER THE PREVIOUS COMMAND RETURNED (only once of course :-P). Afterwards check cat /etc/make.conf | grep FEATURES. If in FEATURES the ccache directive is missing ADD it and you are good to go!

Is everything working right? check your ccache status with ccache -s emerge something (small preferrably) and afterwards check again your ccache’s status. If nothing changed then you have the same problem with me, considered to be misdocumented NOT a bug so don’t file a bug the responses will be just nagging and flames :-P
Check the file /root/.ccache if it is correctly linked against the directory mentioned on the /etc/make.conf with the directive CCACHE_DIR="/var/tmp/ccache" (if there isn’t a directive there the default directory is /var/tmp/ccache. After you figure out what directory to use lets say dir1 remove(or just move maybe) your preexisting ccache directory at /root/.ccache and then link it against dir1 with ln -s dir1 /root/.ccache. Now everything should run smoothly. Give ccache some space with ccache -M 8G and enjoy your investment.

How to measure ccache efficiency by yourself. Just make the user’s ccache directory (in our example /root/.ccache ) to pinpoint to an empty directory. You may do it with; (but DO NOT DO IT YET!!!)
# rm /root/.ccache #since .ccache is a symlink it is ok to delete it :-)
#mkdir /root/.ccache #create an empty directory

Check your system load before running your tests with(i.e. with top, or uptime). If load is below 0.5 continue otherwise results aren’t quite accurate (if you want really accurate results make sure your load is close to 0.01 without spikes)
change a flag USE on vlc @ /etc/portage/package.use and change the vlc USE flags. Take out one of your already flags. Then

# time emerge vlc --newuse

write down the time (t1). Afterwards repeat the same process without the ccache (write down the time - t2 ) . Finally reactivate the ccache as discussed in the previous paragraph and compare results(t3). My guess is that time values should be t1>t2>t3 if you haven’t installed vlc or t2>t3>t1 if you had.

CONSIDERATIONS!
DO NOT I SAY DO NOT COMPILE YOUR KERNEL WITH CCACHE. THIS IS BY DESIGN PROBLEMATIC (BUT ALSO BY DESIGN DISABLED). If you change your genkernel alias or manually edit the makefile of the kernel, be prepared for the worst. END OF STORY…

Leave a Comment

Name (required)

Mail (will not be published) (required)

Website

Comment