Testing huge pages with libvirt
-------------------------------
(0) Allocate large pages on host
$ echo 1054 > /proc/sys/vm/nr_hugepages
Rationale for the above '1024' value from here:
http://www.linux-kvm.org/page/UsingLargePages
"On x86, large pages are 2M, so determine the max size of the
guest, and with some fudge factor (about 30 pages, completely
arbitrary value); we have something like:
HPAGES = $(($GUEST_SIZE_IN_MB / 2) + 30) For example, a 2G guest
would yield 1054 2MB pages."
(1) Check hugepages info from the proc filesystem:
$ grep -i Huge /proc/meminfo
AnonHugePages: 0 kB
HugePages_Total: 1024
HugePages_Free: 1024
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
(2) Start the libvirt guest and check if hugepages configuration is
correctly reflected in the guest XML configuration:
$ virsh start f21-vm
$ virsh dumpxml f21-vm | grep hugepages -B3 -A2
2000896
2000000
8
(3) QEMU invocation of the libvirt guest:
$ cat /var/log/libvirt/qemu/f21-vm.log
2014-12-13 15:46:00.201+0000: starting up
LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin QEMU_AUDIO_DRV=none /usr/bin/qemu-kvm -name f21-vm -S -machine pc-i440fx-2.1,accel=kvm,usb=off -m 1954 -mem-prealloc -mem-path /dev/hugepages/libvirt/qemu -realtime mlock=off -smp 8,sockets=8,cores=1,threads=1 -uuid 3dc5a06d-ab64-46b5-9379-f5cb7c8971b5 -nographic -no-user-config -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/f21-vm.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 ich9-usb-ehci1,id=usb,bus=pci.0,addr=0x3.0x7 -device ich9-usb-uhci1,masterbus=usb.0,firstport=0,bus=pci.0,multifunction=on,addr=0x3 -device ich9-usb-uhci2,masterbus=usb.0,firstport=2,bus=pci.0,addr=0x3.0x1 -device ich9-usb-uhci3,masterbus=usb.0,firstport=4,bus=pci.0,addr=0x3.0x2 -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x4 -drive file=/var/lib/libvirt/images/f21vm.qcow2,if=none,id=drive-virtio-disk0,format=qcow2,cache=none -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x5,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -netdev tap,fd=24,id=hostnet0,vhost=on,vhostfd=25 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:14:91:01,bus=pci.0,addr=0x2 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -chardev socket,id=charchannel0,path=/var/lib/libvirt/qemu/channel/target/f21-vm.org.qemu.guest_agent.0,server,nowait -device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=org.qemu.guest_agent.0 -device usb-tablet,id=input0 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6 -msg timestamp=on
. . .
(4) Check hugepages info again from the proc filesystem:
grep -i Huge /proc/meminfo
AnonHugePages: 0 kB
HugePages_Total: 1024
HugePages_Free: 47
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB