From 4f958b0b1d7e8a6e5636afc0565f765e93eb43b0 Mon Sep 17 00:00:00 2001
From: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
Date: Tue, 5 Oct 2010 10:35:02 -0300
Subject: [PATCH] kvm: Introduce support for -mem-path

Using hugepages, KVM instances can get a good performance boost. To
activate that, we need to pass the -mem-path argument to KVM along with
the mount point of the hugetlbfs file system on the node.

For the sake of memory availability computation, we use the -mem-prealloc
argument when enabling hugepages, so KVM will reserve all hugepages it
needs when it starts. This avoids allocating an instance on a node that
will not have enough pages in case other instance needs more than what
is available after it boots.

Signed-off-by: Miguel Di Ciurcio Filho <miguel.filho@gmail.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 lib/constants.py         |  3 +++
 lib/hypervisor/hv_kvm.py |  6 ++++++
 man/gnt-instance.sgml    | 13 +++++++++++++
 3 files changed, 22 insertions(+)

diff --git a/lib/constants.py b/lib/constants.py
index 17c9a2e19..2941c8af3 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -558,6 +558,7 @@ HV_KVM_FLAG = "kvm_flag"
 HV_VHOST_NET = "vhost_net"
 HV_KVM_USE_CHROOT = "use_chroot"
 HV_CPU_MASK = "cpu_mask"
+HV_MEM_PATH = "mem_path"
 
 HVS_PARAMETER_TYPES = {
   HV_BOOT_ORDER: VTYPE_STRING,
@@ -594,6 +595,7 @@ HVS_PARAMETER_TYPES = {
   HV_VHOST_NET: VTYPE_BOOL,
   HV_KVM_USE_CHROOT: VTYPE_BOOL,
   HV_CPU_MASK: VTYPE_STRING,
+  HV_MEM_PATH: VTYPE_STRING,
   }
 
 HVS_PARAMETERS = frozenset(HVS_PARAMETER_TYPES.keys())
@@ -934,6 +936,7 @@ HVC_DEFAULTS = {
     HV_KVM_FLAG: "",
     HV_VHOST_NET: False,
     HV_KVM_USE_CHROOT: False,
+    HV_MEM_PATH: "",
     },
   HT_FAKE: {
     },
diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py
index f18bc6994..205e57120 100644
--- a/lib/hypervisor/hv_kvm.py
+++ b/lib/hypervisor/hv_kvm.py
@@ -205,6 +205,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
       hv_base.ParamInSet(False, constants.HT_KVM_FLAG_VALUES),
     constants.HV_VHOST_NET: hv_base.NO_CHECK,
     constants.HV_KVM_USE_CHROOT: hv_base.NO_CHECK,
+    constants.HV_MEM_PATH: hv_base.OPT_DIR_CHECK,
     }
 
   _MIGRATION_STATUS_RE = re.compile('Migration\s+status:\s+(\w+)',
@@ -567,6 +568,11 @@ class KVMHypervisor(hv_base.BaseHypervisor):
         root_append.append('console=ttyS0,38400')
       kvm_cmd.extend(['-append', ' '.join(root_append)])
 
+    mem_path = hvp[constants.HV_MEM_PATH]
+    if mem_path:
+      kvm_cmd.extend(["-mem-path", mem_path])
+      kvm_cmd.extend(["-mem-prealloc"])
+
     mouse_type = hvp[constants.HV_USB_MOUSE]
     vnc_bind_address = hvp[constants.HV_VNC_BIND_ADDRESS]
 
diff --git a/man/gnt-instance.sgml b/man/gnt-instance.sgml
index 9be66b1b5..560b66560 100644
--- a/man/gnt-instance.sgml
+++ b/man/gnt-instance.sgml
@@ -658,6 +658,19 @@
               </listitem>
             </varlistentry>
 
+            <varlistentry>
+              <term>mem_path</term>
+              <listitem>
+                <simpara>Valid for the KVM hypervisor.</simpara>
+
+                <simpara>This option passes the -mem-path argument to kvm with
+                the path (on the node) to the mount point of the hugetlbfs
+                file system, along with the -mem-prealloc argument too.
+                </simpara>
+
+              </listitem>
+            </varlistentry>
+
             <varlistentry>
               <term>use_chroot</term>
               <listitem>
-- 
GitLab