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] Move the dom0 ballooning-out code from the xm create han

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] Move the dom0 ballooning-out code from the xm create handler and into the
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 01 Dec 2005 11:20:13 +0000
Delivery-date: Thu, 01 Dec 2005 11:21:19 +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 e0d01dd6c4ca0f14b29aa7b07d9a3a82d58371ea
# Parent  2e3051c017574001c70283f1144e6aa1e6cef847
Move the dom0 ballooning-out code from the xm create handler and into the
server, where it can be used on reboot and migrate as well as create.
Ballooning bugs may still exist (it is unclear) but this is certainly a good
step in the right direction.

Ignore the memory and maxmem entries in the store for dom0 when restarting.
This means that the value in use at the time becomes the configured target.
This should fix the bug whereby dom0_mem settings on the command line are
being overridden by (older) entries in the store.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>

diff -r 2e3051c01757 -r e0d01dd6c4ca tools/python/xen/xend/XendCheckpoint.py
--- a/tools/python/xen/xend/XendCheckpoint.py   Thu Dec  1 03:32:39 2005
+++ b/tools/python/xen/xend/XendCheckpoint.py   Thu Dec  1 03:39:23 2005
@@ -18,6 +18,7 @@
 
 import xen.lowlevel.xc
 
+import balloon
 from XendError import XendError
 from XendLogging import log
 
@@ -131,6 +132,8 @@
             raise XendError(
                 "not a valid guest state file: pfn count out of range")
 
+        balloon.free(xc.pages_to_kib(nr_pfns))
+
         cmd = map(str, [xen.util.auxbin.pathTo(XC_RESTORE),
                         xc.handle(), fd, dominfo.getDomid(), nr_pfns,
                         store_port, console_port])
@@ -213,4 +216,4 @@
         if line == "":
             break
         else:
-            log.error('%s', line)
+            log.error('%s', line.strip())
diff -r 2e3051c01757 -r e0d01dd6c4ca tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   Thu Dec  1 03:32:39 2005
+++ b/tools/python/xen/xend/XendDomainInfo.py   Thu Dec  1 03:39:23 2005
@@ -33,6 +33,7 @@
 from xen.util import asserts
 from xen.util.blkif import blkdev_uname_to_file
 
+import balloon
 import image
 import sxp
 import uuid
@@ -226,13 +227,13 @@
                 'Uuid in store does not match uuid for existing domain %d: '
                 '%s != %s' % (domid, uuid2_str, xeninfo['uuid']))
 
-        vm = XendDomainInfo(xeninfo, domid, dompath, True)
+        vm = XendDomainInfo(xeninfo, domid, dompath, True, priv)
 
     except Exception, exn:
         if priv:
             log.warn(str(exn))
 
-        vm = XendDomainInfo(xeninfo, domid, dompath, True)
+        vm = XendDomainInfo(xeninfo, domid, dompath, True, priv)
         vm.removeDom()
         vm.removeVm()
         vm.storeVmDetails()
@@ -369,7 +370,8 @@
 
 class XendDomainInfo:
 
-    def __init__(self, info, domid = None, dompath = None, augment = False):
+    def __init__(self, info, domid = None, dompath = None, augment = False,
+                 priv = False):
 
         self.info = info
 
@@ -387,7 +389,7 @@
         self.dompath = dompath
 
         if augment:
-            self.augmentInfo()
+            self.augmentInfo(priv)
 
         self.validateInfo()
 
@@ -443,7 +445,7 @@
         return 1
 
 
-    def augmentInfo(self):
+    def augmentInfo(self, priv):
         """Augment self.info, as given to us through {@link #recreate}, with
         values taken from the store.  This recovers those values known to xend
         but not to the hypervisor.
@@ -452,8 +454,15 @@
             if not self.infoIsSet(name) and val is not None:
                 self.info[name] = val
 
-        map(lambda x, y: useIfNeeded(x[0], y), VM_STORE_ENTRIES,
-            self.readVMDetails(VM_STORE_ENTRIES))
+        if priv:
+            entries = VM_STORE_ENTRIES[:]
+            entries.remove(('memory', int))
+            entries.remove(('maxmem', int))
+        else:
+            entries = VM_STORE_ENTRIES
+
+        map(lambda x, y: useIfNeeded(x[0], y), entries,
+            self.readVMDetails(entries))
 
         device = []
         for c in controllerClasses:
@@ -842,6 +851,9 @@
         """Set the memory target of this domain.
         @param target In MiB.
         """
+        log.debug("Setting memory target of domain %s (%d) to %d MiB.",
+                  self.info['name'], self.domid, target)
+        
         self.info['memory'] = target
         self.storeVm("memory", target)
         self.storeDom("memory/target", target << 10)
@@ -1105,6 +1117,7 @@
             xc.domain_setcpuweight(self.domid, self.info['cpu_weight'])
 
             m = self.image.getDomainMemory(self.info['memory'] * 1024)
+            balloon.free(m)
             xc.domain_setmaxmem(self.domid, m)
             xc.domain_memory_increase_reservation(self.domid, m, 0, 0)
 
diff -r 2e3051c01757 -r e0d01dd6c4ca tools/python/xen/xm/create.py
--- a/tools/python/xen/xm/create.py     Thu Dec  1 03:32:39 2005
+++ b/tools/python/xen/xm/create.py     Thu Dec  1 03:39:23 2005
@@ -798,57 +798,6 @@
     opts.info("Started domain %s" % (dom))
     return int(sxp.child_value(dominfo, 'domid'))
 
-def get_dom0_alloc():
-    """Return current allocation memory of dom0 (in MB). Return 0 on error"""
-    PROC_XEN_BALLOON = "/proc/xen/balloon"
-
-    f = open(PROC_XEN_BALLOON, "r")
-    line = f.readline()
-    for x in line.split():
-        for n in x:
-            if not n.isdigit():
-                break
-        else:
-            f.close()
-            return int(x)/1024
-    f.close()
-    return 0
-
-def balloon_out(dom0_min_mem, opts):
-    """Balloon out memory from dom0 if necessary"""
-    SLACK = 4
-    timeout = 20 # 2s
-    ret = 1
-
-    xc = xen.lowlevel.xc.xc()
-    free_mem = xc.physinfo()['free_pages'] / 256
-    domU_need_mem = opts.vals.memory + SLACK 
-
-    # we already have enough free memory, return success
-    if free_mem >= domU_need_mem:
-        del xc
-        return 0
-
-    dom0_cur_alloc = get_dom0_alloc()
-    dom0_new_alloc = dom0_cur_alloc - (domU_need_mem - free_mem)
-    if dom0_new_alloc < dom0_min_mem:
-        dom0_new_alloc = dom0_min_mem
-
-    server.xend_domain_mem_target_set(0, dom0_new_alloc)
-
-    while timeout > 0:
-        time.sleep(0.1) # sleep 100ms
-
-        free_mem = xc.physinfo()['free_pages'] / 256
-        if free_mem >= domU_need_mem:
-            ret = 0
-            break
-        timeout -= 1
-
-    del xc
-    return ret
-
-
 def parseCommandLine(argv):
     gopts.reset()
     args = gopts.parse(argv)
@@ -891,15 +840,6 @@
     if opts.vals.dryrun:
         PrettyPrint.prettyprint(config)
     else:
-        from xen.xend import XendRoot
-
-        xroot = XendRoot.instance()
-
-        dom0_min_mem = xroot.get_dom0_min_mem()
-        if dom0_min_mem != 0:
-            if balloon_out(dom0_min_mem, opts):
-                err("cannot allocate enough memory for domain")
-
         dom = make_domain(opts, config)
         if opts.vals.console_autoconnect:
             console.execConsole(dom)
diff -r 2e3051c01757 -r e0d01dd6c4ca tools/python/xen/xend/balloon.py
--- /dev/null   Thu Dec  1 03:32:39 2005
+++ b/tools/python/xen/xend/balloon.py  Thu Dec  1 03:39:23 2005
@@ -0,0 +1,97 @@
+#===========================================================================
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#============================================================================
+# Copyright (C) 2004, 2005 Mike Wray <mike.wray@xxxxxx>
+# Copyright (C) 2005 XenSource Ltd
+#============================================================================
+
+
+import time
+
+import xen.lowlevel.xc
+
+import XendDomain
+import XendRoot
+from XendLogging import log
+from XendError import VmError
+
+
+PROC_XEN_BALLOON = "/proc/xen/balloon"
+BALLOON_OUT_SLACK = 1 # MiB.  We need this because the physinfo details are
+                      # rounded.
+
+
+def free(required):
+    """Balloon out memory from the privileged domain so that there is the
+    specified required amount (in KiB) free.
+    """
+    
+    xc = xen.lowlevel.xc.xc()
+    xroot = XendRoot.instance()
+
+    try:
+        free_mem = xc.physinfo()['free_memory']
+        need_mem = (required + 1023) / 1024 + BALLOON_OUT_SLACK
+
+        log.debug("Balloon: free %d; need %d.", free_mem, need_mem)
+        
+        if free_mem >= need_mem:
+            return
+
+        dom0_min_mem = xroot.get_dom0_min_mem()
+        if dom0_min_mem == 0:
+            raise VmError('Not enough free memory and dom0_min_mem is 0.')
+
+        dom0_alloc = _get_dom0_alloc()
+        dom0_new_alloc = dom0_alloc - (need_mem - free_mem)
+        if dom0_new_alloc < dom0_min_mem:
+            raise VmError(
+                ('I need %d MiB, but dom0_min_mem is %d and shrinking to '
+                 '%d MiB would leave only %d MiB free.') %
+                (need_mem, dom0_min_mem, dom0_min_mem,
+                 free_mem + (dom0_alloc - dom0_min_mem)))
+
+        dom0 = XendDomain.instance().privilegedDomain()
+        dom0.setMemoryTarget(dom0_new_alloc)
+
+        timeout = 20 # 2 sec
+        while timeout > 0:
+            time.sleep(0.1)
+
+            free_mem = xc.physinfo()['free_memory']
+            if free_mem >= need_mem:
+                return
+
+            timeout -= 1
+
+        raise VmError('The privileged domain did not balloon!')
+    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] Move the dom0 ballooning-out code from the xm create handler and into the, Xen patchbot -unstable <=