render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
9119d9
From c0af84c532e72d42a66059998ef7f03dcb0d6bd1 Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <c0af84c532e72d42a66059998ef7f03dcb0d6bd1@dist-git>
9119d9
From: Michal Privoznik <mprivozn@redhat.com>
9119d9
Date: Mon, 23 Feb 2015 08:20:03 +0100
9119d9
Subject: [PATCH] qemuBuildNumaArgStr: Use memory-backend-ram more wisely
9119d9
9119d9
RHEL-7.2: https://bugzilla.redhat.com/show_bug.cgi?id=1191567
9119d9
RHEL-7.1.z: https://bugzilla.redhat.com/show_bug.cgi?id=1194982
9119d9
9119d9
So, when building the '-numa' command line, the qemuBuildNumaArgStr()
9119d9
function does quite a lot of checks to chose the best backend, or to
9119d9
check if one is in fact needed. However, it returned that backend is
9119d9
needed even for this little fella:
9119d9
9119d9
  <numatune>
9119d9
    <memory mode="strict" nodeset="0,2"/>
9119d9
  </numatune>
9119d9
9119d9
This can be guaranteed via CGroups entirely, there's no need to use
9119d9
memory-backend-ram to let qemu know where to get memory from. Well, as
9119d9
long as there's no <memnode/> element, which explicitly requires the
9119d9
backend. Long story short, we wouldn't have to care, as qemu works
9119d9
either way. However, the problem is migration (as always). Previously,
9119d9
libvirt would have started qemu with:
9119d9
9119d9
  -numa node,memory=X
9119d9
9119d9
in this case and restricted memory placement in CGroups. Today, libvirt
9119d9
creates more complicated command line:
9119d9
9119d9
  -object memory-backend-ram,id=ram-node0,size=X
9119d9
  -numa node,memdev=ram-node0
9119d9
9119d9
Again, one wouldn't find anything wrong with these two approaches.
9119d9
Both work just fine. Unless you try to migrated from the older libvirt
9119d9
into the newer one. These two approaches are, unfortunately, not
9119d9
compatible. My suggestion is, in order to allow users to migrate, lets
9119d9
use the older approach for as long as the newer one is not needed.
9119d9
9119d9
Moreover, this partly cherry-picks
9119d9
b92a0037103efc15639dee9562866dbaffe302fb too. Especially the tests,
9119d9
which need to be fixed too. We can't mix the bare -numa and
9119d9
memory-backend-ram on the command line.
9119d9
9119d9
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
9119d9
(cherry picked from commit 7832fac84741d65e851dbdbfaf474785cbfdcf3c)
9119d9
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
9119d9
9119d9
Conflicts:
9119d9
	src/qemu/qemu_command.c: The code is totally rewritten
9119d9
        upstream (esp. after memory hotplug).
9119d9
        tests/qemuxml2argvtest.c: Context, some tests were not
9119d9
        introduced yet.
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/qemu/qemu_command.c                            | 35 +++++++++++---------
9119d9
 .../qemuxml2argv-cputune-numatune.args             |  5 +++
9119d9
 .../qemuxml2argv-cputune-numatune.xml              | 37 ++++++++++++++++++++++
9119d9
 .../qemuxml2argv-hugepages-pages3.args             |  3 +-
9119d9
 .../qemuxml2argv-numatune-auto-prefer.args         |  5 +++
9119d9
 .../qemuxml2argv-numatune-memnode-no-memory.args   |  3 +-
9119d9
 tests/qemuxml2argvtest.c                           |  6 ++++
9119d9
 7 files changed, 77 insertions(+), 17 deletions(-)
9119d9
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cputune-numatune.args
9119d9
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cputune-numatune.xml
9119d9
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-numatune-auto-prefer.args
9119d9
9119d9
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
9119d9
index db0c324..a9cb7a3 100644
9119d9
--- a/src/qemu/qemu_command.c
9119d9
+++ b/src/qemu/qemu_command.c
9119d9
@@ -6540,22 +6540,27 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
9119d9
     char *nodemask = NULL;
9119d9
     char *mem_path = NULL;
9119d9
     int ret = -1;
9119d9
+    bool useNodemask = false;
9119d9
 
9119d9
-    if (virDomainNumatuneHasPerNodeBinding(def->numatune) &&
9119d9
-        !(virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_RAM) ||
9119d9
-          virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FILE))) {
9119d9
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
9119d9
-                       _("Per-node memory binding is not supported "
9119d9
-                         "with this QEMU"));
9119d9
-        goto cleanup;
9119d9
+    if (virDomainNumatuneHasPerNodeBinding(def->numatune)) {
9119d9
+        if (!(virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_RAM) ||
9119d9
+              virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FILE))) {
9119d9
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
9119d9
+                           _("Per-node memory binding is not supported "
9119d9
+                             "with this QEMU"));
9119d9
+            goto cleanup;
9119d9
+        }
9119d9
+        useNodemask = true;
9119d9
     }
9119d9
 
9119d9
-    if (def->mem.nhugepages && def->mem.hugepages[0].size &&
9119d9
-        !virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FILE)) {
9119d9
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
9119d9
-                       _("huge pages per NUMA node are not "
9119d9
-                         "supported with this QEMU"));
9119d9
-        goto cleanup;
9119d9
+    if (def->mem.nhugepages && def->mem.hugepages[0].size) {
9119d9
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FILE)) {
9119d9
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
9119d9
+                           _("huge pages per NUMA node are not "
9119d9
+                             "supported with this QEMU"));
9119d9
+            goto cleanup;
9119d9
+        }
9119d9
+        useNodemask = true;
9119d9
     }
9119d9
 
9119d9
     for (i = 0; i < def->mem.nhugepages; i++) {
9119d9
@@ -6714,7 +6719,7 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
9119d9
                 virBufferAsprintf(&buf, ",policy=%s", policy);
9119d9
             }
9119d9
 
9119d9
-            if (hugepage || nodemask) {
9119d9
+            if (useNodemask) {
9119d9
                 virCommandAddArg(cmd, "-object");
9119d9
                 virCommandAddArgBuffer(cmd, &buf;;
9119d9
             } else {
9119d9
@@ -6739,7 +6744,7 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
9119d9
             virBufferAdd(&buf, tmpmask, -1);
9119d9
         }
9119d9
 
9119d9
-        if (hugepage || nodemask)
9119d9
+        if (useNodemask)
9119d9
             virBufferAsprintf(&buf, ",memdev=ram-node%zu", i);
9119d9
         else
9119d9
             virBufferAsprintf(&buf, ",mem=%d", cellmem);
9119d9
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cputune-numatune.args b/tests/qemuxml2argvdata/qemuxml2argv-cputune-numatune.args
9119d9
new file mode 100644
9119d9
index 0000000..481f72f
9119d9
--- /dev/null
9119d9
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cputune-numatune.args
9119d9
@@ -0,0 +1,5 @@
9119d9
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
9119d9
+/usr/bin/qemu-system-x86_64 -S -M pc-q35-2.3 -m 128 \
9119d9
+-smp 2,maxcpus=6,sockets=6,cores=1,threads=1 \
9119d9
+-nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi \
9119d9
+-boot c -net none -serial none -parallel none
9119d9
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cputune-numatune.xml b/tests/qemuxml2argvdata/qemuxml2argv-cputune-numatune.xml
9119d9
new file mode 100644
9119d9
index 0000000..01bbb3d
9119d9
--- /dev/null
9119d9
+++ b/tests/qemuxml2argvdata/qemuxml2argv-cputune-numatune.xml
9119d9
@@ -0,0 +1,37 @@
9119d9
+<domain type='kvm'>
9119d9
+  <name>dummy2</name>
9119d9
+  <uuid>4d92ec27-9ebf-400b-ae91-20c71c647c19</uuid>
9119d9
+  <memory unit='KiB'>131072</memory>
9119d9
+  <currentMemory unit='KiB'>65536</currentMemory>
9119d9
+  <vcpu placement='auto' current='2'>6</vcpu>
9119d9
+  <iothreads>2</iothreads>
9119d9
+  <cputune>
9119d9
+    <emulatorpin cpuset='1-3'/>
9119d9
+    <iothreadpin iothread='1' cpuset='2'/>
9119d9
+  </cputune>
9119d9
+  <numatune>
9119d9
+    <memory mode='strict' placement='auto'/>
9119d9
+  </numatune>
9119d9
+  <os>
9119d9
+    <type arch='x86_64' machine='pc-q35-2.3'>hvm</type>
9119d9
+    <boot dev='hd'/>
9119d9
+  </os>
9119d9
+  <clock offset='utc'/>
9119d9
+  <on_poweroff>destroy</on_poweroff>
9119d9
+  <on_reboot>restart</on_reboot>
9119d9
+  <on_crash>destroy</on_crash>
9119d9
+  <devices>
9119d9
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
9119d9
+    <controller type='sata' index='0'>
9119d9
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
9119d9
+    </controller>
9119d9
+    <controller type='pci' index='0' model='pcie-root'/>
9119d9
+    <controller type='pci' index='1' model='dmi-to-pci-bridge'>
9119d9
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x1e' function='0x0'/>
9119d9
+    </controller>
9119d9
+    <controller type='pci' index='2' model='pci-bridge'>
9119d9
+      <address type='pci' domain='0x0000' bus='0x01' slot='0x01' function='0x0'/>
9119d9
+    </controller>
9119d9
+    <memballoon model='none'/>
9119d9
+  </devices>
9119d9
+</domain>
9119d9
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages3.args b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages3.args
9119d9
index f81947e..27b3f8e 100644
9119d9
--- a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages3.args
9119d9
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages3.args
9119d9
@@ -1,6 +1,7 @@
9119d9
 LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
9119d9
 /usr/bin/qemu -S -M pc -m 1024 -smp 2 \
9119d9
--numa node,nodeid=0,cpus=0,mem=256 \
9119d9
+-object memory-backend-ram,size=256M,id=ram-node0 \
9119d9
+-numa node,nodeid=0,cpus=0,memdev=ram-node0 \
9119d9
 -object memory-backend-file,prealloc=yes,\
9119d9
 mem-path=/dev/hugepages1G/libvirt/qemu,size=768M,id=ram-node1 \
9119d9
 -numa node,nodeid=1,cpus=1,memdev=ram-node1 \
9119d9
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-numatune-auto-prefer.args b/tests/qemuxml2argvdata/qemuxml2argv-numatune-auto-prefer.args
9119d9
new file mode 100644
9119d9
index 0000000..0b1b0f5
9119d9
--- /dev/null
9119d9
+++ b/tests/qemuxml2argvdata/qemuxml2argv-numatune-auto-prefer.args
9119d9
@@ -0,0 +1,5 @@
9119d9
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
9119d9
+/usr/bin/kvm -S -M pc -m 64 -smp 1 \
9119d9
+-numa node,nodeid=0,cpus=0,mem=64 \
9119d9
+-nographic -monitor unix:/tmp/test-monitor,server,nowait \
9119d9
+-no-acpi -boot c -usb -net none -serial none -parallel none
9119d9
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-numatune-memnode-no-memory.args b/tests/qemuxml2argvdata/qemuxml2argv-numatune-memnode-no-memory.args
9119d9
index 2addf97..b0e274c 100644
9119d9
--- a/tests/qemuxml2argvdata/qemuxml2argv-numatune-memnode-no-memory.args
9119d9
+++ b/tests/qemuxml2argvdata/qemuxml2argv-numatune-memnode-no-memory.args
9119d9
@@ -2,6 +2,7 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
9119d9
 /usr/bin/kvm -S -M pc -m 64 -smp 2 \
9119d9
 -object memory-backend-ram,size=32M,id=ram-node0,host-nodes=3,policy=preferred \
9119d9
 -numa node,nodeid=0,cpus=0,memdev=ram-node0 \
9119d9
--numa node,nodeid=1,cpus=1,mem=32 \
9119d9
+-object memory-backend-ram,size=32M,id=ram-node1 \
9119d9
+-numa node,nodeid=1,cpus=1,memdev=ram-node1 \
9119d9
 -nographic -monitor unix:/tmp/test-monitor,server,nowait \
9119d9
 -no-acpi -boot c -usb -net none -serial none -parallel none
9119d9
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
9119d9
index 98bb9ad..ee7397a 100644
9119d9
--- a/tests/qemuxml2argvtest.c
9119d9
+++ b/tests/qemuxml2argvtest.c
9119d9
@@ -1246,6 +1246,10 @@ mymain(void)
9119d9
     DO_TEST("blkiotune-device", QEMU_CAPS_NAME);
9119d9
     DO_TEST("cputune", QEMU_CAPS_NAME);
9119d9
     DO_TEST("cputune-zero-shares", QEMU_CAPS_NAME);
9119d9
+    DO_TEST("cputune-numatune", QEMU_CAPS_SMP_TOPOLOGY,
9119d9
+            QEMU_CAPS_KVM,
9119d9
+            QEMU_CAPS_OBJECT_MEMORY_RAM,
9119d9
+            QEMU_CAPS_OBJECT_MEMORY_FILE);
9119d9
 
9119d9
     DO_TEST("numatune-memory", NONE);
9119d9
     DO_TEST_PARSE_ERROR("numatune-memory-invalid-nodeset", NONE);
9119d9
@@ -1256,6 +1260,8 @@ mymain(void)
9119d9
     DO_TEST_FAILURE("numatune-memnode-no-memory", NONE);
9119d9
 
9119d9
     DO_TEST("numatune-auto-nodeset-invalid", NONE);
9119d9
+    DO_TEST("numatune-auto-prefer", QEMU_CAPS_OBJECT_MEMORY_RAM,
9119d9
+            QEMU_CAPS_OBJECT_MEMORY_FILE);
9119d9
     DO_TEST_PARSE_ERROR("numatune-memnode-nocpu", NONE);
9119d9
     DO_TEST_PARSE_ERROR("numatune-memnodes-problematic", NONE);
9119d9
     DO_TEST("numad", NONE);
9119d9
-- 
9119d9
2.3.0
9119d9