I have three VMs running on Red Hat Enterprise Linux with 8 GB RAM, each of the VMs has 3 GB allocated, and I also run a 512 MB VM. If we also consider the guest OS's memory usage (usually 1.5 GB due to a mandatory corporate-issued antivirus), this adds up to 11 GB of RAM. In order to be able to run all that stuff without grinding my computer to a halt, I use ZRAM with 7 GB of maximum memory usage. Most of the time I hardly have any trouble this way, but in return, my memory is usually very full, with about 700 MB of free physical RAM and roughly the same amount of free ZRAM.
What I have found from this setup, is that in order to successfully save a VM's state using
virt-manager's Save command (which translates to
managedsave), I must add some extra swap space, and when this happens my VM will save at about the rate at which the swap space is read, because it would seem as if the VM state saving algorithm is to copy blocks of guest memory to the host's memory and then save these blocks to hard disk, which means saving a VM's state requires some amount of extra memory. By trial and error I found the minimum extra virtual memory required to save my 3 GB VMs to be 1 GB, i.e. I must issue
swapon <pagefile> on a 1 GB file formatted as swap space, which leads me to believe that you need at least 30% of your VM's assigned memory available in order to save its state. Also, when I have enough ZRAM available but my main memory is almost full, I can see on GKrellm how my system is fumbling pages at full speed on in-memory swap space.
So, does anyone know exactly why does KVM-QEMU requires extra memory in order to save a VM's state?