QEMU KVM Libvirt手册(8): 半虚拟化设备virtio

KVM本身并不提供半虚拟化功能,是通过virtio来实现的

The benefits of virtio drivers are of lower overhead and higher performance.

Memory Ballooning (virtio_balloon)

memory ballooning可以动态调整guest的内存的大小

如果有-m参数,则向更大的内存调整时无效的,但是可以往小的里面调整

我们首先ssh到guest里面

ip netns exec qrouter-26a45e0e-a58a-443b-a972-d62c0c5a1323 ssh -i openstack.pem ubuntu@192.168.0.35

在虚拟机里面看内存的大小

ubuntu@testinject19:~$ free
             total       used       free     shared    buffers     cached
Mem:       2051748     478276    1573472          0      46620     345908
-/+ buffers/cache:      85748    1966000
Swap:            0          0          0

在Monitor上看balloon的大小

root:/home/cliu8# virsh qemu-monitor-command instance-00000024 --hmp "info balloon"
balloon: actual=2048

我们试图往大里调整

root:/home/cliu8# virsh qemu-monitor-command instance-00000024 --hmp "balloon 4096"

发现无效

root:/home/cliu8# virsh qemu-monitor-command instance-00000024 --hmp "info balloon"
balloon: actual=2048

ubuntu@testinject19:~$ free
             total       used       free     shared    buffers     cached
Mem:       2051748     478276    1573472          0      46628     345920
-/+ buffers/cache:      85728    1966020
Swap:            0          0          0

我们往小里调整内存

root:/home/cliu8# virsh qemu-monitor-command instance-00000024 --hmp "balloon 1024"

发现生效了

root:/home/cliu8# virsh qemu-monitor-command instance-00000024 --hmp "info balloon"
balloon: actual=1024

ubuntu@testinject19:~$ free
             total       used       free     shared    buffers     cached
Mem:       1003172     470796     532376          0      46636     345920
-/+ buffers/cache:      78240     924932
Swap:            0          0          0

有了balloon,如果guest需要更多的RAM,则可以给它增加一些内存。如果guest不需要那么多内存,可以通过balloon从中拿出一部分内存。这个过程,不需要启停虚拟机。

balloon driver像是一个特殊的process,运行在guest机器上,它可以扩大自己的内存,使得其他的应用程序的内存减少,也可以缩小内存,使得其他的应用程序内存增加。

balloon-expanded

balloon-shrink

guest中的balloon driver通过virtio channel和host进行交互,接收host发来的命令,比如发来的命令式减少内存,则balloon driver就扩大它的内存占有量。

然后balloon driver将自己占有的内存交回给host,使得host有了更多的内存。

balloon-chunk

对于libvirt而言,有currentMemory和maxMemory两种概念,maxMemory就是-m参数设定的,currentMemory就是balloon设定的。

Para-virtualized network interface cards (virtio_net)

-netdev tap,fd=32,id=hostnet0,vhost=on,vhostfd=37 
-device virtio-net-pci,netdev=hostnet0,id=net0,mac=fa:16:3e:d1:2d:99,bus=pci.0,addr=0x3

Para-virtualized block devices (virtio_blk)

-drive file=/var/lib/nova/instances/1f8e6f7e-5a70-4780-89c1-464dc0e7f308/disk,if=none,id=drive-virtio-disk0,format=qcow2,cache=none 
-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1

转载于:https://www.cnblogs.com/Ansing/p/5844466.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值