一. 动态调整内存
<domain> ... <memory unit='KiB'>4194304</memory> <currentMemory unit='KiB'>1048576</currentMemory> ... </domain>
- memory:在qemu命令中使用参数-m来设置的。表示虚拟机在启动阶段使用的内存。包括在启动或稍后热插拔时指定的可能的附加内存。
- currentMemory:通过libvirt调整balloon值的初始值是currentMemory。
说明:
- 在虚拟机启动后加载了内存balloon驱动后就开始对虚拟机内存进行热插拔,先设置内存为<currentMemory>大小,这个<currentMemory>qemu进程不知道,时记录在libvirt中的。然后根据需求对内存进行调整(balloon),调整的上限是<memory>,这个<memory>qemu进程是知道的,在虚拟机启动时使用了这个值。
- 要禁止memballoon设备,可以设置memballoon model=’none’
禁止内存气泡设备后,虚拟机内部看到的内存就是<memory>,也不能通过气泡进行调整。
# virsh list Id Name State ---------------------------------------------------- 19 nattest running # virsh dommemstat 19 actual 1048576 swap_in 0 swap_out 0 major_fault 166 minor_fault 122154 unused 2104012 available 2221280 usable 2049928 last_update 1589444988 rss 352284
- actual 1048576 当前使用
# virsh setmem 19 --size 1536000 # virsh dommemstat 19 actual 1536000 swap_in 0 swap_out 0 major_fault 166 minor_fault 122154 unused 2104012 available 2221280 usable 2049928 last_update 1589444988 rss 352284
调整完成之后, 不用重启可以直接 free 看到 调整前后的变化
二,动态调整CPU
<domain> ... <vcpu placement='static' current='4'>8</vcpu> <cputune> <vcpupin vcpu="0" cpuset="1-4,^2"/> <vcpupin vcpu="1" cpuset="0,1"/> <vcpupin vcpu="2" cpuset="2,3"/> <vcpupin vcpu="3" cpuset="0,4"/> </cputune> ... </domain>
# virsh vcpuinfo nattest VCPU: 0 CPU: 4 State: running CPU time: 4.0s CPU Affinity: -y-yy----------- VCPU: 1 CPU: 1 State: running CPU time: 2.2s CPU Affinity: yy-------------- VCPU: 2 CPU: 3 State: running CPU time: 2.0s CPU Affinity: --yy------------ VCPU: 3 CPU: 0 State: running CPU time: 3.1s CPU Affinity: y---y----------- # virsh setvcpus nattest --current 6 # virsh vcpuinfo nattest VCPU: 0 CPU: 3 State: running CPU time: 4.3s CPU Affinity: -y-yy----------- VCPU: 1 CPU: 1 State: running CPU time: 2.9s CPU Affinity: yy-------------- VCPU: 2 CPU: 2 State: running CPU time: 2.7s CPU Affinity: --yy------------ VCPU: 3 CPU: 0 State: running CPU time: 3.9s CPU Affinity: y---y----------- VCPU: 4 CPU: 6 State: running CPU time: 0.1s CPU Affinity: yyyyyyyyyyyyyyyy VCPU: 5 CPU: 10 State: running CPU Affinity: yyyyyyyyyyyyyyyy
- virsh setvcpus nattest –current 6 调整CPU数量
https://libvirt.org/formatdomain.html#elementsCPUAllocation
https://libvirt.org/formatdomain.html#elementsMemoryAllocation
评论前必须登录!
注册