KVM仮想マシンCPUバインドパフォーマンスのチューニング

6473 ワード

linuxプロセスのプロセッサ親和性のvCPU分離とバインドについては、以前にテストを行いましたが、ubuntuでテストプロセスのプロセッサ親和性とvCPUのバインドを確認します.
試験接続設定KVM processor affinitieshttps://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Virtualization/ch33s08.html
では、KVMの仮想化の下でどのように直接仮想マシンにCPUをバインドするか、KVMは便利な方法を提供しています.
仮想マシンがあると表示
root@network:~# virsh list --all
 Id    Name                           State
----------------------------------------------------
 2     instance-000000ef              running
 4     instance-000000f3              running
 7     instance-00000120              running
 10    instance-00000146              running
 11    instance-00000147              running
 12    instance-00000148              running
 26    instance-00000157              running
 35    instance-0000015c              running
 38    instance-00000158              running
 39    instance-0000015b              running
 -     instance-00000122              shut off

VM情報の表示
root@network:~# virsh dumpxml instance-00000146

  instance-00000146
  45d77d2b-723f-40c8-a953-13f886a317f8
  4194304
  4194304
  4
  
    /machine
  
  
    
      OpenStack Foundation
      OpenStack Nova
      2014.1.3
      202b2f9b-3fb8-dc11-8e76-e03f490e5d2c
      45d77d2b-723f-40c8-a953-13f886a317f8
    
  
  
cvpuの表示
root@network:~# ps -ef|grep instance-00000146
root     21561 13180  0 14:31 pts/12   00:00:00 grep --color=auto instance-00000146
libvirt+ 31858     1  5 Jan08 ?        17:09:02 /usr/bin/qemu-system-x86_64 -name instance-00000146 -S -machine pc-i440fx-trusty,accel=kvm,usb=off -cpu Opteron_G5,+bmi1,+perfctr_nb,+perfctr_core,+topoext,+nodeid_msr,+tce,+lwp,+wdt,+skinit,+ibs,+osvw,+cr8legacy,+extapic,+cmp_legacy,+fxsr_opt,+mmxext,+osxsave,+monitor,+ht,+vme -m 4096 -realtime mlock=off -smp 4,sockets=4,cores=1,threads=1 -uuid 45d77d2b-723f-40c8-a953-13f886a317f8 -smbios type=1,manufacturer=OpenStack Foundation,product=OpenStack Nova,version=2014.1.3,serial=202b2f9b-3fb8-dc11-8e76-e03f490e5d2c,uuid=45d77d2b-723f-40c8-a953-13f886a317f8 -no-user-config -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/instance-00000146.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc,driftfix=slew -global kvm-pit.lost_tick_policy=discard -no-hpet -no-shutdown -boot strict=on -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive file=/var/lib/nova/instances/45d77d2b-723f-40c8-a953-13f886a317f8/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 -drive file=/var/lib/nova/instances/45d77d2b-723f-40c8-a953-13f886a317f8/disk.swap,if=none,id=drive-virtio-disk1,format=qcow2,cache=none -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x5,drive=drive-virtio-disk1,id=virtio-disk1 -netdev tap,fd=25,id=hostnet0,vhost=on,vhostfd=34 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=fa:16:3e:83:8e:cf,bus=pci.0,addr=0x3 -chardev file,id=charserial0,path=/var/lib/nova/instances/45d77d2b-723f-40c8-a953-13f886a317f8/console.log -device isa-serial,chardev=charserial0,id=serial0 -chardev pty,id=charserial1 -device isa-serial,chardev=charserial1,id=serial1 -device usb-tablet,id=input0 -vnc 0.0.0.0:8 -k en-us -device cirrus-vga,id=video0,bus=pci.0,addr=0x2 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6
root@network:~# ps -eLo ruser,pid,ppid,lwp,psr|grep 31858
libvirt+ 31858     1 31858   0
libvirt+ 31858     1 31867   6
libvirt+ 31858     1 31869   4
libvirt+ 31858     1 31871   7
libvirt+ 31858     1 31873   0
libvirt+ 31858     1 31882   7
libvirt+ 31858     1 19834   6
libvirt+ 31858     1 20272   6
libvirt+ 31858     1 20679   6
libvirt+ 31858     1 20925   6
libvirt+ 31858     1 20926   6
libvirt+ 31858     1 20927   6
libvirt+ 31858     1 20928   7
libvirt+ 31858     1 20930   6

最後の列はcpuの番号で、ps-eLo ruser、pid、ppid、lwp、psr|grep 31858を繰り返し実行すると、スレッドが不通cpu上でドリフトしていることがわかります.こんなに多くのスレッドをバインドするのは面倒です.
virsh vcpuinfo instance-00000146を使用して、vCPUごとに対応する物理コアを表示します(フローティングでもあります).
root@network:~# virsh vcpuinfo instance-00000146
VCPU:           0
CPU:            4
State:          running
CPU time:       16025.9s
CPU Affinity:   yyyyyyyy             CPU  ,Y , CPU 


VCPU:           1
CPU:            6
State:          running
CPU time:       20221.3s
CPU Affinity:   yyyyyyyy

VCPU:           2
CPU:            6
State:          running
CPU time:       12179.5s
CPU Affinity:   yyyyyyyy

VCPU:           3
CPU:            5
State:          running
CPU time:       12411.4s
CPU Affinity:   yyyyyyyy

instance-0000146のvcpu 0を物理cpu 3にバインド
root@network:~# virsh vcpupin instance-00000146 0 3

root@network:~# virsh vcpuinfo instance-00000146
VCPU:           0
CPU:            3
State:          running
CPU time:       16033.7s
CPU Affinity:   ---y----                     cpu  Y

VCPU:           1
CPU:            1
State:          running
CPU time:       20234.7s
CPU Affinity:   yyyyyyyy

VCPU:           2
CPU:            0
State:          running
CPU time:       12188.5s
CPU Affinity:   yyyyyyyy

VCPU:           3
CPU:            0
State:          running
CPU time:       12420.2s
CPU Affinity:   yyyyyyyy
順次バインド
root@network:~# virsh vcpupin instance-00000146 1 4

root@network:~# virsh vcpupin instance-00000146 2 5

root@network:~# virsh vcpupin instance-00000146 3 6

root@network:~# virsh vcpuinfo instance-00000146
VCPU:           0
CPU:            3
State:          running
CPU time:       16050.3s
CPU Affinity:   ---y----

VCPU:           1
CPU:            4
State:          running
CPU time:       20255.6s
CPU Affinity:   ----y---

VCPU:           2
CPU:            5
State:          running
CPU time:       12203.2s
CPU Affinity:   -----y--

VCPU:           3
CPU:            6
State:          running
CPU time:       12438.0s
CPU Affinity:   ------y-