ia64/xen-unstable

changeset 15786:505021d029eb

xend: Fix memory ballooning logic during save/restore. Should be same
as during domain creation.
Signed-off-by: Chris Lalancette <clalance@redhat.com>
author kfraser@localhost.localdomain
date Tue Aug 28 16:06:32 2007 +0100 (2007-08-28)
parents 2aee2e4eacc8
children 7f53312a3297
files tools/python/xen/xend/XendCheckpoint.py
line diff
     1.1 --- a/tools/python/xen/xend/XendCheckpoint.py	Tue Aug 28 15:58:46 2007 +0100
     1.2 +++ b/tools/python/xen/xend/XendCheckpoint.py	Tue Aug 28 16:06:32 2007 +0100
     1.3 @@ -16,7 +16,7 @@ from xen.util.xpopen import xPopen3
     1.4  import xen.util.auxbin
     1.5  import xen.lowlevel.xc
     1.6  
     1.7 -from xen.xend import balloon, sxp
     1.8 +from xen.xend import balloon, sxp, image
     1.9  from xen.xend.XendError import XendError, VmError
    1.10  from xen.xend.XendLogging import log
    1.11  from xen.xend.XendConfig import XendConfig
    1.12 @@ -181,9 +181,6 @@ def restore(xd, fd, dominfo = None, paus
    1.13      assert store_port
    1.14      assert console_port
    1.15  
    1.16 -    page_size_kib = xc.pages_to_kib(1)
    1.17 -    nr_pfns = (dominfo.getMemoryTarget() + page_size_kib - 1) / page_size_kib 
    1.18 -
    1.19      # if hvm, pass mem size to calculate the store_mfn
    1.20      image_cfg = dominfo.info.get('image', {})
    1.21      is_hvm = dominfo.info.is_hvm()
    1.22 @@ -197,19 +194,33 @@ def restore(xd, fd, dominfo = None, paus
    1.23          pae  = 0
    1.24  
    1.25      try:
    1.26 -        shadow = dominfo.info['shadow_memory']
    1.27 +        restore_image = image.create(dominfo, dominfo.info['image'],
    1.28 +                                     dominfo.info['device'])
    1.29 +        memory = restore_image.getRequiredAvailableMemory(
    1.30 +            dominfo.info['memory'] * 1024)
    1.31 +        maxmem = restore_image.getRequiredAvailableMemory(
    1.32 +            dominfo.info['maxmem'] * 1024)
    1.33 +        shadow = restore_image.getRequiredShadowMemory(
    1.34 +            dominfo.info['shadow_memory'] * 1024,
    1.35 +            dominfo.info['maxmem'] * 1024)
    1.36 +
    1.37          log.debug("restore:shadow=0x%x, _static_max=0x%x, _static_min=0x%x, ",
    1.38                    dominfo.info['shadow_memory'],
    1.39                    dominfo.info['memory_static_max'],
    1.40                    dominfo.info['memory_static_min'])
    1.41  
    1.42 -        balloon.free(xc.pages_to_kib(nr_pfns) + shadow * 1024)
    1.43 +        # Round shadow up to a multiple of a MiB, as shadow_mem_control
    1.44 +        # takes MiB and we must not round down and end up under-providing.
    1.45 +        shadow = ((shadow + 1023) / 1024) * 1024
    1.46  
    1.47 -        shadow_cur = xc.shadow_mem_control(dominfo.getDomid(), shadow)
    1.48 +        # set memory limit
    1.49 +        xc.domain_setmaxmem(dominfo.getDomid(), maxmem)
    1.50 +
    1.51 +        balloon.free(memory + shadow)
    1.52 +
    1.53 +        shadow_cur = xc.shadow_mem_control(dominfo.getDomid(), shadow / 1024)
    1.54          dominfo.info['shadow_memory'] = shadow_cur
    1.55  
    1.56 -        xc.domain_setmaxmem(dominfo.getDomid(), dominfo.getMemoryMaximum())
    1.57 -
    1.58          cmd = map(str, [xen.util.auxbin.pathTo(XC_RESTORE),
    1.59                          fd, dominfo.getDomid(),
    1.60                          store_port, console_port, int(is_hvm), pae, apic])
    1.61 @@ -220,7 +231,7 @@ def restore(xd, fd, dominfo = None, paus
    1.62          forkHelper(cmd, fd, handler.handler, True)
    1.63  
    1.64          # We don't want to pass this fd to any other children -- we 
    1.65 -        # might need to recover ths disk space that backs it.
    1.66 +        # might need to recover the disk space that backs it.
    1.67          try:
    1.68              flags = fcntl.fcntl(fd, fcntl.F_GETFD)
    1.69              flags |= fcntl.FD_CLOEXEC