Change in vdsm[master]: Add basic ballooning policy to vdsm

lvroyce at linux.vnet.ibm.com lvroyce at linux.vnet.ibm.com
Mon Jan 21 09:07:03 UTC 2013


Royce Lv has uploaded a new change for review.

Change subject: Add basic ballooning policy to vdsm
......................................................................

Add basic ballooning policy to vdsm

Change-Id: Ieffd589dbe524091d84c53cdf109a933b8a3eb4d
Signed-off-by: Royce Lv<lvroyce at linux.vnet.ibm.com>
---
M vdsm.spec.in
M vdsm/Makefile.am
A vdsm/mom_policies/balloon.policy
R vdsm/mom_policies/ksm.policy
4 files changed, 110 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/44/11244/1

diff --git a/vdsm.spec.in b/vdsm.spec.in
index 4c82e9c..e3e4a2a 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -646,7 +646,8 @@
 %attr (755,vdsm,kvm) %{_datadir}/%{vdsm_name}/nwfilter.py*
 %config(noreplace) %{_sysconfdir}/%{vdsm_name}/logger.conf
 %config(noreplace) %{_sysconfdir}/%{vdsm_name}/mom.conf
-%config(noreplace) %{_sysconfdir}/%{vdsm_name}/mom-policy-dir/mom.policy
+%config(noreplace) %{_sysconfdir}/%{vdsm_name}/mom-policy-dir/balloon.policy
+%config(noreplace) %{_sysconfdir}/%{vdsm_name}/mom-policy-dir/ksm.policy
 %config(noreplace) %{_sysconfdir}/logrotate.d/vdsm
 %config(noreplace) %{_sysconfdir}/rwtab.d/vdsm
 %config(noreplace) %{_sysconfdir}/sysctl.d/vdsm
diff --git a/vdsm/Makefile.am b/vdsm/Makefile.am
index 3b57693..5697380 100644
--- a/vdsm/Makefile.am
+++ b/vdsm/Makefile.am
@@ -126,7 +126,8 @@
 	logger.conf.in \
 	mk_sysprep_floppy.in \
 	mom.conf.in \
-	mom_policies/mom.policy \
+	mom_policies/balloon.policy \
+	mom_policies/ksm.policy \
 	sudoers.vdsm.in \
 	vdsmd.8.in \
 	vdsmd.init.in \
@@ -226,13 +227,16 @@
 
 install-data-mom:
 		$(MKDIR_P) $(DESTDIR)$(vdsmconfdir)/mom-policy-dir
-		$(INSTALL_DATA) mom_policies/mom.policy \
-			$(DESTDIR)$(vdsmconfdir)/mom-policy-dir/mom.policy
+		$(INSTALL_DATA) mom_policies/balloon.policy \
+			$(DESTDIR)$(vdsmconfdir)/mom-policy-dir/balloon.policy
+		$(INSTALL_DATA) mom_policies/ksm.policy \
+			$(DESTDIR)$(vdsmconfdir)/mom-policy-dir/ksm.policy
 		$(INSTALL_DATA) mom.conf \
 			$(DESTDIR)$(vdsmconfdir)/mom.conf
 
 uninstall-data-mom:
-		$(RM) $(DESTDIR)$(vdsmconfdir)/mom-policy-dir/mom.policy
+		$(RM) $(DESTDIR)$(vdsmconfdir)/mom-policy-dir/balloon.policy
+		$(RM) $(DESTDIR)$(vdsmconfdir)/mom-policy-dir/ksm.policy
 		$(RM) $(DESTDIR)$(vdsmconfdir)/mom.conf
 
 install-data-sudoers:
diff --git a/vdsm/mom_policies/balloon.policy b/vdsm/mom_policies/balloon.policy
new file mode 100644
index 0000000..bc2e237
--- /dev/null
+++ b/vdsm/mom_policies/balloon.policy
@@ -0,0 +1,100 @@
+### Auto-Balloon ###############################################################
+
+### Constants
+# If the percentage of host free memory drops below this value
+# then we will consider the host to be under memory pressure
+(defvar pressure_threshold 0.20)
+
+# If pressure threshold drops below this level, then the pressure
+# is critical and more aggressive ballooning will be employed.
+(defvar pressure_critical 0.05)
+
+# This is the minimum percentage of free memory that an unconstrained
+# guest would like to maintain
+(defvar min_guest_free_percent 0.20)
+
+# Don't change a guest's memory by more than this percent of total memory
+(defvar max_balloon_change_percent 0.05)
+
+# Only ballooning operations that change the balloon by this percentage
+# of current guest memory should be undertaken to avoid overhead
+(defvar min_balloon_change_percent 0.0025)
+
+### Helper functions
+# Check if the proposed new balloon value is a large-enough
+# change to justify a balloon operation.  This prevents us from
+# introducing overhead through lots of small ballooning operations
+(def change_big_enough (guest new_val)
+{
+    (if (> (abs (- new_val guest.balloon_cur))
+           (* min_balloon_change_percent guest.balloon_cur))
+        1 0)
+})
+
+(def shrink_guest (guest)
+{
+    # Determine the degree of host memory pressure
+    (if (<= host_free_percent pressure_critical)
+        # Pressure is critical:
+        #   Force guest to swap by making free memory negative
+        (defvar guest_free_percent (+ -0.05 host_free_percent))
+        # Normal pressure situation
+        #   Scale the guest free memory back according to host pressure
+        (defvar guest_free_percent (* min_guest_free_percent
+                                    (/ host_free_percent pressure_threshold))))
+
+    # Given current conditions, determine the ideal guest memory size
+    (defvar guest_used_mem (- (guest.StatAvg "balloon_cur")
+                              (guest.StatAvg "mem_unused")))
+    (defvar balloon_min (+ guest_used_mem
+                           (* guest_free_percent guest.balloon_cur)))
+    # But do not change it too fast
+    (defvar balloon_size (* guest.balloon_cur
+                            (- 1 max_balloon_change_percent)))
+    (if (< balloon_size balloon_min)
+        (set balloon_size balloon_min)
+        0)
+    # Set the new target for the BalloonController.  Only set it if the
+    # value makes sense and is a large enough change to be worth it.
+    (if (and (<= balloon_size guest.balloon_cur)
+            (change_big_enough guest balloon_size))
+        (guest.Control "balloon_target" balloon_size)
+        0)
+})
+
+(def grow_guest (guest)
+{
+    # There is only work to do if the guest is ballooned
+    (if (< guest.balloon_cur guest.balloon_max) {
+        # Minimally, increase so the guest has its desired free memory
+        (defvar guest_used_mem (- (guest.StatAvg "balloon_cur")
+                                  (guest.StatAvg "mem_unused")))
+        (defvar balloon_min (+ guest_used_mem (* min_guest_free_percent
+                                                 guest.balloon_max)))
+        # Otherwise, increase according to the max balloon change
+        (defvar balloon_size (* guest.balloon_cur
+                                (+ 1 max_balloon_change_percent)))
+
+        # Determine the new target for the BalloonController.  Only set
+        # if the value is a large enough for the change to be worth it.
+        (if (> balloon_size guest.balloon_max)
+            (set balloon_size guest.balloon_max) 0)
+        (if (< balloon_size balloon_min)
+            (set balloon_size balloon_min) 0)
+        (if (change_big_enough guest balloon_size)
+            (guest.Control "balloon_target" balloon_size) 0)
+    } 0)
+})
+
+### Main script
+# Methodology: The goal is to shrink all guests fairly and by an amount
+# scaled to the level of host memory pressure.  If the host is under
+# severe pressure, scale back more aggressively.  We don't yet handle
+# symptoms of over-ballooning guests or try to balloon idle guests more
+# aggressively.  When the host is not under memory pressure, slowly
+# deflate the balloons.
+
+(defvar host_free_percent (/ (Host.StatAvg "mem_free") Host.mem_available))
+(if (< host_free_percent pressure_threshold)
+    (with Guests guest (shrink_guest guest))
+    (with Guests guest (grow_guest guest)))
diff --git a/vdsm/mom_policies/mom.policy b/vdsm/mom_policies/ksm.policy
similarity index 100%
rename from vdsm/mom_policies/mom.policy
rename to vdsm/mom_policies/ksm.policy


--
To view, visit http://gerrit.ovirt.org/11244
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieffd589dbe524091d84c53cdf109a933b8a3eb4d
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Royce Lv <lvroyce at linux.vnet.ibm.com>


More information about the vdsm-patches mailing list