]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuBuildThreadContextProps: Generate ThreadContext less frequently
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 5 Jan 2023 08:51:07 +0000 (09:51 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 13 Jan 2023 07:43:30 +0000 (08:43 +0100)
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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_command.c
tests/qemuxml2argvdata/hugepages-memaccess2.x86_64-latest.args
tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest.args
tests/qemuxml2argvdata/numatune-memnode.x86_64-latest.args
tests/qemuxml2argvdata/numatune-system-memory.x86_64-latest.args

index d03ddb08868655c1b2ad3dbdd284840e98628154..b96f2d33c1582489253051bc5ba6d9d4936c6fd6 100644 (file)
@@ -3658,6 +3658,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",
@@ -3680,11 +3684,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;
index f73da5865dd392775bbc2b5b588becda0bab4ce3..fedc9fe1cea22f7a7d5591b7cebf3363c2f71f4a 100644 (file)
@@ -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 \
index 04876fc04417b5e3fa85c111fee34cc7b48500e7..5aa8110aebb48e847deb20b5ab3cd5089c5f0a69 100644 (file)
@@ -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"}' \
index f4ef91006f20409e32aae88890a8db2522ae2730..7cb7e659a43fcce741b85c02cf0f1a2ebc5a3255 100644 (file)
@@ -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 \
index 125dc431532350aadd72f4a94ad84befd2dc946c..fd93abe3eb2fb260be1289377b1ea8b89cbc1974 100644 (file)
@@ -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 \