How to limit VM resource usage with rctl


When trying to guarantee a minimum CPU percentage of CPU for FreeBSD itself (from a few VMs), I found that though FreeBSD and latest vm-bhyve have the capability to do this, it’s not enabled by default.

The following steps described here worked for me in FreeBSD 11.1 / vm-bhyve 1.1.8:

  1. Check whether RACCT / RCTL are built into FreeBSD kernel
    • GENERIC kernel since FreeBSD 10.2 should already have this
    • Can be found with sysctl kern.racct.enable
    • See this post if you have to rebuild kernel for RACCT
  2. Enable RACCT by adding kern.racct.enable=1 in loader.conf and reboot
    • You should see kern.racct.enable.1 in sysctl kern.racct.enable output
  3. Set resource limits with rctl. You can either use options provided in vm-bhyve, or call rctl manually.
    • This PR shows the actual commands vm-bhyve uses.
    • rctl can do much more than limiting CPU usage of a bhyve process, see man rctl for more rctl options