[PVE 9/ZFS-Based VM/LXC Storage] Why Shouldn't I Disable Swap Inside Linux VMs?

Sep 1, 2022
516
194
53
42
I am aware that on bare metal Linux, or a non-ZFS-based Proxmox VE host, there are advantages to having swap enabled.

So, I'm asking specifically about using swap inside VMs stored as zVols on a thin-provisioned ZFS mirror pool. I have a 4 GiB Debian 13 that I've never seen use more than 1.2 GiB of its allotted 4 GiB of RAM, to the point I might restrict it to 2 GiB soon. Debian 13's default ext4 partition scheme sets up a 2 GiB swap partition.

But, I've seen this VM use swap, even only 256 KiB.

I don't really like this. A zVol backed paravirtualized SCSI virtual disk is always going to be slower than accessing RAM directly, and I gave it it 4 GiB because it's an I/O heavy VM. I don't want to introduce avoidable latency.

So, question: What reasons should I keep this config, where an I/O-intensive VM with enough RAM to never run out of memory is swapping into a zVol-backed virtual disk? What are the downsides of turning off swap in this setup?
Thanks. :)
 
I am aware that on bare metal Linux, or a non-ZFS-based Proxmox VE host, there are advantages to having swap enabled.
Swap inside (Linux) VMs is just as advantageous. Having ZFS (or BTRFS) underneath those VMs is not ideal, but should not be a problem (with enterprise drives) unless they start thrashing, which is a problem of and in itself.
Writing every once in a while to swap is good for performance and througput and memory defragmentation. Continuously writing and also reading swap is called thrashing and very bad.
Of course, running applications with not enough real memory and trying to use swap instead is a terrible idea regardless of virtualization and/or ZFS. And Proxmox does not really support memory over-commitment.
 
Last edited:
  • Like
Reactions: Johannes S
  • Like
Reactions: leesteken