重点部分
1、添加hugepages
<memory unit='M'>4096</memory>
<currentMemory unit='M'>4096</currentMemory>
<memoryBacking>
<hugepages>
<page size="1" unit="G" nodeset="0"/>
</hugepages>
<source type="file"/>
<access mode="private"/>
<allocation mode="immediate"/>
</memoryBacking>
<cpu mode='host-model'>
<model fallback='allow'/>
<topology sockets='1' cores='4' threads='1'/>
<numa>
<cell id='0' cpus='0-3' memory='4096' unit='M' memAccess='shared'/>
</numa>
</cpu>
2、添加vhost接口,mode有server和client
<interface type='vhostuser'>
<mac address='fa:16:3e:66:bd:66'/>
<source type='unix' path='/usr/local/var/run/openvswitch/vhost-user1' mode='client' />
<model type='virtio'/>
</interface>
<interface type='vhostuser'>
<mac address='fa:16:3e:66:bd:88'/>
<source type='unix' path='/usr/local/var/run/openvswitch/vhost-user2' mode='client' />
<model type='virtio'/>
</interface>
3、指定qemu启动时hugepage挂载路径
在/etc/libvirt/qemu.conf添加
memory_backing_dir = "/mnt/huge"
4、完整XML文件
<domain type='kvm' id='93'>
<name>instance-vhost</name>
<uuid>5f98aaaa-0f1c-4660-ac93-c92ea4d46e91</uuid>
<metadata>
<nova:instance xmlns:nova="http://openstack.org/xmlns/libvirt/nova/1.0">
<nova:package version="2015.1.0-20161229.el7"/>
<nova:name>VM_1482923074.24</nova:name>
<nova:creationTime>2017-01-03 08:05:04</nova:creationTime>
<nova:flavor name="FLV_1483411170.68">
<nova:memory>8192</nova:memory>
<nova:disk>50</nova:disk>
<nova:swap>0</nova:swap>
<nova:ephemeral>0</nova:ephemeral>
<nova:vcpus>32</nova:vcpus>
</nova:flavor>
<nova:owner>
<nova:user uuid="9a880356a66443049beb632bf6835ed3">jianghui522</nova:user>
<nova:project uuid="d6aa39869a4843b2a70cf7e59b1d1076">jianghui522</nova:project>
</nova:owner>
<nova:root type="image" uuid="ba652e41-47d8-4820-a1b5-7024e70ac67c"/>
</nova:instance>
</metadata>
<memory unit='M'>4096</memory>
<currentMemory unit='M'>4096</currentMemory>
<memoryBacking>
<hugepages>
<page size="1" unit="G" nodeset="0"/>
</hugepages>
<source type="file"/>
<access mode="private"/>
<allocation mode="immediate"/>
</memoryBacking>
<cpu mode='host-model'>
<model fallback='allow'/>
<topology sockets='1' cores='4' threads='1'/>
<numa>
<cell id='0' cpus='0-3' memory='4096' unit='M' memAccess='shared'/>
</numa>
</cpu>
<vcpu placement='static' current='4'>4</vcpu>
<cputune>
<shares>12288</shares>
</cputune>
<resource>
<partition>/machine</partition>
</resource>
<sysinfo type='smbios'>
<system>
<entry name='manufacturer'>Fedora Project</entry>
<entry name='product'>OpenStack Nova</entry>
<entry name='version'>2015.1.0-20161229.el7</entry>
<entry name='serial'>5a8f8f31-db9f-4b84-93bb-6f4837434eb9</entry>
<entry name='uuid'>5f98aaaa-0f1c-4660-ac93-c92ea4d46e91</entry>
</system>
</sysinfo>
<os>
<type arch='x86_64' machine='pc-i440fx-1.6'>hvm</type>
<boot dev='hd'/>
<smbios mode='sysinfo'/>
</os>
<features>
<acpi/>
<apic/>
<hyperv>
<relaxed state='on'/>
<vapic state='on'/>
<spinlocks state='on' retries='8191'/>
</hyperv>
</features>
<clock offset='localtime'>
<timer name='pit' tickpolicy='delay'/>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='hpet' present='no'/>
</clock>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/home/vm/vm_licko/CENT_7.1_S_64_X_20_X_pktgen.qcow2'/>
<backingStore/>
<target dev='vda' bus='virtio'/>
<serial>cafb3cff-8267-4a13-991b-c92103741992</serial>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</disk>
<controller type='usb' index='0'>
<alias name='usb0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'>
<alias name='pci.0'/>
</controller>
<interface type='vhostuser'>
<mac address='fa:16:3e:66:bd:66'/>
<source type='unix' path='/usr/local/var/run/openvswitch/vhost-user1' mode='client' />
<model type='virtio'/>
</interface>
<interface type='vhostuser'>
<mac address='fa:16:3e:66:bd:88'/>
<source type='unix' path='/usr/local/var/run/openvswitch/vhost-user2' mode='client' />
<model type='virtio'/>
</interface>
<serial type='file'>
<source path='/var/lib/nova/instances/5f98aaaa-0f1c-4660-ac93-c92ea4d46e91/console.log'/>
<target port='0'/>
<alias name='serial0'/>
</serial>
<serial type='pty'>
<source path='/dev/pts/1'/>
<target port='1'/>
<alias name='serial1'/>
</serial>
<input type='tablet' bus='usb'>
<alias name='input0'/>
</input>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='vnc' port='5901' autoport='yes' listen='0.0.0.0' keymap='en-us'>
<listen type='address' address='0.0.0.0'/>
</graphics>
<video>
<model type='cirrus' vram='16384' heads='1'/>
<alias name='video0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<alias name='balloon0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
<stats period='10'/>
</memballoon>
</devices>
</domain>