[libvirt PATCH] qemu_command: do not use host-nodes for system memory

Pavel Hrdina posted 1 patch 2 years, 5 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1c6dc7e39470720b192665c81d94d9499e32fa09.1636467145.git.phrdina@redhat.com
src/qemu/qemu_command.c                       |  3 +-
.../numatune-system-memory.x86_64-latest.args | 32 +++++++++++++++++++
.../numatune-system-memory.xml                | 24 ++++++++++++++
tests/qemuxml2argvtest.c                      |  1 +
4 files changed, 59 insertions(+), 1 deletion(-)
create mode 100644 tests/qemuxml2argvdata/numatune-system-memory.x86_64-latest.args
create mode 100644 tests/qemuxml2argvdata/numatune-system-memory.xml
[libvirt PATCH] qemu_command: do not use host-nodes for system memory
Posted by Pavel Hrdina 2 years, 5 months ago
Commit 88957116c9d3cb4705380c3702c9d4315fb500bb switched to use
memory-backend-* for regular VM memory as well. That change indirectly
started using 'host-nodes' for system memory which results in QEMU
calling mbind() to bind the system memory to specific NUMA node if the
VM XML contains the configuration similar to this:

  ...
  <numatune>
    <memory mode='strict' nodeset='0'/>
  </numatune>
  ...

Once the VM was started with that configuration it was no longer
possible to change the memory NUMA nodeset.

Fixes: 677c90cc1d1fcb3aba09b5d4f0f8f83099911775
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/qemu/qemu_command.c                       |  3 +-
 .../numatune-system-memory.x86_64-latest.args | 32 +++++++++++++++++++
 .../numatune-system-memory.xml                | 24 ++++++++++++++
 tests/qemuxml2argvtest.c                      |  1 +
 4 files changed, 59 insertions(+), 1 deletion(-)
 create mode 100644 tests/qemuxml2argvdata/numatune-system-memory.x86_64-latest.args
 create mode 100644 tests/qemuxml2argvdata/numatune-system-memory.xml

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 483041f584..9bd7258b1d 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3631,7 +3631,8 @@ qemuBuildMemoryBackendProps(virJSONValue **backendProps,
     /* If mode is "restrictive", we should only use cgroups setting allowed memory
      * nodes, and skip passing the host-nodes and policy parameters to QEMU command
      * line which means we will use system default memory policy. */
-    if (nodemask && mode != VIR_DOMAIN_NUMATUNE_MEM_RESTRICTIVE) {
+    if (!systemMemory && nodemask &&
+        mode != VIR_DOMAIN_NUMATUNE_MEM_RESTRICTIVE) {
         if (!virNumaNodesetIsAvailable(nodemask))
             return -1;
         if (virJSONValueObjectAdd(props,
diff --git a/tests/qemuxml2argvdata/numatune-system-memory.x86_64-latest.args b/tests/qemuxml2argvdata/numatune-system-memory.x86_64-latest.args
new file mode 100644
index 0000000000..aee9b2ce76
--- /dev/null
+++ b/tests/qemuxml2argvdata/numatune-system-memory.x86_64-latest.args
@@ -0,0 +1,32 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-QEMUGuest1 \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
+/usr/bin/qemu-system-x86_64 \
+-name guest=QEMUGuest1,debug-threads=on \
+-S \
+-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tmp/lib/domain--1-QEMUGuest1/master-key.aes"}' \
+-machine pc,accel=tcg,usb=off,dump-guest-core=off,memory-backend=pc.ram \
+-cpu qemu64 \
+-m 214 \
+-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}' \
+-overcommit mem-lock=off \
+-smp 2,sockets=2,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-no-acpi \
+-boot strict=on \
+-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
+-audiodev id=audio1,driver=none \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/numatune-system-memory.xml b/tests/qemuxml2argvdata/numatune-system-memory.xml
new file mode 100644
index 0000000000..833303fe36
--- /dev/null
+++ b/tests/qemuxml2argvdata/numatune-system-memory.xml
@@ -0,0 +1,24 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>2</vcpu>
+  <numatune>
+    <memory mode='strict' nodeset='0'/>
+  </numatune>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+    <controller type='usb' index='0'/>
+    <controller type='pci' index='0' model='pci-root'/>
+    <memballoon model='none'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index a0498a0d92..161e7efa62 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -2063,6 +2063,7 @@ mymain(void)
     DO_TEST_CAPS_LATEST("numatune-memnode");
     DO_TEST_PARSE_ERROR_NOCAPS("numatune-memnode-invalid-mode");
     DO_TEST_CAPS_LATEST("numatune-memnode-restrictive-mode");
+    DO_TEST_CAPS_LATEST("numatune-system-memory");
 
     DO_TEST("numatune-memnode-no-memory",
             QEMU_CAPS_NUMA,
-- 
2.31.1

Re: [libvirt PATCH] qemu_command: do not use host-nodes for system memory
Posted by Michal Prívozník 2 years, 5 months ago
On 11/9/21 3:13 PM, Pavel Hrdina wrote:
> Commit 88957116c9d3cb4705380c3702c9d4315fb500bb switched to use
> memory-backend-* for regular VM memory as well. That change indirectly
> started using 'host-nodes' for system memory which results in QEMU
> calling mbind() to bind the system memory to specific NUMA node if the
> VM XML contains the configuration similar to this:
> 
>   ...
>   <numatune>
>     <memory mode='strict' nodeset='0'/>
>   </numatune>
>   ...
> 
> Once the VM was started with that configuration it was no longer
> possible to change the memory NUMA nodeset.
> 
> Fixes: 677c90cc1d1fcb3aba09b5d4f0f8f83099911775
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>  src/qemu/qemu_command.c                       |  3 +-
>  .../numatune-system-memory.x86_64-latest.args | 32 +++++++++++++++++++
>  .../numatune-system-memory.xml                | 24 ++++++++++++++
>  tests/qemuxml2argvtest.c                      |  1 +
>  4 files changed, 59 insertions(+), 1 deletion(-)
>  create mode 100644 tests/qemuxml2argvdata/numatune-system-memory.x86_64-latest.args
>  create mode 100644 tests/qemuxml2argvdata/numatune-system-memory.xml

Oops, yes.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal