As with CPUs, the possibility to add memory on the fly is an added value in mission-critical environments where downtime can literally cost a company millions of Euros.
The recipe presented here is quite simple, similar to the one on CPUs. Here, your guest needs to be prepared to use this functionality as well.
If you want to be able to add memory on the fly to a guest, it must be configured to support it. As with the CPU, this has to be activated. There are three ways to do this:
maxmem
option, as follows:--memory 2G,maxmemory=4G
virsh
command, as follows:~]# virsh setmaxmem --domain <guestname> --size <max mem> --live
~]# virsh edit <guestname>
Of course, the latter 2 option requires you to shut down the guest, which is not always possible in production environments.
Ensure that the guests' XML configuration files contain the following elements with the subsequent attributes:
<domain type='kvm'> ... <memory unit='KiB'>4194304</memory> <currentMemory unit='KiB'>2097152</currentMemory> ... </domain>
Let's increase the guest's memory.
On the KVM host, perform the following steps:
~]# virsh dumpxml srv00002 |grep -i memory <memory unit='KiB'>4194304</memory> <currentMemory unit='KiB'>4194304</currentMemory>
~]# virsh setmem --domain <guestname> --size <memory> --live
On the KVM guest, perform the following: