For the complete documentation index, see llms.txt. This page is also available as Markdown.

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 4

On 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: 16

Or check the number of available CPU cores on the system:

# sysctl hw.ncpu
hw.ncpu: 16

The 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.

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

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.

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:

  • -c Resume broken download

  • -t 3 Retry count 3

  • --max-threads=16 Set 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

Last updated