43fe83
From ecb424b6ca400a126e5677a1f573e3688490d9e6 Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <ecb424b6ca400a126e5677a1f573e3688490d9e6.1377873642.git.jdenemar@redhat.com>
43fe83
From: Michal Privoznik <mprivozn@redhat.com>
43fe83
Date: Mon, 26 Aug 2013 17:41:45 +0200
43fe83
Subject: [PATCH] qemu: Drop qemuDomainMemoryLimit
43fe83
43fe83
https://bugzilla.redhat.com/show_bug.cgi?id=1001143
43fe83
43fe83
This function is to guess the correct limit for maximal memory
43fe83
usage by qemu for given domain. This can never be guessed
43fe83
correctly, not to mention all the pains and sleepless nights this
43fe83
code has caused. Once somebody discovers algorithm to solve the
43fe83
Halting Problem, we can compute the limit algorithmically. But
43fe83
till then, this code should never see the light of the release
43fe83
again.
43fe83
(cherry picked from commit 16bcb3b61675a88bff00317336b9610080c31000)
43fe83
---
43fe83
 src/qemu/qemu_cgroup.c  |  3 +--
43fe83
 src/qemu/qemu_command.c |  2 +-
43fe83
 src/qemu/qemu_domain.c  | 49 -------------------------------------------------
43fe83
 src/qemu/qemu_domain.h  |  2 --
43fe83
 src/qemu/qemu_hotplug.c |  2 +-
43fe83
 5 files changed, 3 insertions(+), 55 deletions(-)
43fe83
43fe83
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
43fe83
index 787ddeb..f07c450 100644
43fe83
--- a/src/qemu/qemu_cgroup.c
43fe83
+++ b/src/qemu/qemu_cgroup.c
43fe83
@@ -428,8 +428,7 @@ qemuSetupMemoryCgroup(virDomainObjPtr vm)
43fe83
         }
43fe83
     }
43fe83
 
43fe83
-    if (virCgroupSetMemoryHardLimit(priv->cgroup,
43fe83
-                                    qemuDomainMemoryLimit(vm->def)) < 0)
43fe83
+    if (virCgroupSetMemoryHardLimit(priv->cgroup, vm->def->mem.hard_limit) < 0)
43fe83
         return -1;
43fe83
 
43fe83
     if (vm->def->mem.soft_limit != 0 &&
43fe83
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
43fe83
index af8a5b4..7bbfd03 100644
43fe83
--- a/src/qemu/qemu_command.c
43fe83
+++ b/src/qemu/qemu_command.c
43fe83
@@ -9240,7 +9240,7 @@ qemuBuildCommandLine(virConnectPtr conn,
43fe83
     }
43fe83
 
43fe83
     if (mlock)
43fe83
-        virCommandSetMaxMemLock(cmd, qemuDomainMemoryLimit(def) * 1024);
43fe83
+        virCommandSetMaxMemLock(cmd, def->mem.hard_limit * 1024);
43fe83
 
43fe83
     virObjectUnref(cfg);
43fe83
     return cmd;
43fe83
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
43fe83
index 393af6b..7f4d17d 100644
43fe83
--- a/src/qemu/qemu_domain.c
43fe83
+++ b/src/qemu/qemu_domain.c
43fe83
@@ -2306,55 +2306,6 @@ cleanup:
43fe83
     return ret;
43fe83
 }
43fe83
 
43fe83
-
43fe83
-unsigned long long
43fe83
-qemuDomainMemoryLimit(virDomainDefPtr def)
43fe83
-{
43fe83
-    unsigned long long mem;
43fe83
-    size_t i;
43fe83
-
43fe83
-    if (def->mem.hard_limit) {
43fe83
-        mem = def->mem.hard_limit;
43fe83
-    } else {
43fe83
-        /* If there is no hard_limit set, compute a reasonable one to avoid
43fe83
-         * system thrashing caused by exploited qemu.  A 'reasonable
43fe83
-         * limit' has been chosen:
43fe83
-         *     (1 + k) * (domain memory + total video memory) + (32MB for
43fe83
-         *     cache per each disk) + F
43fe83
-         * where k = 0.5 and F = 400MB.  The cache for disks is important as
43fe83
-         * kernel cache on the host side counts into the RSS limit.
43fe83
-         * Moreover, VFIO requires some amount for IO space. Alex Williamson
43fe83
-         * suggested adding 1GiB for IO space just to be safe (some finer
43fe83
-         * tuning might be nice, though).
43fe83
-         *
43fe83
-         * Technically, the disk cache does not have to be included in
43fe83
-         * RLIMIT_MEMLOCK but it doesn't hurt as it's just an upper limit and
43fe83
-         * it makes this function and its usage simpler.
43fe83
-         */
43fe83
-        mem = def->mem.max_balloon;
43fe83
-        for (i = 0; i < def->nvideos; i++)
43fe83
-            mem += def->videos[i]->vram;
43fe83
-        mem *= 1.5;
43fe83
-        mem += def->ndisks * 32768;
43fe83
-        mem += 409600;
43fe83
-
43fe83
-        for (i = 0; i < def->nhostdevs; i++) {
43fe83
-            virDomainHostdevDefPtr hostdev = def->hostdevs[i];
43fe83
-            if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
43fe83
-                hostdev->source.subsys.type ==
43fe83
-                    VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
43fe83
-                hostdev->source.subsys.u.pci.backend ==
43fe83
-                    VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
43fe83
-                mem += 1024 * 1024;
43fe83
-                break;
43fe83
-            }
43fe83
-        }
43fe83
-    }
43fe83
-
43fe83
-    return mem;
43fe83
-}
43fe83
-
43fe83
-
43fe83
 int
43fe83
 qemuDomainUpdateDeviceList(virQEMUDriverPtr driver,
43fe83
                            virDomainObjPtr vm)
43fe83
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
43fe83
index 0a4a51e..21f116c 100644
43fe83
--- a/src/qemu/qemu_domain.h
43fe83
+++ b/src/qemu/qemu_domain.h
43fe83
@@ -365,8 +365,6 @@ extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks;
43fe83
 extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace;
43fe83
 extern virDomainDefParserConfig virQEMUDriverDomainDefParserConfig;
43fe83
 
43fe83
-unsigned long long qemuDomainMemoryLimit(virDomainDefPtr def);
43fe83
-
43fe83
 int qemuDomainUpdateDeviceList(virQEMUDriverPtr driver,
43fe83
                                virDomainObjPtr vm);
43fe83
 
43fe83
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
43fe83
index b1f4586..89df4ad 100644
43fe83
--- a/src/qemu/qemu_hotplug.c
43fe83
+++ b/src/qemu/qemu_hotplug.c
43fe83
@@ -1035,7 +1035,7 @@ int qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver,
43fe83
          */
43fe83
         vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
43fe83
         virProcessSetMaxMemLock(vm->pid,
43fe83
-                                qemuDomainMemoryLimit(vm->def) * 1024);
43fe83
+                                vm->def->mem.hard_limit * 1024);
43fe83
         vm->def->hostdevs[vm->def->nhostdevs--] = NULL;
43fe83
     }
43fe83
 
43fe83
-- 
43fe83
1.8.3.2
43fe83