render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From ecb424b6ca400a126e5677a1f573e3688490d9e6 Mon Sep 17 00:00:00 2001
Message-Id: <ecb424b6ca400a126e5677a1f573e3688490d9e6.1377873642.git.jdenemar@redhat.com>
From: Michal Privoznik <mprivozn@redhat.com>
Date: Mon, 26 Aug 2013 17:41:45 +0200
Subject: [PATCH] qemu: Drop qemuDomainMemoryLimit

https://bugzilla.redhat.com/show_bug.cgi?id=1001143

This function is to guess the correct limit for maximal memory
usage by qemu for given domain. This can never be guessed
correctly, not to mention all the pains and sleepless nights this
code has caused. Once somebody discovers algorithm to solve the
Halting Problem, we can compute the limit algorithmically. But
till then, this code should never see the light of the release
again.
(cherry picked from commit 16bcb3b61675a88bff00317336b9610080c31000)
---
 src/qemu/qemu_cgroup.c  |  3 +--
 src/qemu/qemu_command.c |  2 +-
 src/qemu/qemu_domain.c  | 49 -------------------------------------------------
 src/qemu/qemu_domain.h  |  2 --
 src/qemu/qemu_hotplug.c |  2 +-
 5 files changed, 3 insertions(+), 55 deletions(-)

diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 787ddeb..f07c450 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -428,8 +428,7 @@ qemuSetupMemoryCgroup(virDomainObjPtr vm)
         }
     }
 
-    if (virCgroupSetMemoryHardLimit(priv->cgroup,
-                                    qemuDomainMemoryLimit(vm->def)) < 0)
+    if (virCgroupSetMemoryHardLimit(priv->cgroup, vm->def->mem.hard_limit) < 0)
         return -1;
 
     if (vm->def->mem.soft_limit != 0 &&
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index af8a5b4..7bbfd03 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9240,7 +9240,7 @@ qemuBuildCommandLine(virConnectPtr conn,
     }
 
     if (mlock)
-        virCommandSetMaxMemLock(cmd, qemuDomainMemoryLimit(def) * 1024);
+        virCommandSetMaxMemLock(cmd, def->mem.hard_limit * 1024);
 
     virObjectUnref(cfg);
     return cmd;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 393af6b..7f4d17d 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2306,55 +2306,6 @@ cleanup:
     return ret;
 }
 
-
-unsigned long long
-qemuDomainMemoryLimit(virDomainDefPtr def)
-{
-    unsigned long long mem;
-    size_t i;
-
-    if (def->mem.hard_limit) {
-        mem = def->mem.hard_limit;
-    } else {
-        /* If there is no hard_limit set, compute a reasonable one to avoid
-         * system thrashing caused by exploited qemu.  A 'reasonable
-         * limit' has been chosen:
-         *     (1 + k) * (domain memory + total video memory) + (32MB for
-         *     cache per each disk) + F
-         * where k = 0.5 and F = 400MB.  The cache for disks is important as
-         * kernel cache on the host side counts into the RSS limit.
-         * Moreover, VFIO requires some amount for IO space. Alex Williamson
-         * suggested adding 1GiB for IO space just to be safe (some finer
-         * tuning might be nice, though).
-         *
-         * Technically, the disk cache does not have to be included in
-         * RLIMIT_MEMLOCK but it doesn't hurt as it's just an upper limit and
-         * it makes this function and its usage simpler.
-         */
-        mem = def->mem.max_balloon;
-        for (i = 0; i < def->nvideos; i++)
-            mem += def->videos[i]->vram;
-        mem *= 1.5;
-        mem += def->ndisks * 32768;
-        mem += 409600;
-
-        for (i = 0; i < def->nhostdevs; i++) {
-            virDomainHostdevDefPtr hostdev = def->hostdevs[i];
-            if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
-                hostdev->source.subsys.type ==
-                    VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
-                hostdev->source.subsys.u.pci.backend ==
-                    VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
-                mem += 1024 * 1024;
-                break;
-            }
-        }
-    }
-
-    return mem;
-}
-
-
 int
 qemuDomainUpdateDeviceList(virQEMUDriverPtr driver,
                            virDomainObjPtr vm)
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 0a4a51e..21f116c 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -365,8 +365,6 @@ extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks;
 extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace;
 extern virDomainDefParserConfig virQEMUDriverDomainDefParserConfig;
 
-unsigned long long qemuDomainMemoryLimit(virDomainDefPtr def);
-
 int qemuDomainUpdateDeviceList(virQEMUDriverPtr driver,
                                virDomainObjPtr vm);
 
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index b1f4586..89df4ad 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1035,7 +1035,7 @@ int qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver,
          */
         vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
         virProcessSetMaxMemLock(vm->pid,
-                                qemuDomainMemoryLimit(vm->def) * 1024);
+                                vm->def->mem.hard_limit * 1024);
         vm->def->hostdevs[vm->def->nhostdevs--] = NULL;
     }
 
-- 
1.8.3.2