[root@UA-KVM1 ~]# tail -f /var/log/messages
Dec 16 13:01:01 UA-KVM1 systemd: Starting Session 2 of user root.
Dec 16 13:19:08 UA-KVM1 kernel: Unregister pv shared memory for cpu 1
Dec 16 13:19:08 UA-KVM1 kernel: smpboot: CPU 1 is now offline
[root@UA-KVM1 ~]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 2
On-line CPU(s) list: 0
Off-line CPU(s) list: 1
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 44
Model name: Westmere E56xx/L56xx/X56xx (Nehalem-C)
Stepping: 1
CPU MHz: 2594.058
BogoMIPS: 5188.11
Hypervisor vendor: KVM
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 4096K
NUMA node0 CPU(s): 0
[root@UA-KVM1 ~]#
注意:
在KVM物理主机中过,你依然会看到两个vCPU呗分配给虚拟机UAKVM2,只有重启VM才会生效。
[root@UA-HA ~]# virsh dominfo UAKVM2
Id: 38
Name: UAKVM2
UUID: 6013be3b-08f9-4827-83fb-390bd5a86de6
OS Type: hvm
State: running
CPU(s): 2
CPU time: 90.4s
Max memory: 1048576 KiB
Used memory: 1048576 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: selinux
Security DOI: 0
Security label: system_u:system_r:svirt_t:s0:c709,c868 (permissive)
[root@UA-HA ~]#
关闭UAKVM2 KVM虚拟机并验证
[root@UA-HA ~]# virsh destroy UAKVM2
Domain UAKVM2 destroyed
[root@UA-HA ~]# virsh dominfo UAKVM2
Id: -
Name: UAKVM2
UUID: 6013be3b-08f9-4827-83fb-390bd5a86de6
OS Type: hvm
State: shut off
CPU(s): 1
Max memory: 1048576 KiB
Used memory: 0 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: selinux
Security DOI: 0
[root@UA-HA ~]#
此时可以看到vCPU被修改成1个。
如果尝试添加比预分配更多的vCPU会看到如下错误信息error: invalid argument: requested vcpus is greater than max allowable vcpus for the domain
[root@UA-HA ~]# virsh setvcpus UAKVM2 3
error: invalid argument: requested vcpus is greater than max allowable vcpus for the domain: 3 > 2
[root@UA-HA ~]#
[root@UA-HA ~]# virsh list
Id Name State
----------------------------------------------------
39 UAKVM2 running
[root@UA-HA ~]# virsh shutdown UAKVM2
Domain UAKVM2 is being shutdown
[root@UA-HA ~]#
编辑VM配置类似如下,这里将最大vCPU数量从2修改成4:
<vcpu placement='static' currtne='1'>2</vcpu>
修改成
<vcpu placement='static' currtne='1'>4</vcpu>
vCPU XML 格式:
<vcpu placement='static' current='N'>M</vcpu>
这里N时当前激活的CPU数量,而M是CPU的最大数量
启动KVM虚拟机UAKVM2
[root@UA-HA ~]# virsh start UAKVM2
Domain UAKVM2 started
[root@UA-HA ~]#
验证UAKVM2虚拟机的vCPU信息
[root@UA-HA ~]# virsh vcpuinfo UAKVM2
VCPU: 0
CPU: 1
State: running
CPU time: 24.0s
CPU Affinity: yy
[root@UA-HA ~]#