KVM virsh setmem (memory allocation) example
setmem domain size [[--config] [--live] | [--current]]
Change the memory allocation for a guest domain. If --live
is specified, perform a memory balloon of a running guest. If --config
is specified, affect the next boot of a persistent guest. If --current
is specified, affect the current guest state. Both --live
and --config
flags may be given, but --current
is exclusive. If no flag is specified, behavior is different depending on hypervisor.
size
is a scaled integer; it defaults to kibibytes (blocks of 1024 bytes) unless you provide a suffix (and the older option name --kilobytes
is available as a deprecated synonym) . Libvirt rounds up to the nearest kibibyte. Some hypervisors require a larger granularity than KiB, and requests that are not an even multiple will be rounded up. For example, vSphere/ESX rounds the parameter up to mebibytes (1024 kibibytes).
For Xen, you can only adjust the memory of a running domain if the domain is paravirtualized or running the PV balloon driver.
For LXC, the value being set is the cgroups value for limit_in_bytes
or the maximum amount of user memory (including file cache). When viewing memory inside the container, this is the /proc/meminfo "MemTotal" value. When viewing the value from the host, use the virsh memtune
command. In order to view the current memory in use and the maximum value allowed to set memory, use the virsh dominfo
command.