Browse code

Enable Kernel Samepage Merging by default

In an effort to reduce memory consumption enable KSM by default. The
biggest win here is when using libvirt with nova or ironic with its
fake baremetal instances. In theory any process that runs duplicates
with mergeable memory will benefit though.

Change-Id: I4c5addfd3e83b6516023b36cbaabd5169f0d5ceb

Clark Boylan authored on 2017/03/18 04:54:30
Showing 2 changed files
... ...
@@ -1006,6 +1006,22 @@ init_service_check
1006 1006
 # Save configuration values
1007 1007
 save_stackenv $LINENO
1008 1008
 
1009
+# Kernel Samepage Merging (KSM)
1010
+# -----------------------------
1011
+
1012
+# Processes that mark their memory as mergeable can share identical memory
1013
+# pages if KSM is enabled. This is particularly useful for nova + libvirt
1014
+# backends but any other setup that marks its memory as mergeable can take
1015
+# advantage. The drawback is there is higher cpu load; however, we tend to
1016
+# be memory bound not cpu bound so enable KSM by default but allow people
1017
+# to opt out if the CPU time is more important to them.
1018
+
1019
+if [[ "ENABLE_KSM" == "True" ]] ; then
1020
+    if [[ -f /sys/kernel/mm/ksm/run ]] ; then
1021
+        sudo sh -c "echo 1 > /sys/kernel/mm/ksm/run"
1022
+    fi
1023
+fi
1024
+
1009 1025
 
1010 1026
 # Start Services
1011 1027
 # ==============
... ...
@@ -104,6 +104,14 @@ if [[ "$USE_SYSTEMD" == "True" ]]; then
104 104
     USE_SCREEN=False
105 105
 fi
106 106
 
107
+# Whether or not to enable Kernel Samepage Merging (KSM) if available.
108
+# This allows programs that mark their memory as mergeable to share
109
+# memory pages if they are identical. This is particularly useful with
110
+# libvirt backends. This reduces memory useage at the cost of CPU overhead
111
+# to scan memory. We default to enabling it because we tend to be more
112
+# memory constrained than CPU bound.
113
+ENABLE_KSM=$(trueorfalse True ENABLE_KSM)
114
+
107 115
 # When using screen, should we keep a log file on disk?  You might
108 116
 # want this False if you have a long-running setup where verbose logs
109 117
 # can fill-up the host.