Sharing

2012年6月16日 星期六

KVM Guest with virtio network driver loses network connectivity


最近開始使用 Ubuntu 12.04, Kernel 是 3.2.0, 但發現如果用這版來裝的 VM, 會三不五時遇到網路斷掉的狀況, 系統沒有 Crash, 也只要重啟網路就可以繼續使用, 但老是這樣, 總是讓人感到不方便, 而且後來發現只要流量一大就會發生這個問題, 那影響就很大了. 找了一下網路, 發現這個問題也很多人 遇到, 似乎是 KVM 的 virtio 有 bug.

http://www.mail-archive.com/kvm@vger.kernel.org/msg68530.html

一路測到 3.2.0-26 , 這個問題也都還存在


virsh # version
Compiled against library: libvir 0.9.8
Using library: libvir 0.9.8
Using API: QEMU 0.9.8
Running hypervisor: QEMU 1.0.0

目前有找到兩個暫解

1. turn off event_idx parameter in qemu driver for virtio
  
       a. use libvirt xml
         
             
         

       b. use kvm command
          -device virtio-net-pci,event_idx=off
 
2. turn on vhost

       a. use libvirt
          modprobe vhost_net
          service libvirtd restart
          restart your vm

       b. use kvm command
          -netdev tap,vhost=on

兩個方案都是可行的, 不過第二個方案看起來是比較好的選擇, 因為根據文件還可以加強 Performance. 我用 iperf 測試的結果, 如果是從 vm 從資料到 host 端, 可以達到 13Gbits/sec, 如果不用 virtio, 預設的網卡設定, 大概都只有 150 Mbits/sec, 實在是很慢

另外補上 KVM 的 tuning 網頁

如果是用 virt-install, 可以加上以下幾個參數, 做的事情其實是和上面那篇一樣
-v
--cpu host
--disk bus=virtio,cache=writeback 
--accelerate
--network model=virtio

產生的指令會類似下面
kvm -S -M pc-1.0 -cpu core2duo,+lahf_lm,+rdtscp,+pdpe1gb,+aes,+popcnt,+sse4.2,+sse4.1,+dca,+xtpr,+cx16,+tm2,+est,+vmx,+ds_cpl,+pbe,+tm,+ht,+ss,+acpi,+ds -enable-kvm -m 8192 -smp 1,sockets=1,cores=1,threads=1 -name iscsi-server4 -uuid 035b0292-5866-ddac-e088-4cfd04f8af93 -nodefconfig -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/iscsi-server4.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-shutdown -drive file=iscsi-server4.qcow2,if=none,id=drive-virtio-disk0,format=qcow2,cache=writeback -device virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -netdev tap,fd=23,id=hostnet0,vhost=on,vhostfd=24 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:1c:9d:f0,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -usb -vnc 0.0.0.0:5 -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5





沒有留言: