render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c480ed
From af079d99de7c556c3b9bb10037dae90e0f23f38a Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <af079d99de7c556c3b9bb10037dae90e0f23f38a@dist-git>
c480ed
From: Michal Privoznik <mprivozn@redhat.com>
c480ed
Date: Tue, 18 Dec 2018 11:47:36 +0100
c480ed
Subject: [PATCH] qemu: Don't use -mem-prealloc among with .prealloc=yes
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
https://bugzilla.redhat.com/show_bug.cgi?id=1624223
c480ed
c480ed
There are two ways to request memory preallocation on cmd line:
c480ed
-mem-prealloc and .prealloc attribute for a memory-backend-file.
c480ed
However, as it turns out it's not safe to use both at the same
c480ed
time. If -mem-prealloc is used then qemu will fully allocate the
c480ed
memory (this is done by actually touching every page that has
c480ed
been allocated). Then, if .prealloc=yes is specified,
c480ed
mbind(flags = MPOL_MF_STRICT | MPOL_MF_MOVE) is called which:
c480ed
c480ed
a) has to (possibly) move the memory to a different NUMA node,
c480ed
b) can have no effect when hugepages are in play (thus ignoring user
c480ed
request to place memory on desired NUMA nodes).
c480ed
c480ed
Prefer -mem-prealloc as it is more backward compatible
c480ed
compared to switching to "-numa node,memdev=  + -object
c480ed
memory-backend-file".
c480ed
c480ed
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
c480ed
Reviewed-by: John Ferlan <jferlan@redhat.com>
c480ed
(cherry picked from commit c658764decf357ef2a064f09235fb6b8bd027f8b)
c480ed
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
c480ed
c480ed
Conflicts:
c480ed
src/qemu/qemu_command.c:
c480ed
src/qemu/qemu_domain.c:
c480ed
src/qemu/qemu_domain.h: Context mostly, the upstream code
c480ed
                        diverged.
c480ed
c480ed
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
c480ed
Message-Id: <37771aafbb9d1855721efde7ade34c7b98fb1fc7.1545129996.git.mprivozn@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/qemu/qemu_command.c                       | 26 ++++++++++++-------
c480ed
 src/qemu/qemu_domain.c                        |  7 +++++
c480ed
 src/qemu/qemu_domain.h                        |  3 +++
c480ed
 .../hugepages-numa-default-dimm.args          |  2 +-
c480ed
 4 files changed, 28 insertions(+), 10 deletions(-)
c480ed
c480ed
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
c480ed
index fa2b904239..7ffc4358e3 100644
c480ed
--- a/src/qemu/qemu_command.c
c480ed
+++ b/src/qemu/qemu_command.c
c480ed
@@ -3185,11 +3185,13 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps,
c480ed
         if (useHugepage) {
c480ed
             if (qemuGetDomainHupageMemPath(def, cfg, pagesize, &memPath) < 0)
c480ed
                 goto cleanup;
c480ed
-            prealloc = true;
c480ed
+            if (!priv->memPrealloc)
c480ed
+                prealloc = true;
c480ed
         } else if (mem->nvdimmPath) {
c480ed
             if (VIR_STRDUP(memPath, mem->nvdimmPath) < 0)
c480ed
                 goto cleanup;
c480ed
-            prealloc = true;
c480ed
+            if (!priv->memPrealloc)
c480ed
+                prealloc = true;
c480ed
         } else {
c480ed
             /* We can have both pagesize and mem source. If that's the case,
c480ed
              * prefer hugepages as those are more specific. */
c480ed
@@ -7603,7 +7605,8 @@ qemuBuildSmpCommandLine(virCommandPtr cmd,
c480ed
 static int
c480ed
 qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
c480ed
                     const virDomainDef *def,
c480ed
-                    virCommandPtr cmd)
c480ed
+                    virCommandPtr cmd,
c480ed
+                    qemuDomainObjPrivatePtr priv)
c480ed
 {
c480ed
     const long system_page_size = virGetSystemPageSizeKB();
c480ed
     char *mem_path = NULL;
c480ed
@@ -7624,8 +7627,10 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
c480ed
     if (qemuGetDomainHupageMemPath(def, cfg, def->mem.hugepages[0].size, &mem_path) < 0)
c480ed
         return -1;
c480ed
 
c480ed
-    if (def->mem.allocation != VIR_DOMAIN_MEMORY_ALLOCATION_IMMEDIATE)
c480ed
+    if (def->mem.allocation != VIR_DOMAIN_MEMORY_ALLOCATION_IMMEDIATE) {
c480ed
         virCommandAddArgList(cmd, "-mem-prealloc", NULL);
c480ed
+        priv->memPrealloc = true;
c480ed
+    }
c480ed
 
c480ed
     virCommandAddArgList(cmd, "-mem-path", mem_path, NULL);
c480ed
     VIR_FREE(mem_path);
c480ed
@@ -7638,7 +7643,8 @@ static int
c480ed
 qemuBuildMemCommandLine(virCommandPtr cmd,
c480ed
                         virQEMUDriverConfigPtr cfg,
c480ed
                         const virDomainDef *def,
c480ed
-                        virQEMUCapsPtr qemuCaps)
c480ed
+                        virQEMUCapsPtr qemuCaps,
c480ed
+                        qemuDomainObjPrivatePtr priv)
c480ed
 {
c480ed
     if (qemuDomainDefValidateMemoryHotplug(def, qemuCaps, NULL) < 0)
c480ed
         return -1;
c480ed
@@ -7657,15 +7663,17 @@ qemuBuildMemCommandLine(virCommandPtr cmd,
c480ed
                               virDomainDefGetMemoryInitial(def) / 1024);
c480ed
     }
c480ed
 
c480ed
-    if (def->mem.allocation == VIR_DOMAIN_MEMORY_ALLOCATION_IMMEDIATE)
c480ed
+    if (def->mem.allocation == VIR_DOMAIN_MEMORY_ALLOCATION_IMMEDIATE) {
c480ed
         virCommandAddArgList(cmd, "-mem-prealloc", NULL);
c480ed
+        priv->memPrealloc = true;
c480ed
+    }
c480ed
 
c480ed
     /*
c480ed
      * Add '-mem-path' (and '-mem-prealloc') parameter here if
c480ed
      * the hugepages and no numa node is specified.
c480ed
      */
c480ed
     if (!virDomainNumaGetNodeCount(def->numa) &&
c480ed
-        qemuBuildMemPathStr(cfg, def, cmd) < 0)
c480ed
+        qemuBuildMemPathStr(cfg, def, cmd, priv) < 0)
c480ed
         return -1;
c480ed
 
c480ed
     if (def->mem.locked && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_REALTIME_MLOCK)) {
c480ed
@@ -7772,7 +7780,7 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
c480ed
     }
c480ed
 
c480ed
     if (!needBackend &&
c480ed
-        qemuBuildMemPathStr(cfg, def, cmd) < 0)
c480ed
+        qemuBuildMemPathStr(cfg, def, cmd, priv) < 0)
c480ed
         goto cleanup;
c480ed
 
c480ed
     for (i = 0; i < ncells; i++) {
c480ed
@@ -10445,7 +10453,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
c480ed
     if (!migrateURI && !snapshot && qemuDomainAlignMemorySizes(def) < 0)
c480ed
         goto error;
c480ed
 
c480ed
-    if (qemuBuildMemCommandLine(cmd, cfg, def, qemuCaps) < 0)
c480ed
+    if (qemuBuildMemCommandLine(cmd, cfg, def, qemuCaps, priv) < 0)
c480ed
         goto error;
c480ed
 
c480ed
     if (qemuBuildSmpCommandLine(cmd, def) < 0)
c480ed
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
c480ed
index 8604385aa2..95b84af78a 100644
c480ed
--- a/src/qemu/qemu_domain.c
c480ed
+++ b/src/qemu/qemu_domain.c
c480ed
@@ -1936,6 +1936,8 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr priv)
c480ed
     VIR_FREE(priv->libDir);
c480ed
     VIR_FREE(priv->channelTargetDir);
c480ed
 
c480ed
+    priv->memPrealloc = false;
c480ed
+
c480ed
     /* remove automatic pinning data */
c480ed
     virBitmapFree(priv->autoNodeset);
c480ed
     priv->autoNodeset = NULL;
c480ed
@@ -2439,6 +2441,9 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf,
c480ed
 
c480ed
     qemuDomainObjPrivateXMLFormatPR(buf, priv);
c480ed
 
c480ed
+    if (priv->memPrealloc)
c480ed
+        virBufferAddLit(buf, "<memPrealloc/>\n");
c480ed
+
c480ed
     if (qemuDomainObjPrivateXMLFormatBlockjobs(buf, vm) < 0)
c480ed
         return -1;
c480ed
 
c480ed
@@ -2934,6 +2939,8 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
c480ed
     if (qemuDomainObjPrivateXMLParseBlockjobs(priv, ctxt) < 0)
c480ed
         goto error;
c480ed
 
c480ed
+    priv->memPrealloc = virXPathBoolean("boolean(./memPrealloc)", ctxt) == 1;
c480ed
+
c480ed
     return 0;
c480ed
 
c480ed
  error:
c480ed
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
c480ed
index cc406e3ca0..8463a8b706 100644
c480ed
--- a/src/qemu/qemu_domain.h
c480ed
+++ b/src/qemu/qemu_domain.h
c480ed
@@ -367,6 +367,9 @@ struct _qemuDomainObjPrivate {
c480ed
     /* qemuProcessStartCPUs stores the reason for starting vCPUs here for the
c480ed
      * RESUME event handler to use it */
c480ed
     virDomainRunningReason runningReason;
c480ed
+
c480ed
+    /* true if global -mem-prealloc appears on cmd line */
c480ed
+    bool memPrealloc;
c480ed
 };
c480ed
 
c480ed
 # define QEMU_DOMAIN_PRIVATE(vm) \
c480ed
diff --git a/tests/qemuxml2argvdata/hugepages-numa-default-dimm.args b/tests/qemuxml2argvdata/hugepages-numa-default-dimm.args
c480ed
index 855966a137..e7294a0882 100644
c480ed
--- a/tests/qemuxml2argvdata/hugepages-numa-default-dimm.args
c480ed
+++ b/tests/qemuxml2argvdata/hugepages-numa-default-dimm.args
c480ed
@@ -13,7 +13,7 @@ QEMU_AUDIO_DRV=none \
c480ed
 -mem-prealloc \
c480ed
 -mem-path /dev/hugepages2M/libvirt/qemu/-1-fedora \
c480ed
 -numa node,nodeid=0,cpus=0-1,mem=1024 \
c480ed
--object memory-backend-file,id=memdimm0,prealloc=yes,\
c480ed
+-object memory-backend-file,id=memdimm0,\
c480ed
 mem-path=/dev/hugepages1G/libvirt/qemu/-1-fedora,size=1073741824,\
c480ed
 host-nodes=1-3,policy=bind \
c480ed
 -device pc-dimm,node=0,memdev=memdimm0,id=dimm0,slot=0 \
c480ed
-- 
c480ed
2.22.0
c480ed