WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] The attached patch cleans up the parsing of /proc/xen/ba

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] The attached patch cleans up the parsing of /proc/xen/balloon that
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Fri, 10 Mar 2006 11:54:08 +0000
Delivery-date: Fri, 10 Mar 2006 11:54:57 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID cc303cdf88099ecdae5b1be53b3ef1cadee2df28
# Parent  e0741ec5ec52d222c39324c672fc31742b2a9a88
The attached patch cleans up the parsing of /proc/xen/balloon that
occurs in xend.  Currently, the parsing is hard-coded; it expects that
the desired number is on the first line.  My patch is more robust; it
lets values be retrieved by a label.  It also exposes a few functions to
retrieve the current allocation and the target allocation.

By abstracting this a little better, I'll be able to address a few
other issues in subsequent patches.  Mostly, this allows for better
error checking and guidance for the user.  For example, by exposing
get_dom0_current_alloc(), we can (elsewhere, in a later patch) calculate
how large of a VM could potentially be started.  This is useful, as it
lets simple VM-creation GUIs guide the user towards reasonable memory
values for new VMs.

Signed-off-by:  Charles Coffing <ccoffing@xxxxxxxxxx>

diff -r e0741ec5ec52 -r cc303cdf8809 tools/python/xen/xend/balloon.py
--- a/tools/python/xen/xend/balloon.py  Fri Mar 10 09:54:25 2006
+++ b/tools/python/xen/xend/balloon.py  Fri Mar 10 10:05:59 2006
@@ -27,7 +27,8 @@
 from XendError import VmError
 
 
-PROC_XEN_BALLOON = "/proc/xen/balloon"
+PROC_XEN_BALLOON = '/proc/xen/balloon'
+
 BALLOON_OUT_SLACK = 1 # MiB.  We need this because the physinfo details are
                       # rounded.
 RETRY_LIMIT = 10
@@ -39,6 +40,47 @@
 # such requirements.
 SLEEP_TIME_GROWTH = 0.1
 
+# A mapping between easy-to-remember labels and the more verbose
+# label actually shown in the PROC_XEN_BALLOON file.
+labels = { 'current'      : 'Current allocation',
+           'target'       : 'Requested target',
+           'low-balloon'  : 'Low-mem balloon',
+           'high-balloon' : 'High-mem balloon',
+           'limit'        : 'Xen hard limit' }
+
+def _get_proc_balloon(label):
+    """Returns the value for the named label.  Returns None if the label was
+       not found or the value was non-numeric."""
+
+    f = file(PROC_XEN_BALLOON, 'r')
+    try:
+        for line in f:
+            keyvalue = line.split(':')
+            if keyvalue[0] == label:
+                values = keyvalue[1].split()
+                if values[0].isdigit():
+                    return int(values[0])
+                else:
+                    return None
+        return None
+    finally:
+        f.close()
+
+def get_dom0_current_alloc():
+    """Returns the current memory allocation (in MiB) of dom0."""
+
+    kb = _get_proc_balloon(labels['current'])
+    if kb == None:
+        raise VmError('Failed to query current memory allocation of dom0.')
+    return kb / 1024
+
+def get_dom0_target_alloc():
+    """Returns the target memory allocation (in MiB) of dom0."""
+
+    kb = _get_proc_balloon(labels['target'])
+    if kb == None:
+        raise VmError('Failed to query target memory allocation of dom0.')
+    return kb / 1024
 
 def free(required):
     """Balloon out memory from the privileged domain so that there is the
@@ -88,7 +130,7 @@
                 log.debug("Balloon: free %d; need %d.", free_mem, need_mem)
 
             if dom0_min_mem > 0:
-                dom0_alloc = _get_dom0_alloc()
+                dom0_alloc = get_dom0_current_alloc()
                 new_alloc = dom0_alloc - (need_mem - free_mem)
 
                 if (new_alloc >= dom0_min_mem and
@@ -121,20 +163,3 @@
 
     finally:
         del xc
-
-
-def _get_dom0_alloc():
-    """Return current allocation memory of dom0 (in MiB). Return 0 on error"""
-
-    f = file(PROC_XEN_BALLOON, 'r')
-    try:
-        line = f.readline()
-        for x in line.split():
-            for n in x:
-                if not n.isdigit():
-                    break
-            else:
-                return int(x) / 1024
-        return 0
-    finally:
-        f.close()

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] The attached patch cleans up the parsing of /proc/xen/balloon that, Xen patchbot -unstable <=