8.5 Ports Build Tuning
FreeBSD Ports Multi-Threaded Compilation
To speed up compilation, you can configure multi-threaded compilation options to take advantage of multi-core processor performance.
Write the following content to the /etc/make.conf file; if it does not exist, touch to create the corresponding file.
FORCE_MAKE_JOBS=yes # Force enable parallel compilation
MAKE_JOBS_NUMBER=4 # Set the number of parallel compilation jobs to 4On Linux (such as Gentoo), -jX or -j(X+1) is generally used directly, where X is the number of cores.
4 represents the number of parallel compilation jobs for the processor (usually corresponding to the number of cores or threads).
You can check the number of CPU cores detected by the system using the following command:
# sysctl kern.smp.cpus
kern.smp.cpus: 16Or check the number of available CPU cores on the system:
# sysctl hw.ncpu
hw.ncpu: 16The output value can be used as the value for MAKE_JOBS_NUMBER.
Search for the Intel processor model plus ARK to navigate to the Intel official website to check the thread count.
FreeBSD Project. SMP -- symmetric multiprocessing kernel subsystem[EB/OL]. [2026-03-25]. https://man.freebsd.org/cgi/man.cgi?query=SMP&sektion=4. Documentation for kern.smp.cpus and hw.ncpu sysctl variables in the SMP subsystem.
Setting /tmp as a Memory File System
To improve read and write speeds for temporary files, you can mount the /tmp directory as a memory file system tmpfs.
Edit the /etc/fstab file and write the following line:
reboot to apply the changes.
References
FreeBSD Project. tmpfs -- in-memory file system[EB/OL]. [2026-03-25]. https://man.freebsd.org/cgi/man.cgi?query=tmpfs&sektion=4. Official technical specification for the in-memory file system tmpfs.
Using ccache for Compilation Caching
ccache is a compilation caching tool that can accelerate the process of repeated compilation.
Warning
Using ccache may cause compilation failures. It is only effective during repeated compilation; the first compilation will not be accelerated and may even be slower. It is a space-for-time tradeoff.
ccache3 is a commonly used version.
Installing ccache3
Install using pkg:
Install using Ports:
After installation, you can view the symlinks created by ccache:
Configuring ccache3
Configure ccache to enable compilation caching:
Modify the /etc/make.conf file and add the following line to enable ccache for accelerated compilation:
To prevent the cache from occupying too much disk space, it is recommended to set a maximum cache size limit.
Set the ccache compilation cache maximum to 10 GB:
After using it for a period of time, you can view ccache's statistics to understand the cache hit rate.
Display ccache statistics after compiling with Ports for a while:
Installing ccache4
ccache4 is a newer major version of ccache. The installation and configuration methods are the same as ccache3; only the package name is different.
Install using pkg:
Or install using Ports:
Configuring ccache4
The symlinks and /etc/make.conf configuration are the same as ccache3 and will not be repeated. The output format of ccache4 is slightly different:
Set the compilation cache maximum to 20 GB:
After compiling with Ports for a while, view the compilation cache:
Display ccache4's current configuration parameters:
References
For more detailed information and usage of ccache, please refer to the following resources.
FreeBSD Project. ccache-howto-freebsd.txt.in[EB/OL]. [2026-03-25]. https://github.com/freebsd/freebsd-ports/blob/main/devel/ccache/files/ccache-howto-freebsd.txt.in. Configuration guide for ccache in FreeBSD Ports, explaining how to enable cache acceleration during compilation.
FreeBSD Project. ccache - a fast C/C++ compiler cache[EB/OL]. [2026-03-25]. https://man.freebsd.org/cgi/man.cgi?query=ccache&sektion=1&n=1.
Multi-Threaded Downloading
To speed up the download of Ports source code, you can use multi-threaded download tools.
axel
axel is a lightweight multi-threaded download tool that can significantly improve download speeds.
Install using pkg:
Or install using Ports:
After installation, you need to configure the Ports framework to use axel as the download tool.
Create or edit the /etc/make.conf file and write the following lines:
wget2
Install using Ports:
Create or edit the /etc/make.conf file and write the following lines:
wget2 parameter descriptions:
-cResume broken download-t 3Retry count 3--max-threads=16Set the maximum concurrent download thread count to 16, default is 5
Tip
Many servers do not support multiple threads downloading simultaneously. This puts significant pressure on the server and may trigger countermeasures, such as adding the downloading IP to a blacklist.
References
FreeBSD Project. ports -- contributed applications[EB/OL]. [2026-03-25]. https://man.freebsd.org/cgi/man.cgi?query=ports&sektion=7. Official documentation for the Ports framework, including FETCH_CMD and BATCH parameter descriptions.
Last updated