Currently, the ThreadContext object is generated whenever we see
.host-nodes attribute for a memory-backend-* object. The idea was
that when the backend is pinned to a specific set of host NUMA
nodes, then the allocation could be happening on CPUs from those
nodes too. But this may not be always possible.
Users might configure their guests in such way that vCPUs and
corresponding guest NUMA nodes are on different host NUMA nodes
than emulator thread. In this case, ThreadContext won't work,
because ThreadContext objects live in context of the emulator
thread (vCPU threads are moved around by us later, when emulator
thread finished its setup and spawned vCPU threads - see
qemuProcessSetupVcpus()). Therefore, memory allocation is done by
emulator thread which is pinned to a subset of host NUMA nodes,
but tries to create a ThreadContext object with a disjoint subset
of host NUMA nodes, which fails.
Resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=2154750
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_command.c | 11 ++++++-----
.../hugepages-memaccess2.x86_64-latest.args | 9 +++------
.../memory-hotplug-virtio-mem.x86_64-latest.args | 3 +--
.../numatune-memnode.x86_64-latest.args | 9 +++------
.../numatune-system-memory.x86_64-latest.args | 3 +--
5 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 06e29ff8ae..af17f37754 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3633,6 +3633,10 @@ qemuBuildThreadContextProps(virJSONValue **tcProps,
if (!nodemask)
return 0;
+ if (virJSONValueObjectGetBoolean(*memProps, "prealloc", &prealloc) <
0 ||
+ !prealloc)
+ return 0;
+
memalias = virJSONValueObjectGetString(*memProps, "id");
if (!memalias) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -3655,11 +3659,8 @@ qemuBuildThreadContextProps(virJSONValue **tcProps,
NULL) < 0)
return -1;
- if (virJSONValueObjectGetBoolean(*memProps, "prealloc", &prealloc)
>= 0 &&
- prealloc) {
- priv->threadContextAliases = g_slist_prepend(priv->threadContextAliases,
- g_steal_pointer(&tcAlias));
- }
+ priv->threadContextAliases = g_slist_prepend(priv->threadContextAliases,
+ g_steal_pointer(&tcAlias));
*tcProps = g_steal_pointer(&props);
return 0;
diff --git a/tests/qemuxml2argvdata/hugepages-memaccess2.x86_64-latest.args
b/tests/qemuxml2argvdata/hugepages-memaccess2.x86_64-latest.args
index f73da5865d..fedc9fe1ce 100644
--- a/tests/qemuxml2argvdata/hugepages-memaccess2.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/hugepages-memaccess2.x86_64-latest.args
@@ -16,17 +16,14 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
-m size=4194304k,slots=16,maxmem=8388608k \
-overcommit mem-lock=off \
-smp 4,sockets=4,cores=1,threads=1 \
--object
'{"qom-type":"thread-context","id":"tc-ram-node0","node-affinity":[0,1,2,3]}'
\
--object
'{"qom-type":"memory-backend-file","id":"ram-node0","mem-path":"/var/lib/libvirt/qemu/ram/-1-QEMUGuest1/ram-node0","share":false,"size":1073741824,"host-nodes":[0,1,2,3],"policy":"bind","prealloc-context":"tc-ram-node0"}'
\
+-object
'{"qom-type":"memory-backend-file","id":"ram-node0","mem-path":"/var/lib/libvirt/qemu/ram/-1-QEMUGuest1/ram-node0","share":false,"size":1073741824,"host-nodes":[0,1,2,3],"policy":"bind"}'
\
-numa node,nodeid=0,cpus=0,memdev=ram-node0 \
-object
'{"qom-type":"thread-context","id":"tc-ram-node1","node-affinity":[0,1,2,3]}'
\
-object
'{"qom-type":"memory-backend-file","id":"ram-node1","mem-path":"/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1","share":true,"prealloc":true,"size":1073741824,"host-nodes":[0,1,2,3],"policy":"bind","prealloc-context":"tc-ram-node1"}'
\
-numa node,nodeid=1,cpus=1,memdev=ram-node1 \
--object
'{"qom-type":"thread-context","id":"tc-ram-node2","node-affinity":[0,1,2,3]}'
\
--object
'{"qom-type":"memory-backend-file","id":"ram-node2","mem-path":"/var/lib/libvirt/qemu/ram/-1-QEMUGuest1/ram-node2","share":false,"size":1073741824,"host-nodes":[0,1,2,3],"policy":"bind","prealloc-context":"tc-ram-node2"}'
\
+-object
'{"qom-type":"memory-backend-file","id":"ram-node2","mem-path":"/var/lib/libvirt/qemu/ram/-1-QEMUGuest1/ram-node2","share":false,"size":1073741824,"host-nodes":[0,1,2,3],"policy":"bind"}'
\
-numa node,nodeid=2,cpus=2,memdev=ram-node2 \
--object
'{"qom-type":"thread-context","id":"tc-ram-node3","node-affinity":[3]}'
\
--object
'{"qom-type":"memory-backend-file","id":"ram-node3","mem-path":"/var/lib/libvirt/qemu/ram/-1-QEMUGuest1/ram-node3","share":false,"size":1073741824,"host-nodes":[3],"policy":"bind","prealloc-context":"tc-ram-node3"}'
\
+-object
'{"qom-type":"memory-backend-file","id":"ram-node3","mem-path":"/var/lib/libvirt/qemu/ram/-1-QEMUGuest1/ram-node3","share":false,"size":1073741824,"host-nodes":[3],"policy":"bind"}'
\
-numa node,nodeid=3,cpus=3,memdev=ram-node3 \
-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
-display none \
diff --git a/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest.args
b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest.args
index 04876fc044..5aa8110aeb 100644
--- a/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest.args
@@ -32,8 +32,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
-device
'{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}'
\
-object
'{"qom-type":"memory-backend-ram","id":"memvirtiomem0","reserve":false,"size":1073741824}'
\
-device
'{"driver":"virtio-mem-pci","node":0,"block-size":2097152,"requested-size":536870912,"memdev":"memvirtiomem0","id":"virtiomem0","bus":"pci.0","addr":"0x2"}'
\
--object
'{"qom-type":"thread-context","id":"tc-memvirtiomem1","node-affinity":[1,2,3]}'
\
--object
'{"qom-type":"memory-backend-file","id":"memvirtiomem1","mem-path":"/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1","reserve":false,"size":2147483648,"host-nodes":[1,2,3],"policy":"bind","prealloc-context":"tc-memvirtiomem1"}'
\
+-object
'{"qom-type":"memory-backend-file","id":"memvirtiomem1","mem-path":"/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1","reserve":false,"size":2147483648,"host-nodes":[1,2,3],"policy":"bind"}'
\
-device
'{"driver":"virtio-mem-pci","node":0,"block-size":2097152,"requested-size":1073741824,"memdev":"memvirtiomem1","prealloc":true,"id":"virtiomem1","bus":"pci.1","addr":"0x1"}'
\
-blockdev
'{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1","node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}'
\
-blockdev
'{"node-name":"libvirt-1-format","read-only":false,"driver":"raw","file":"libvirt-1-storage"}'
\
diff --git a/tests/qemuxml2argvdata/numatune-memnode.x86_64-latest.args
b/tests/qemuxml2argvdata/numatune-memnode.x86_64-latest.args
index f4ef91006f..7cb7e659a4 100644
--- a/tests/qemuxml2argvdata/numatune-memnode.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/numatune-memnode.x86_64-latest.args
@@ -16,14 +16,11 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest/.config \
-m 24105 \
-overcommit mem-lock=off \
-smp 32,sockets=32,cores=1,threads=1 \
--object
'{"qom-type":"thread-context","id":"tc-ram-node0","node-affinity":[3]}'
\
--object
'{"qom-type":"memory-backend-ram","id":"ram-node0","size":20971520,"host-nodes":[3],"policy":"preferred","prealloc-context":"tc-ram-node0"}'
\
+-object
'{"qom-type":"memory-backend-ram","id":"ram-node0","size":20971520,"host-nodes":[3],"policy":"preferred"}'
\
-numa node,nodeid=0,cpus=0,memdev=ram-node0 \
--object
'{"qom-type":"thread-context","id":"tc-ram-node1","node-affinity":[0,1,2,3,4,5,6,7]}'
\
--object
'{"qom-type":"memory-backend-ram","id":"ram-node1","size":676331520,"host-nodes":[0,1,2,3,4,5,6,7],"policy":"bind","prealloc-context":"tc-ram-node1"}'
\
+-object
'{"qom-type":"memory-backend-ram","id":"ram-node1","size":676331520,"host-nodes":[0,1,2,3,4,5,6,7],"policy":"bind"}'
\
-numa node,nodeid=1,cpus=1-27,cpus=29,memdev=ram-node1 \
--object
'{"qom-type":"thread-context","id":"tc-ram-node2","node-affinity":[1,2,5,7]}'
\
--object
'{"qom-type":"memory-backend-ram","id":"ram-node2","size":24578621440,"host-nodes":[1,2,5,7],"policy":"bind","prealloc-context":"tc-ram-node2"}'
\
+-object
'{"qom-type":"memory-backend-ram","id":"ram-node2","size":24578621440,"host-nodes":[1,2,5,7],"policy":"bind"}'
\
-numa node,nodeid=2,cpus=28,cpus=30-31,memdev=ram-node2 \
-uuid 9f4b6512-e73a-4a25-93e8-5307802821ce \
-display none \
diff --git a/tests/qemuxml2argvdata/numatune-system-memory.x86_64-latest.args
b/tests/qemuxml2argvdata/numatune-system-memory.x86_64-latest.args
index 125dc43153..fd93abe3eb 100644
--- a/tests/qemuxml2argvdata/numatune-system-memory.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/numatune-system-memory.x86_64-latest.args
@@ -14,8 +14,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
-accel tcg \
-cpu qemu64 \
-m 214 \
--object
'{"qom-type":"thread-context","id":"tc-pc.ram","node-affinity":[0]}'
\
--object
'{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264,"host-nodes":[0],"policy":"bind","prealloc-context":"tc-pc.ram"}'
\
+-object
'{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264,"host-nodes":[0],"policy":"bind"}'
\
-overcommit mem-lock=off \
-smp 2,sockets=2,cores=1,threads=1 \
-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
--
2.38.2