1、KVM内存气球技术
KVM的内存气球技术使得可以在虚拟机中按照需要调整的内存大小,提升内存的利用率。使用的时候,默认情况是需要安装virt balloon的驱动,内核开启CONFIG_VIRTIO_BALLOON。CentOS7默认已经开启了此选项,并且也安装了virtballoon驱动。
查看.xml文件,如下可以看到balloon是支持的
<memballoon model=‘virtio‘> <address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x07‘ function=‘0x0‘/> </memballoon>
balloon有两种类型:
膨胀:虚拟机的内存被拿掉给宿主机
压缩:宿主机的内存还给虚拟机
气球技术最大优点是内存可以超用,缺点是可能造成内存不够用的而影响性能
2、CentOS7下气球技术的演示
a)查看虚拟机的信息
[root@kvm02 ~]# virsh list --all Id Name State ---------------------------------------------------- 1 CentOS-7.3-x86_64.raw running
b)查看当前宿主机下的虚拟机的内存大小
[root@kvm02 ~]# virsh qemu-monitor-command CentOS-7.3-x86_64.raw --hmp --cmd balloon 1024 [root@kvm02 ~]# virsh qemu-monitor-command CentOS-7.3-x86_64.raw --hmp --cmd info balloon balloon: actual=1024 在虚拟机中查看内存大小 [root@localhost ~]# free -m total used free shared buff/cache available Mem: 881 116 647 8 117 573 Swap: 1023 0 1023
c)调整限制内存为512M
[root@kvm02 ~]# virsh qemu-monitor-command CentOS-7.3-x86_64.raw --hmp --cmd balloon 512 [root@localhost ~]# free -m total used free shared buff/cache available Mem: 369 116 135 8 117 62 Swap: 1023 0 1023
说明:windows下也支持内存气球技术,可以参考肖力大哥的《深度实践KVM》
本文出自 “冰冻vs西瓜” 博客,请务必保留此出处http://molewan.blog.51cto.com/287340/1901841
原文:http://molewan.blog.51cto.com/287340/1901841