Changing a VM's memory live works downwards at once. Upwards, libvirt stops at the limit, which can only be moved while the VM is off.
Symptom
virsh setmem web1 1024M --live virsh setmem web1 2G --live error: invalid argument: cannot set memory higher than max memory
Going back to 1024 MB works, 2 GB does not.
Diagnosis
The guest lost RAM before without a reboot – setmem works live, but only within the limit.
total used free shared buff/cache available
Mem: 961 291 625 1 186 669
total used free shared buff/cache available
Mem: 705 286 374 1 186 419
Causes
maxMemoryThe domain's upper limit
Every domain has an upper limit. setmem only moves the current value below it; the limit itself is part of the definition.
--liveThe limit does not change while running
The upper limit (setmaxmem) can only be changed while the VM is shut off.
Fix
Don't: Set the limit very high just in case. The guest plans for the maximum memory at boot.
KVM hands-on, Day 9: the guest – changing memory live, virtiofs, the agent.
Go to day 9 →
FAQ
Does the guest see the change immediately?
Yes. In the course, free shows 256 MB less right after setmem --live, without a reboot.
Where do I set the upper limit?
With virsh setmaxmem while the VM is off, or in the memory element of the domain XML.