6d3351
From 766ccea976922a5da2f76e26fc37e03ac14ecacd Mon Sep 17 00:00:00 2001
6d3351
Message-Id: <766ccea976922a5da2f76e26fc37e03ac14ecacd@dist-git>
6d3351
From: Michal Privoznik <mprivozn@redhat.com>
6d3351
Date: Wed, 14 Jun 2017 16:58:12 +0200
6d3351
Subject: [PATCH] qemu: Prefer hugepages over mem source='file'
6d3351
6d3351
https://bugzilla.redhat.com/show_bug.cgi?id=1214369
6d3351
6d3351
Consider the following XML:
6d3351
6d3351
  <memoryBacking>
6d3351
    <hugepages>
6d3351
      <page size='2048' unit='KiB' nodeset='1'/>
6d3351
    </hugepages>
6d3351
    <source type='file'/>
6d3351
    <access mode='shared'/>
6d3351
  </memoryBacking>
6d3351
6d3351
  <numa>
6d3351
    <cell id='0' cpus='0-3' memory='512000' unit='KiB'/>
6d3351
    <cell id='1' cpus='4-7' memory='512000' unit='KiB'/>
6d3351
  </numa>
6d3351
6d3351
The following cmd line is generated:
6d3351
6d3351
  -object
6d3351
  memory-backend-file,id=ram-node0,mem-path=/var/lib/libvirt/qemu/ram,
6d3351
  share=yes,size=524288000 -numa node,nodeid=0,cpus=0-3,memdev=ram-node0
6d3351
  -object
6d3351
  memory-backend-file,id=ram-node1,mem-path=/var/lib/libvirt/qemu/ram,
6d3351
  share=yes,size=524288000 -numa node,nodeid=1,cpus=4-7,memdev=ram-node1
6d3351
6d3351
This is obviously wrong as for node 1 hugepages should have been
6d3351
used. The hugepages configuration is more specific than 
6d3351
type='file'/>.
6d3351
6d3351
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6d3351
(cherry picked from commit 992bf863fccfe1fa1d0c5a5277b9cee50abc48ef)
6d3351
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6d3351
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
6d3351
---
6d3351
 src/qemu/qemu_command.c                            |  6 +--
6d3351
 .../qemuxml2argv-hugepages-memaccess2.args         | 39 ++++++++++++++
6d3351
 .../qemuxml2argv-hugepages-memaccess2.xml          | 62 ++++++++++++++++++++++
6d3351
 tests/qemuxml2argvtest.c                           |  3 ++
6d3351
 .../qemuxml2xmlout-hugepages-memaccess2.xml        |  1 +
6d3351
 tests/qemuxml2xmltest.c                            |  1 +
6d3351
 6 files changed, 109 insertions(+), 3 deletions(-)
6d3351
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.args
6d3351
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.xml
6d3351
 create mode 120000 tests/qemuxml2xmloutdata/qemuxml2xmlout-hugepages-memaccess2.xml
6d3351
6d3351
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
6d3351
index c791214528..5013d3149d 100644
6d3351
--- a/src/qemu/qemu_command.c
6d3351
+++ b/src/qemu/qemu_command.c
6d3351
@@ -3413,9 +3413,9 @@ qemuBuildMemoryBackendStr(virJSONValuePtr *backendProps,
6d3351
             if (VIR_STRDUP(memPath, mem->nvdimmPath) < 0)
6d3351
                 goto cleanup;
6d3351
             prealloc = true;
6d3351
-        } else if (def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_FILE) {
6d3351
-            /* We can have both pagesize and mem source,
6d3351
-             * then check mem source first. */
6d3351
+        } else if (!pagesize && def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_FILE) {
6d3351
+            /* We can have both pagesize and mem source. If that's the case,
6d3351
+             * prefer hugepages as those are more specific. */
6d3351
             if (VIR_STRDUP(memPath, cfg->memoryBackingDir) < 0)
6d3351
                 goto cleanup;
6d3351
         } else {
6d3351
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.args b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.args
6d3351
new file mode 100644
6d3351
index 0000000000..11985232a7
6d3351
--- /dev/null
6d3351
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.args
6d3351
@@ -0,0 +1,39 @@
6d3351
+LC_ALL=C \
6d3351
+PATH=/bin \
6d3351
+HOME=/home/test \
6d3351
+USER=test \
6d3351
+LOGNAME=test \
6d3351
+QEMU_AUDIO_DRV=none \
6d3351
+/usr/bin/qemu-system-i686 \
6d3351
+-name QEMUGuest1 \
6d3351
+-S \
6d3351
+-M pc \
6d3351
+-m size=4194304k,slots=16,maxmem=8388608k \
6d3351
+-smp 4,sockets=4,cores=1,threads=1 \
6d3351
+-object memory-backend-file,id=ram-node0,mem-path=/var/lib/libvirt/qemu/ram,\
6d3351
+share=no,size=1073741824,host-nodes=0-3,policy=bind \
6d3351
+-numa node,nodeid=0,cpus=0,memdev=ram-node0 \
6d3351
+-object memory-backend-file,id=ram-node1,prealloc=yes,\
6d3351
+mem-path=/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1,share=yes,size=1073741824,\
6d3351
+host-nodes=0-3,policy=bind \
6d3351
+-numa node,nodeid=1,cpus=1,memdev=ram-node1 \
6d3351
+-object memory-backend-file,id=ram-node2,mem-path=/var/lib/libvirt/qemu/ram,\
6d3351
+share=no,size=1073741824,host-nodes=0-3,policy=bind \
6d3351
+-numa node,nodeid=2,cpus=2,memdev=ram-node2 \
6d3351
+-object memory-backend-file,id=ram-node3,mem-path=/var/lib/libvirt/qemu/ram,\
6d3351
+share=no,size=1073741824,host-nodes=3,policy=bind \
6d3351
+-numa node,nodeid=3,cpus=3,memdev=ram-node3 \
6d3351
+-object memory-backend-file,id=memdimm0,prealloc=yes,\
6d3351
+mem-path=/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1,share=yes,size=536870912,\
6d3351
+host-nodes=0-3,policy=bind \
6d3351
+-device pc-dimm,node=1,memdev=memdimm0,id=dimm0,slot=0,addr=4294967296 \
6d3351
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
6d3351
+-nographic \
6d3351
+-nodefaults \
6d3351
+-monitor unix:/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server,nowait \
6d3351
+-no-acpi \
6d3351
+-boot c \
6d3351
+-usb \
6d3351
+-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
6d3351
+-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
6d3351
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
6d3351
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.xml b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.xml
6d3351
new file mode 100644
6d3351
index 0000000000..c0011285c2
6d3351
--- /dev/null
6d3351
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.xml
6d3351
@@ -0,0 +1,62 @@
6d3351
+<domain type='qemu'>
6d3351
+  <name>QEMUGuest1</name>
6d3351
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
6d3351
+  <maxMemory slots='16' unit='KiB'>8388608</maxMemory>
6d3351
+  <memory unit='KiB'>4194304</memory>
6d3351
+  <currentMemory unit='KiB'>4194304</currentMemory>
6d3351
+  <memoryBacking>
6d3351
+    <hugepages>
6d3351
+      <page size='2048' unit='KiB' nodeset='1'/>
6d3351
+    </hugepages>
6d3351
+    <source type='file'/>
6d3351
+    <access mode='private'/>
6d3351
+  </memoryBacking>
6d3351
+  <vcpu placement='static'>4</vcpu>
6d3351
+  <numatune>
6d3351
+    <memory mode='strict' nodeset='0-3'/>
6d3351
+    <memnode cellid='3' mode='strict' nodeset='3'/>
6d3351
+  </numatune>
6d3351
+  <os>
6d3351
+    <type arch='i686' machine='pc'>hvm</type>
6d3351
+    <boot dev='hd'/>
6d3351
+  </os>
6d3351
+  <cpu>
6d3351
+    <numa>
6d3351
+      <cell id='0' cpus='0' memory='1048576' unit='KiB'/>
6d3351
+      <cell id='1' cpus='1' memory='1048576' unit='KiB' memAccess='shared'/>
6d3351
+      <cell id='2' cpus='2' memory='1048576' unit='KiB' memAccess='private'/>
6d3351
+      <cell id='3' cpus='3' memory='1048576' unit='KiB'/>
6d3351
+    </numa>
6d3351
+  </cpu>
6d3351
+  <clock offset='utc'/>
6d3351
+  <on_poweroff>destroy</on_poweroff>
6d3351
+  <on_reboot>restart</on_reboot>
6d3351
+  <on_crash>destroy</on_crash>
6d3351
+  <devices>
6d3351
+    <emulator>/usr/bin/qemu-system-i686</emulator>
6d3351
+    <disk type='block' device='disk'>
6d3351
+      <source dev='/dev/HostVG/QEMUGuest1'/>
6d3351
+      <target dev='hda' bus='ide'/>
6d3351
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
6d3351
+    </disk>
6d3351
+    <controller type='usb' index='0'>
6d3351
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
6d3351
+    </controller>
6d3351
+    <controller type='ide' index='0'>
6d3351
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
6d3351
+    </controller>
6d3351
+    <controller type='pci' index='0' model='pci-root'/>
6d3351
+    <input type='mouse' bus='ps2'/>
6d3351
+    <input type='keyboard' bus='ps2'/>
6d3351
+    <memballoon model='virtio'>
6d3351
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
6d3351
+    </memballoon>
6d3351
+    <memory model='dimm'>
6d3351
+      <target>
6d3351
+        <size unit='KiB'>524288</size>
6d3351
+        <node>1</node>
6d3351
+      </target>
6d3351
+      <address type='dimm' slot='0' base='0x100000000'/>
6d3351
+    </memory>
6d3351
+  </devices>
6d3351
+</domain>
6d3351
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
6d3351
index 77e52bd33b..98e70033ec 100644
6d3351
--- a/tests/qemuxml2argvtest.c
6d3351
+++ b/tests/qemuxml2argvtest.c
6d3351
@@ -830,6 +830,9 @@ mymain(void)
6d3351
     DO_TEST("hugepages-memaccess", QEMU_CAPS_OBJECT_MEMORY_FILE,
6d3351
             QEMU_CAPS_OBJECT_MEMORY_RAM, QEMU_CAPS_DEVICE_PC_DIMM,
6d3351
             QEMU_CAPS_NUMA);
6d3351
+    DO_TEST("hugepages-memaccess2", QEMU_CAPS_OBJECT_MEMORY_FILE,
6d3351
+            QEMU_CAPS_OBJECT_MEMORY_RAM, QEMU_CAPS_DEVICE_PC_DIMM,
6d3351
+            QEMU_CAPS_NUMA);
6d3351
     DO_TEST("nosharepages", QEMU_CAPS_MACHINE_OPT, QEMU_CAPS_MEM_MERGE);
6d3351
     DO_TEST("disk-cdrom", NONE);
6d3351
     DO_TEST("disk-iscsi", NONE);
6d3351
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-hugepages-memaccess2.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-hugepages-memaccess2.xml
6d3351
new file mode 120000
6d3351
index 0000000000..3f7a38333f
6d3351
--- /dev/null
6d3351
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-hugepages-memaccess2.xml
6d3351
@@ -0,0 +1 @@
6d3351
+../qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.xml
6d3351
\ No newline at end of file
6d3351
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
6d3351
index 511d1b3fb9..f2abad00cf 100644
6d3351
--- a/tests/qemuxml2xmltest.c
6d3351
+++ b/tests/qemuxml2xmltest.c
6d3351
@@ -421,6 +421,7 @@ mymain(void)
6d3351
     DO_TEST("hugepages-pages3", NONE);
6d3351
     DO_TEST("hugepages-shared", NONE);
6d3351
     DO_TEST("hugepages-memaccess", NONE);
6d3351
+    DO_TEST("hugepages-memaccess2", NONE);
6d3351
     DO_TEST("nosharepages", NONE);
6d3351
     DO_TEST("restore-v2", NONE);
6d3351
     DO_TEST("migrate", NONE);
6d3351
-- 
6d3351
2.13.1
6d3351