码迷,mamicode.com
首页 > 其他好文 > 详细

kvm半虚拟化驱动

时间:2015-10-29 00:53:09      阅读:2061      评论:0      收藏:0      [点我收藏+]

标签:kvm   虚拟化   半虚拟化   

 

半虚拟化驱动

host:宿主机(物理机),guest:客户机(虚拟机)

1.使用virtio驱动

linux中的virtio驱动

linux内核一般都自带virtio模块

内核配置文件与virtio相关配置

[root@desktop0 ~]# grep VIRTIO_ /boot/config-3.10.0-123.el7.x86_64

CONFIG_VIRTIO_BLK=m

CONFIG_VIRTIO_NET=m

CONFIG_VIRTIO_CONSOLE=m

CONFIG_VIRTIO_PCI=m

CONFIG_VIRTIO_BALLOON=m

# CONFIG_VIRTIO_MMIO is not set

[root@desktop0 ~]#

查看virtio驱动

[root@foundation0 images]# find/lib/modules/3.10.0-123.el7.x86_64/ -name "virtio*.ko"

/lib/modules/3.10.0-123.el7.x86_64/kernel/drivers/block/virtio_blk.ko

/lib/modules/3.10.0-123.el7.x86_64/kernel/drivers/char/hw_random/virtio-rng.ko

/lib/modules/3.10.0-123.el7.x86_64/kernel/drivers/char/virtio_console.ko

/lib/modules/3.10.0-123.el7.x86_64/kernel/drivers/net/virtio_net.ko

/lib/modules/3.10.0-123.el7.x86_64/kernel/drivers/scsi/virtio_scsi.ko

/lib/modules/3.10.0-123.el7.x86_64/kernel/drivers/virtio/virtio.ko

/lib/modules/3.10.0-123.el7.x86_64/kernel/drivers/virtio/virtio_balloon.ko

/lib/modules/3.10.0-123.el7.x86_64/kernel/drivers/virtio/virtio_pci.ko

/lib/modules/3.10.0-123.el7.x86_64/kernel/drivers/virtio/virtio_ring.ko

[root@foundation0 images]#

查看已加载的virtio模块

[root@desktop0 ~]# lsmod |grep virtio

virtio_balloon         13530 0

virtio_blk             18329  2

virtio_net             28059  0

virtio_pci             17725  0

virtio_ring            21011  4virtio_blk,virtio_net,virtio_pci,virtio_balloon

virtio                 14187  4virtio_blk,virtio_net,virtio_pci,virtio_balloon

windows中的virtio驱动没写完

[root@foundation0 /]# yum -y installvirto-win

Loaded plugins: langpacks, product-id,subscription-manager

This system is not registered to Red HatSubscription Management. You can use subscription-manager to register.

rhel-dvd                                                | 4.1 kB     00:00    

rht-ext                                                  | 2.9 kB     00:00    

No package virto-win available.

Error: Nothing to do

[root@foundation0 /]# rpm -q virtio-win

package virtio-win is not installed

[root@foundation0 /]# ls/usr/share/virt-win/

ls: cannot access /usr/share/virt-win/: Nosuch file or directory

 

2.virtio_balloon

ballooning:内存的ballooning(气球)技术可以在guest运行时动态地调整它所占用的host内存资源,不需要关机。但需要手动调整。

如下图,正方形里的内存是guest的,ballooning技术形象地在guest占用的内存中引入气球(balloon)概念,气球中的内存可供host使用(不能被guest访问或使用)。

guest空闲,但host内存不够时,气球膨胀,将guest内存分给host.

guest繁忙,host空闲时,气球放气变小,将气球里的内存还给guest.

技术分享

查看balloon设备

[root@desktop0 ~]# lspci

00:00.0 Host bridge: Intel Corporation440FX - 82441FX PMC [Natoma] (rev 02)

00:01.0 ISA bridge: Intel Corporation82371SB PIIX3 ISA [Natoma/Triton II]

00:01.1 IDE interface: Intel Corporation82371SB PIIX3 IDE [Natoma/Triton II]

00:01.2 USB controller: Intel Corporation82371SB PIIX3 USB [Natoma/Triton II] (rev 01)

00:01.3 Bridge: Intel Corporation82371AB/EB/MB PIIX4 ACPI (rev 03)

00:02.0 VGA compatible controller: Red Hat,Inc. QXL paravirtual graphic card (rev 04)

00:03.0 Ethernet controller: Red Hat, IncVirtio network device

00:04.0 Ethernet controller: Red Hat, IncVirtio network device

00:05.0 Ethernet controller: Red Hat, IncVirtio network device

00:06.0 SCSI storage controller: Red Hat,Inc Virtio block device

00:07.0 SCSI storage controller: Red Hat,Inc Virtio block device

00:08.0Unclassified device [00ff]: Red Hat, Inc Virtio memory balloon

[root@desktop0 ~]#

[root@desktop0~]# lsmod |grep virtio

virtio_balloon         13530 0

virtio_blk             18329  2

virtio_net             28059  0

virtio_pci             17725  0

virtio_ring            21011  4 virtio_blk,virtio_net,virtio_pci,virtio_balloon

virtio                 14187  4 virtio_blk,virtio_net,virtio_pci,virtio_balloon

[root@desktop0 ~]#

[root@desktop0~]# lspci -s 00:08.0 -v

00:08.0 Unclassified device [00ff]: RedHat, Inc Virtio memory balloon

         Subsystem:Red Hat, Inc Device 0005

         PhysicalSlot: 8

         Flags:bus master, fast devsel, latency 0, IRQ 11

         I/Oports at c120 [size=32]

         Kernel driver in use: virtio-pci

 [root@desktop0~]#

查看内存使用情况

[root@desktop0~]# free -m

             total      used       free     shared   buffers     cached

Mem:     1841        704      1137         16          0        286

-/+ buffers/cache:        416       1424

Swap:            0          0          0

[root@desktop0 ~]#

下面将内存设置为1024M

技术分享

[root@desktop0 ~]# free -m

            total       used       free    shared    buffers    cached

Mem:      817        703        113         16          0        286

-/+ buffers/cache:        416        400

Swap:            0          0          0

[root@desktop0 ~]#

 

3.virtio_net

使用virtio_net半虚拟化驱动,可以提高网络吞吐量和降低网络延迟,使guest拥有和host一样的原生网卡网络性能。

guest中查看virtio网卡使用情况

[root@desktop0 ~]# grep VIRTIO_ /boot/config-3.10.0-123.el7.x86_64

CONFIG_VIRTIO_BLK=m

CONFIG_VIRTIO_NET=m

CONFIG_VIRTIO_CONSOLE=m

CONFIG_VIRTIO_PCI=m

CONFIG_VIRTIO_BALLOON=m

# CONFIG_VIRTIO_MMIO is not set

[root@desktop0 ~]#

[root@desktop0 ~]# lspci

00:00.0 Host bridge: Intel Corporation440FX - 82441FX PMC [Natoma] (rev 02)

00:01.0 ISA bridge: Intel Corporation82371SB PIIX3 ISA [Natoma/Triton II]

00:01.1 IDE interface: Intel Corporation82371SB PIIX3 IDE [Natoma/Triton II]

00:01.2 USB controller: Intel Corporation82371SB PIIX3 USB [Natoma/Triton II] (rev 01)

00:01.3 Bridge: Intel Corporation82371AB/EB/MB PIIX4 ACPI (rev 03)

00:02.0 VGA compatible controller: Red Hat,Inc. QXL paravirtual graphic card (rev 04)

00:03.0Ethernet controller: Red Hat, Inc Virtio network device

00:04.0Ethernet controller: Red Hat, Inc Virtio network device

00:05.0Ethernet controller: Red Hat, Inc Virtio network device

 [root@desktop0~]# lspci -vv -s 00:03.0

00:03.0 Ethernet controller: Red Hat, IncVirtio network device

         Subsystem:Red Hat, Inc Device 0001

         PhysicalSlot: 3

         Control:I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+FastB2B- DisINTx+

         Status:Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort-<MAbort- >SERR- <PERR- INTx-

         Latency:0

         Interrupt:pin A routed to IRQ 10

         Region0: I/O ports at c0c0 [size=32]

         Region1: Memory at fc0d2000 (32-bit, non-prefetchable) [size=4K]

         ExpansionROM at fc000000 [disabled] [size=256K]

         Capabilities:[

[root@desktop0 ~]# lsmod |grep virtio

virtio_balloon         13530 0

virtio_blk             18329  2

virtio_net             28059  0

 [root@desktop0~]#

[root@desktop0~]# ethtool -i eth0

driver:virtio_net

version: 1.0.0

firmware-version:

bus-info: 0000:00:03.0

supports-statistics: no

supports-test: no

supports-eeprom-access: no

supports-register-dump: no

supports-priv-flags: no

[root@desktop0~]# ifconfig eth0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

       inet 172.25.0.10  netmask 255.255.255.0  broadcast 172.25.0.255

[root@desktop0~]# ping 172.25.0.250 -c 1

PING 172.25.0.250 (172.25.0.250) 56(84)bytes of data.

64bytes from 172.25.0.250: icmp_seq=1 ttl=64 time=0.304 ms

--- 172.25.0.250 ping statistics ---

1 packets transmitted, 1 received, 0%packet loss, time 0ms

rtt min/avg/max/mdev =0.304/0.304/0.304/0.000 ms

[root@desktop0 ~]#

host闭关TSOGSO,可使半虚拟化网络驱动的性能更加优化,其中eno16777736是建立bridgeguest使用的网络接口

[root@foundation0images]# ethtool  -k eno16777736

Features for eno16777736:

rx-checksumming: off

tx-checksumming: on

         tx-checksum-ipv4:off [fixed]

         tx-checksum-ip-generic:on

         tx-checksum-ipv6:off [fixed]

         tx-checksum-fcoe-crc:off [fixed]

         tx-checksum-sctp:off [fixed]

scatter-gather: on

         tx-scatter-gather:on

         tx-scatter-gather-fraglist:off [fixed]

tcp-segmentation-offload:on

         tx-tcp-segmentation:on

         tx-tcp-ecn-segmentation:off [fixed]

         tx-tcp6-segmentation:off [fixed]

udp-fragmentation-offload: off [fixed]

generic-segmentation-offload:on

[root@foundation0images]# ethtool -K eno16777736 gso off

[root@foundation0images]# ethtool -K eno16777736 tso off

[root@foundation0images]# ethtool -k eno16777736

Features for eno16777736:

rx-checksumming: off

tx-checksumming: on

         tx-checksum-ipv4:off [fixed]

         tx-checksum-ip-generic:on

         tx-checksum-ipv6:off [fixed]

         tx-checksum-fcoe-crc:off [fixed]

         tx-checksum-sctp:off [fixed]

scatter-gather: on

         tx-scatter-gather:on

         tx-scatter-gather-fraglist:off [fixed]

tcp-segmentation-offload:off

         tx-tcp-segmentation:off

         tx-tcp-ecn-segmentation:off [fixed]

         tx-tcp6-segmentation:off [fixed]

udp-fragmentation-offload: off [fixed]

generic-segmentation-offload:off

vhost-net后端驱动

后端驱动一般是由qemu提供的,如果对于网络IO请求的后端处理能够在内核空间来完成,效率就会更高,提高网络吞吐与减少延迟,在较新的内核中有一个叫“vhost-net”的驱动模块,作为一个内核级别的后端处理程序,将virtio-net的后端处理任务放到内核空间中执行,以提高效率。

如果guest处理数据的速度比host发送的速度慢,则不使用vhost-net,让传输速度稍微慢一点反而会提高整体的性能。容易造成缓冲区溢出。

下面查看vhost-net的使用情况

[root@foundation0images]# grep VHOST /boot/config-3.10.0-123.el7.x86_64

CONFIG_VHOST_NET=m

# CONFIG_VHOST_SCSI is not set

CONFIG_VHOST_RING=m

[root@foundation0images]# lsmod |grep vhost

vhost_net              33961  8

macvtap                18302  1 vhost_net

tun                    27183  17 vhost_net

host中的内核将vhost-net编译为模块

[root@foundation0images]# rmmod vhost-net

rmmod: ERROR: Module vhost_net is in use

[root@foundation0 images]#

在使用libvirt时,如使用vhost-net后端驱动XML的配置如下

                <interfacetype="bridge">

                        <sourcebridge="br0"/>

                        <macaddress="52:54:00:00:02:0A"/>

                        <modeltype="virtio"/>

                        <drivername="qemu"/>

                </interface>

4.virtio_blk

 


本文出自 “Yolo” 博客,请务必保留此出处http://4708948.blog.51cto.com/4698948/1707455

kvm半虚拟化驱动

标签:kvm   虚拟化   半虚拟化   

原文地址:http://4708948.blog.51cto.com/4698948/1707455

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!