FreeBSD caches content to RAM by default if the boot drive is ZFS, which greatly improves performance, especially when used as a server. The maximum memory used for caching in FreeBSD is determined by a variable in the kernel known as vfs.zfs.arc_max. In my case, with FreeBSD x64 installed on a machine with 4GB RAM, the default value was around 2.8GB. You can determine the current value by:

$ sysctl -a | grep vfs.zfs.arc_max

Note that the output is in bytes, so you need to convert it to other format that you can easily understand, such as GB. Once you have the current value, you can easily decide how much RAM to reserve, so that the machine will not run out of memory, keeping into account the memory used by the OS and apps. htop has a simple memory bar that will show how much RAM is used by the OS and apps. To set limit immediately:

$ sudo sysctl vfs.zfs.arc_max=yourintendedvalue

Replace yourintendedvalue with the value you want, in bytes. The change will take effect immediately, but it will be lost after a reboot. To make the change permanent, add a line to the bottom of /boot/loader.conf:

$ sudo nano /boot/loader.conf
vfs.zfs.arc_max=yourintendedvalue

Leave a Reply

Your email address will not be published. Required fields are marked *