bhyve Linux VM on ZFS causing swap to max out

So I currently have a Linux VM I remote into via VNC running on my freebsd server. It's just mainly for web browsing and email - nothing crazy. The VMs disk is a block device on zfs.

Everything works fine for the most part, but over time the swap usage of the freebsd server generally climbs until I'm getting super close to the limit (4 GB). At that point, the system starts killing random processes and the VM becomes pretty slow. Meanwhile the server is using less than half of its available RAM o_O

The only way to fix it is to shut down the VM and destroy it, after which the swap usage instantly drops to a few hundred MB.

From reading online, it seems this is something to do with ZFS's caching (ARC?) not playing nicely with the VMs disk. I've been unable to find clear instructions on how I'm supposed to properly configure this though.

Could someone help me out here? Any help would be greatly appreciated.
 
From reading online, it seems this is something to do with ZFS's caching (ARC?) not playing nicely with the VMs disk. I've been unable to find clear instructions on how I'm supposed to properly configure this though.
Only one setting is important to remember, vfs.zfs.arc_max. That sysctl(8) controls the upper limit of the ARC size. Configure this so the VM's memory plus ARC doesn't exceed the amount of RAM you have in the machine.
 
Thanks!
Okay, so my `vfs.zfs.arc_max` is currently set to 15484866560, which is approximately the same as the amount of RAM in my server minus ~ 1GB (16 GB). My VM's RAM is set to 8 GB. Does that mean I should just set `vfs.zfs.arc_max` to 7742433280?

Still curious why `htop` shows a lot of free RAM though while the swap is almost full. Is that because it doesn't account for the RAM the VM has taken?
 
Back
Top