[libvirt] [PATCH v1 19/31] qemu: Take NVMe disks into account when calculating memlock limit

Michal Privoznik mprivozn at redhat.com
Thu Jul 11 15:54:06 UTC 2019


We have this beautiful function that does crystal ball
divination. The function is named
qemuDomainGetMemLockLimitBytes() and it calculates the upper
limit of how much locked memory is given guest going to need. The
function bases its guess on devices defined for a domain. For
instance, if there is a VFIO hostdev defined then it adds 1GiB to
the guessed maximum. Since NVMe disks are pretty much VFIO
hostdevs (but not quite), we have to do the same sorcery.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/qemu/qemu_domain.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index f09abc8a73..09e5ee37f4 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -10950,6 +10950,21 @@ qemuDomainGetMemLockLimitBytes(virDomainDefPtr def)
         }
     }
 
+    for (i = 0; i < def->ndisks; i++) {
+        virDomainDiskDefPtr disk = def->disks[i];
+        virStorageSourcePtr n;
+
+        if (!disk->src)
+            continue;
+
+        for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
+            if (n->type == VIR_STORAGE_TYPE_NVME) {
+                memKB = virDomainDefGetMemoryTotal(def) + 1024 * 1024;
+                goto done;
+            }
+        }
+    }
+
  done:
     return memKB << 10;
 }
-- 
2.21.0




More information about the libvir-list mailing list