[PATCH v1 3/5] qemu: Move @prealloc into qemuBuildMemoryGetPagesize()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The qemuBuildMemoryGetPagesize() function has everything is needs
to decide whether preallocation is needed or not. Move the logic
from qemuBuildMemoryBackendProps() into
qemuBuildMemoryGetPagesize().

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/qemu/qemu_command.c | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 858aa0211a..9ab2b25fe2 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3609,12 +3609,14 @@ qemuBuildMemoryGetPagesize(virQEMUDriverConfig *cfg,
                            const virDomainMemoryDef *mem,
                            unsigned long long *pagesizeRet,
                            bool *needHugepageRet,
-                           bool *useHugepageRet)
+                           bool *useHugepageRet,
+                           bool *preallocRet)
 {
     const long system_page_size = virGetSystemPageSizeKB();
     unsigned long long pagesize = mem->pagesize;
     bool needHugepage = !!pagesize;
     bool useHugepage = !!pagesize;
+    bool prealloc = false;
 
     if (pagesize == 0) {
         virDomainHugePage *master_hugepage = NULL;
@@ -3675,9 +3677,23 @@ qemuBuildMemoryGetPagesize(virQEMUDriverConfig *cfg,
             return -1;
     }
 
+    if (def->mem.allocation == VIR_DOMAIN_MEMORY_ALLOCATION_IMMEDIATE)
+        prealloc = true;
+
+    /* If the NVDIMM is a real device then there's nothing to prealloc.
+     * If anything, we would be only wearing off the device.
+     * Similarly, virtio-pmem-pci doesn't need prealloc either. */
+    if (mem->nvdimmPath && !mem->nvdimmPmem &&
+        mem->model != VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM)
+        prealloc = true;
+
+    if (useHugepage)
+        prealloc = true;
+
     *pagesizeRet = pagesize;
     *needHugepageRet = needHugepage;
     *useHugepageRet = useHugepage;
+    *preallocRet = prealloc;
 
     return 0;
 }
@@ -3767,15 +3783,12 @@ qemuBuildMemoryBackendProps(virJSONValue **backendProps,
     if (discard == VIR_TRISTATE_BOOL_ABSENT)
         discard = def->mem.discard;
 
-    if (def->mem.allocation == VIR_DOMAIN_MEMORY_ALLOCATION_IMMEDIATE)
-        prealloc = true;
-
     if (virDomainNumatuneGetMode(def->numa, mem->targetNode, &mode) < 0 &&
         virDomainNumatuneGetMode(def->numa, -1, &mode) < 0)
         mode = VIR_DOMAIN_NUMATUNE_MEM_STRICT;
 
     if (qemuBuildMemoryGetPagesize(cfg, def, mem, &pagesize,
-                                   &needHugepage, &useHugepage) < 0)
+                                   &needHugepage, &useHugepage, &prealloc) < 0)
         return -1;
 
     props = virJSONValueNewObject();
@@ -3784,13 +3797,10 @@ qemuBuildMemoryBackendProps(virJSONValue **backendProps,
         def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_MEMFD) {
         backendType = "memory-backend-memfd";
 
-        if (useHugepage) {
-            if (virJSONValueObjectAdd(&props, "b:hugetlb", useHugepage, NULL) < 0 ||
-                virJSONValueObjectAdd(&props, "U:hugetlbsize", pagesize << 10, NULL) < 0) {
-                return -1;
-            }
-
-            prealloc = true;
+        if (useHugepage &&
+            (virJSONValueObjectAdd(&props, "b:hugetlb", useHugepage, NULL) < 0 ||
+             virJSONValueObjectAdd(&props, "U:hugetlbsize", pagesize << 10, NULL) < 0)) {
+            return -1;
         }
 
         if (qemuBuildMemoryBackendPropsShare(props, memAccess) < 0)
@@ -3804,15 +3814,9 @@ qemuBuildMemoryBackendProps(virJSONValue **backendProps,
 
         if (mem->nvdimmPath) {
             memPath = g_strdup(mem->nvdimmPath);
-            /* If the NVDIMM is a real device then there's nothing to prealloc.
-             * If anything, we would be only wearing off the device.
-             * Similarly, virtio-pmem-pci doesn't need prealloc either. */
-            if (!mem->nvdimmPmem && mem->model != VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM)
-                prealloc = true;
         } else if (useHugepage) {
             if (qemuGetDomainHupageMemPath(priv->driver, def, pagesize, &memPath) < 0)
                 return -1;
-            prealloc = true;
         } else {
             /* We can have both pagesize and mem source. If that's the case,
              * prefer hugepages as those are more specific. */
-- 
2.34.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux