Pazartesi, Kasım 4, 2024

Configure Guest Domain Memory Usage With Virsh

yüksek çözünürlüklü libvirt virtualization api logosu

virsh provides Linux System Administrators with the ability to dynamically scale allocated memory to virtual guests during runtime.

# virsh dommemstat mySQL01
actual 2097152
rss 903040

dommemstat shows that the domain web-server has a memory allocation limitof 2097152 kB and is currently using 903040 kB. You can confirm this with ps.

# ps -C qemu-kvm -o rss,cmd
  RSS CMD
903040 /usr/bin/qemu-kvm -name mySQL01 -S -M pc-1.2 -enable-kvm -m 2048 -smp

The memory allocation limit is set with setmaxmem and can only be performed whilst the domain is inactive.

# virsh setmaxmem mySQL01 1048576 --config

By passing setmaxmem the config option the memory allocation limit iswritten to the virsh configuration file.

The current memory allocation for a guest domain is set with setmem.

# virsh setmem mySQL01 786432 --config --live

When passing setmem the live option, a memory balloon is performed on the running guest and the change happens instantly. This can be verified with dominfo.

# virsh dominfo mySQL01
Id:             1
Name:           mySQL01
UUID:           a1a0se38-20ff-134b-a0af-2bbc4e4ce167
OS Type:        hvm
State:          running
CPU(s):         4
CPU time:       31.9s
Max memory:     1048576 KiB
Used memory:    786432 KiB
Persistent:     yes
Autostart:      disable
Managed save:   no
Security model: selinux
Security DOI:   0
Security label: system_u:system_r:svirt_t:s0:c782,c903 (enforcing)