fasterdata.es.netfasterdata.es.netESnet Network Performance Knowledge Base

FreeBSD Tuning

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

FreeBSD added TCP autotuning in version 7.0, and better congestion control algorithms (cubic and HTCP) in version 8.2.

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
# turn off inflight limiting
net.inet.tcp.inflight.enable=0
# set this on test/measurement hosts
net.inet.tcp.hostcache.expire=1

Starting with FreeBSD 8.2, cubic and htcp are supported. You can check which are available using:

  net.inet.tcp.cc.available

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

  net.inet.tcp.cc.algorithm=htcp

Depending how your kernel is built, you may not have htcp/cubic by default, and will need to load the driver. To to this add 'cc_cubic_load="YES"' to /boot/loader.conf and reboot, or do a 'kldload cc_cubic'.

FreeBSD's TCP has something called inflight limiting turned on by default. This is good for modem connections, but can be detrimental to TCP throughput in some high-speed situations. If you want "normal" TCP Reno-like behavior, set inflight.enable to 0.

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. They also have a H-TCP patch for FreeBSD 7.X that works great.

FreeBSD and IPV6

Our testing has shown that on end-to-end 10G paths, IPV6 appears to be about 40% slower than IPV4 on FreeBSD 7.3, and 20% slower on FreeBSD 8.2. This is a known FreeBSD issue, and will be addressed in a future release.