半虛拟化驅動
host:主控端(實體機),guest:客戶機(虛拟機)
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
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~]# lsmod |grep virtio
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~]# 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
下面将記憶體設定為1024M
[root@desktop0 ~]# free -m
total used free shared buffers cached
Mem: 817 703 113 16 0 286
-/+ buffers/cache: 416 400
使用virtio_net半虛拟化驅動,可以提高網絡吞吐量和降低網絡延遲,使guest擁有和host一樣的原生網卡網絡性能。
在guest中檢視virtio網卡使用情況
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
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~]# 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
host閉關TSO與GSO,可使半虛拟化網絡驅動的性能更加優化,其中eno16777736是建立bridge供guest使用的網絡接口
[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
tcp-segmentation-offload:off
tx-tcp-segmentation:off
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
在使用libvirt時,如使用vhost-net後端驅動XML的配置如下
<interfacetype="bridge">
<sourcebridge="br0"/>
<macaddress="52:54:00:00:02:0A"/>
<modeltype="virtio"/>
<drivername="qemu"/>
</interface>
本文轉自810105851 51CTO部落格,原文連結:http://blog.51cto.com/4708948/1707455,如需轉載請自行聯系原作者