Skip to main content.

Faster compiles with ccache and tmpfs

2013-10-02

Live demo in BSD Now Episode 005 | Originally written by TJ for bsdnow.tv | Last updated: 2015/04/05

NOTE: the author/maintainer of the tutorial(s) is no longer with the show, so the information below may be outdated or incorrect.

If you've used ports on any BSD system, you know that sometimes things take a while to compile. There are many factors involved, but the most important one is how fast the CPU of the system is. There are a few things you can do to speed up all your compiles though. For FreeBSD, this might include:

  • Using Clang/LLVM instead of GCC (this only applies to FreeBSD <10 where GCC is default)
  • Building ports in RAM instead of being bound by disk I/O
  • Using ccache to save time on things you've already compiled

Setting up ccache is pretty easy. First, install it from ports. If you're using binary packages, you obviously don't need ccache.

# cd /usr/ports/devel/ccache
# make install clean

Append a few lines to your make.conf like so:

# vi /etc/make.conf

Add the following:

CC=clang
CXX=clang++
CPP=clang-cpp
WRKDIRPREFIX=/ram
CCACHE_DIR=/var/tmp/ccache

Next, make the /ram directory and set a limit of how much RAM it can use. In this case I'll use ~2GB. Adjust for your needs.

# mkdir /ram
# echo 'none /ram tmpfs rw,size=2147483648 0 0' >> /etc/fstab
# mount /ram

Now all ports you build will be compiled entirely in RAM. You can check your ccache usage with:

# ccache -s

Latest News

New announcement

2017-05-25

We understand that Michael Dexter, Brad Davis, and George Rosamond think there should be more real news....

Two Year Anniversary

2015-08-08

We're quickly approaching our two-year anniversary, which will be on episode 105. To celebrate, we've created a unique t-shirt design, available for purchase until the end of August. Shirts will be shipped out around September 1st. Most of the proceeds will support the show, and specifically allow us to buy...

New discussion segment

2015-01-17

We're thinking about adding a new segment to the show where we discuss a topic that the listeners suggest. It's meant to be informative like a tutorial, but more of a "free discussion" format. If you have any subjects you want us to explore, or even just a good name...

How did you get into BSD?

2014-11-26

We've got a fun idea for the holidays this year: just like we ask during the interviews, we want to hear how all the viewers and listeners first got into BSD. Email us your story, either written or a video version, and we'll read and play some of them for...


Episode 258: OS Foundations

2018-08-08

Direct Download:MP3 AudioVideo This episode was brought to you by Headlines FreeBSD Foundation Update, July 2018 MESSAGE FROM THE EXECUTIVE DIRECTOR We’re in the middle of summer here, in Boulder, CO. While the days are typically hot, they can also be quite unpredictable. Thanks to the Rocky Mountains, waking up to 50-degree (~10...

Episode 257: Great NetBSD 8

2018-08-01

Direct Download:MP3 AudioVideo This episode was brought to you by Headlines NetBSD v8.0 Released The NetBSD Project is pleased to announce NetBSD 8.0, the sixteenth major release of the NetBSD operating system. This release brings stability improvements, hundreds of bug fixes, and many new features. Some highlights of the...

Episode 2^8: Because Computers

2018-07-25

Direct Download:MP3 AudioVideo This episode was brought to you by Win Celebrate our 256th episode with us. You can win a Mogics Power Bagel (not sponsored). To enter, go find the 4 episodes we did in December of 2017. In the opening, find the 4 letters in the bookshelf behind me. They...

Episode 255: What are you pointing at

2018-07-18

Direct Download:MP3 AudioVideo This episode was brought to you by Headlines What ZFS block pointers are and what's in them I've mentioned ZFS block pointers in the past; for example, when I wrote about some details of ZFS DVAs, I said that DVAs are embedded in block pointers. But I've never really...