Menu

FreeBSD Tuning

This page contains information on tuning FreeBSD hosts connected at speeds of 1Gbps or higher.

Note: This information is quite old and likely out of date. If you are currently running FreeBSD and know what needs to be updated, please contact us. 

Basic tuning configuration

Here are the recommended settings for /etc/sysctl.conf. Some of these are the default settings, but are included in case someone changed the defaults on your system. Explanations are below.

   # set to at least 16MB for 10GE hosts
kern.ipc.maxsockbuf=16777216
# set autotuning maximum to at least 16MB too
net.inet.tcp.sendbuf_max=16777216
net.inet.tcp.recvbuf_max=16777216
# enable send/recv autotuning
net.inet.tcp.sendbuf_auto=1
net.inet.tcp.recvbuf_auto=1
# increase autotuning step size
net.inet.tcp.sendbuf_inc=16384
net.inet.tcp.recvbuf_inc=524288
# set this on test/measurement hosts
net.inet.tcp.hostcache.expire=1

Advanced congestion control in FreeBSD

FreeBSD supports TCP autotuning and advanced congestion control algorithms in all currently-supported releases. You can check which are available in the running kernel using:

  sysctl net.inet.tcp.cc.available

To make additional algorithms available in the kernel, the appropriate module must be loaded. The congestion control modules are in /boot/kernel and begin with cc_ - they can be listed with the following command:

  ls /boot/kernel/cc_* | grep -v symbols

To load a particular congestion control algorithm (for example htcp) you can use:

  kldload cc_htcp

and you will then be able to set the congestion control algorithm using this:

  sysctl net.inet.tcp.cc.algorithm=htcp

FreeBSD 13 will support the BBR congestion control algorithm when it is released (e.g. as of Oct 2019 it is being tested via FreeBSD-current). More information on FreeBSD is available here.

Enabling congestion control algorithms at boot time

Depending how your kernel is built, you may not have the algorithm you want available by default at boot time, and will need to load the driver during the boot process. To to this add the following to /boot/loader.conf:

  cc_htcp_load="YES"

The htcp algorithm will then be loaded at boot time, and will be enabled when sysctl.conf is processed at boot time and the net.inet.tcp.cc.algorithm=htcp variable is set.

Other information

By default, FreeBSD caches connection details such as the slow start threshold and the congestion windows size from the previous connection to the same host for 1 hour. While this is a good idea for a web server, it makes it hard to do network throughput testing, as 1 large congestion event will throttle performance for the next hour. To reduce this effect, set hostcache.expire to 1.

This will still cache values for 5 minutes, for reasons described in this article from the Centre for Advanced Internet Architectures (CAIA) at Swinburne University in Australia. This article has a lot of other good tuning information for FreeBSD too.