When configuring a Xen virtual machine you can specific the initial memory the VM will use as well the maximum memory the machine cn be assigned with. The Xen management interface gives the ability to change the memory of the VM on-the-fly, without restarting any daemons or the VM. In the following example the memory is dropped down from 1G to 768M using the ‘xm’ command with the ‘mem-set’ option:
# xm list node1 Name ID Mem(MiB) VCPUs State Time(s) node1 1 1023 2 -b---- 115.5 # xm mem-set node1 768 # xm list node1 Name ID Mem(MiB) VCPUs State Time(s) node1 1 767 2 -b---- 115.7
The maximum memory the VM will be able to get is 1024M as this is the maxmem definition in its configuration file.
The Xen management interface enables very easy the to pin specific CPUs to VCPUs without affecting any running VMs. In the following example core 2 is mapped to VCPU0 and core 3 is mapped to VCPU1. The VM will now exclusively use these cores for each of the VCPUs rather than switching depending on workload etc.
# xm vcpu-list node1 Name ID VCPUs CPU State Time(s) CPU Affinity node1 1 0 3 -b- 61.1 2-3 node1 1 1 2 -b- 54.4 2-3 # xm vcpu-pin node1 0 2 # xm vcpu-pin node1 1 3 # xm vcpu-list node1 Name ID VCPUs CPU State Time(s) CPU Affinity node1 1 0 2 -b- 61.1 2 node1 1 1 3 -b- 54.4 3
One more very helpful use of the management interface is that it can trun on and off the VCPUs on a VM. Of course, the last one left on can’t be turned off and the most you can turn on are as the number defined in the configuration file.
# xm vcpu-set node1 1 # xm vcpu-list node1 Name ID VCPUs CPU State Time(s) CPU Affinity node1 1 0 2 -b- 61.3 2 node1 1 1 - --p 54.4 3 # xm vcpu-set node1 2 # xm vcpu-list node1 Name ID VCPUs CPU State Time(s) CPU Affinity node1 1 0 2 -b- 61.4 2 node1 1 1 3 -b- 54.5 3
All the commands above worked perfectly on a paravirtualized Scientific Linux 5.2 VM.
EDIT: The same commands can be used for Domain-0, the machine that hosts the VMs.
2 thoughts on “Live memory and CPU tunning on Xen virtual machine”
Pingback: Mudar CPU/RAM sem reiniciar a VM
You solved all my questions – thanks a lot