Skip to content

virsh setmem: cannot set memory higher than max memory

Virtualizationtested on Ubuntu 24.04.5, QEMU 8.2.2, libvirt 10.0.0

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

Shut the VM down, raise the limit with setmaxmem, start the VM, then setmem up to the new limit.

Don't: Set the limit very high just in case. The guest plans for the maximum memory at boot.

▶
Break it yourself and find it – free
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.

Related error patterns

More