Virsh setmem

From wikieduonline
Revision as of 13:52, 23 December 2019 by Welcome (talk | contribs)
Jump to navigation Jump to search

virsh setmem YOUR_VM_NAME size [[--config] [--live] | [--current]][1][2]

Change the memory allocation for a guest domain/Virtual Machine. Operation is not synchronously, as with virsh setvcpus then the fact that the virsh setmem program returned, may not mean the action is complete and you must poll periodically to detect that the guest completed the operation: virsh dominfo YOUR_VM_NAME | grep memory

If --config is specified, affect the next boot of a persistent guest.
If --live is specified, perform a memory balloon of a running 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.

virsh dominfo YOUR_VM_NAME  | grep memory
Max memory:     1048576 KiB
Used memory:    1048576 KiB

# virsh setmem YOUR_VM_NAME 500M           

Example setting showing up error setting up memory higher that max memory:

# virsh setmem YOUR_VM_NAME 8G 
error: invalid argument: cannot set memory higher than max memory          
# virsh dominfo YOUR_VM_NAME  | grep memory
Max memory:     1048576 KiB
Used memory:    512000 KiB
# ssh fedora-27 free -m
                total        used        free      shared  buff/cache   available
Mem:            467          50         327           0          88         285
Swap:          1535          51        1484


See also

  • https://linux.die.net/man/1/virsh
  • https://rentry.co/s3p8o
  • Advertising: