[PATCH] qemu: Increase RLIMIT_MEMLOCK when memoryBacking/locked is used

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

 



If a domain is configured to have all its memory locked, we need to
increase RLIMIT_MEMLOCK so that QEMU is actually allowed to lock the
memory.
---
 src/qemu/qemu_command.c | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index c268a3a..8e2de09 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6440,6 +6440,7 @@ qemuBuildCommandLine(virConnectPtr conn,
     int spice = 0;
     int usbcontroller = 0;
     bool usblegacy = false;
+    bool mlock;
     int contOrder[] = {
         /* We don't add an explicit IDE or FD controller because the
          * provided PIIX4 device already includes one. It isn't possible to
@@ -6551,6 +6552,7 @@ qemuBuildCommandLine(virConnectPtr conn,
         virCommandAddArgFormat(cmd, "mlock=%s",
                                def->mem.locked ? "on" : "off");
     }
+    mlock = def->mem.locked;
 
     virCommandAddArg(cmd, "-smp");
     if (!(smp = qemuBuildSmpArgStr(def, qemuCaps)))
@@ -8191,22 +8193,13 @@ qemuBuildCommandLine(virConnectPtr conn,
 
             if (hostdev->source.subsys.u.pci.backend
                 == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
-                unsigned long long memKB;
-
                 if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
                     virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                                    _("VFIO PCI device assignment is not "
                                      "supported by this version of qemu"));
                     goto error;
                 }
-                /* VFIO requires all of the guest's memory to be
-                 * locked resident, plus some amount for IO
-                 * space. Alex Williamson suggested adding 1GiB for IO
-                 * space just to be safe (some finer tuning might be
-                 * nice, though).
-                 */
-                memKB = def->mem.max_balloon + (1024 * 1024);
-                virCommandSetMaxMemLock(cmd, memKB * 1024);
+                mlock = true;
             }
 
             if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) {
@@ -8425,6 +8418,24 @@ qemuBuildCommandLine(virConnectPtr conn,
         goto error;
     }
 
+    if (mlock) {
+        unsigned long long memKB;
+        /* VFIO requires all of the guest's memory to be locked resident,
+         * plus some amount for IO space. Alex Williamson suggested
+         * adding 1GiB for IO space just to be safe (some finer tuning
+         * might be nice, though).
+         *
+         * If memory hard_limit is configured, we can use it directly as
+         * there is no sense to set MEMLOCK limit beyond it. Also we can
+         * safely use it instead of any magically computed value.
+         */
+        if (def->mem.hard_limit)
+            memKB = def->mem.hard_limit;
+        else
+            memKB = def->mem.max_balloon + (1024 * 1024);
+        virCommandSetMaxMemLock(cmd, memKB * 1024);
+    }
+
     virObjectUnref(cfg);
     return cmd;
 
-- 
1.8.2.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[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]