Fix auto-ballooning of dom0 for HVM domains
PATCH 1/1 Fix auto-ballooning of dom0 for HVM domains
Hi,
I've been trying to make the auto-ballooning of domain 0 work reliably for HVM domains.
Patch #1 is a simple bug fix, in preparation for patch #2. Patch #2 tries to calculate how much memory is needed for HVM domains (XenSource bug #521) and is certainly open for discussion. Patches apply cleanly to both 3.0-testing and unstable.
Patch #1 (xen-hvm-auto-balloon.diff):
When a domain (whether para- or fully-virtualized) reports how much overhead memory it requires (via getDomainMemory in image.py), all such memory was immediately allocated to the domain itself. This is certainly incorrect for HVM domains, since additional increase_reservation calls are made later in qemu. Since all ballooned memory is already taken, qemu will fail. The fix is to treat the requested memory size and the overhead size as separate values. The requested memory size is immediately allocated to the new domain; the overhead is left unallocated for whatever else might need it later.
Patch #2 (xen-get-dom-memory.diff):
This patch calculates the overhead needed for HVM domains. If HVM is supported by the hardware, I add a little ballooning overhead to paravirtualized VMs also, to avoid low-memory situations. (There are various unchecked alloc_domheap_pages calls in shadow*.c that I am trying to avoid tripping over for now...) The values in this patch work fine on 32 bit; I may update them later based on feedback and/or testing on 64 bit.
Thanks,
Chuck
tools/python/xen/xend/XendDomainInfo.py +1 -1
@@ -1247,7 +1247,7 @@ class XendDomainInfo: 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) + xc.domain_memory_increase_reservation(self.domid, self.info['memory'] * 1024, 0, 0) self.createChannels()
tools/python/xen/xend/image.py +16 -8
@@ -19,6 +19,7 @@ import os, string import re +import math import xen.lowlevel.xc from xen.xend import sxp
@@ -143,11 +144,13 @@ class ImageHandler: % (self.ostype, self.vm.getDomid(), str(result))) - def getDomainMemory(self, mem): + def getDomainMemory(self, mem_kb): """@return The memory required, in KiB, by the domain to store the - given amount, also in KiB. This is normally just mem, but HVM domains - have overheads to account for.""" - return mem + given amount, also in KiB. This is normally just mem, but if HVM is + supported, keep a little extra free.""" + if 'hvm' in xc.xeninfo()['xen_caps']: + mem_kb += 4*1024; + return mem_kb def buildDomain(self): """Build the domain. Define in subclass."""
@@ -379,15 +382,20 @@ class HVMImageHandler(ImageHandler): os.waitpid(self.pid, 0) self.pid = 0 - def getDomainMemory(self, mem): + def getDomainMemory(self, mem_kb): """@see ImageHandler.getDomainMemory""" - page_kb = 4 - extra_pages = 0 if os.uname()[4] == 'ia64': page_kb = 16 # ROM size for guest firmware, ioreq page and xenstore page extra_pages = 1024 + 2 - return mem + extra_pages * page_kb + else: + page_kb = 4 + # This was derived emperically: + # 2.4 MB overhead per 1024 MB RAM + 8 MB constant + # + 4 to avoid low-memory condition + extra_mb = (2.4/1024) * (mem_kb/1024.0) + 12; + extra_pages = int( math.ceil( extra_mb*1024 / page_kb )) + return mem_kb + extra_pages * page_kb def register_shutdown_watch(self): """ add xen store watch on control/shutdown """
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Sorry, I forgot the Signed-off-by line. Consider this my sign-off on the previous email:
Quoted 1 line
Quoted 1 line
Quoted 1 line
On Thu, May 18, 2006 at 11:04 AM, in message
Quoted 3 lines · Charles Coffing
Hi,
I've been trying to make the auto- ballooning of domain 0 work
reliably
Quoted 4 lines
for HVM domains.
Patch #1 is a simple bug fix, in preparation for patch #2. Patch #2 tries to calculate how much memory is needed for HVM domains
(XenSource
Quoted 1 line
bug #521) and is certainly open for discussion. Patches apply
cleanly
Quoted 4 lines
to both 3.0- testing and unstable.
Patch #1 (xen- hvm- auto- balloon.diff):
When a domain (whether para- or fully- virtualized) reports how
much
Quoted 1 line
overhead memory it requires (via getDomainMemory in
image.py), all
such
Quoted 3 lines
memory was immediately allocated to the domain itself. This is certainly incorrect for HVM domains, since additional
increase_reservationcalls are made later in qemu. Since all
ballooned
Quoted 3 lines
memory is already taken, qemu will fail. The fix is to treat the requested memory size and the overhead size as separate values. The requested memory size is immediately allocated to the new domain;
the
Quoted 4 lines
overhead is left unallocated for whatever else might need it later.
Patch #2 (xen- get- dom- memory.diff):
This patch calculates the overhead needed for HVM domains. If HVM
is
Quoted 2 lines
supported by the hardware, I add a little ballooning overhead to paravirtualized VMs also, to avoid low- memory situations. (There
are
Quoted 2 lines
various unchecked
alloc_domheap_pagescalls in shadow*.c that I am trying to avoid tripping over for now...) The values in this patch
work
Quoted 1 line
fine on 32 bit; I may update them later based on feedback and/or
testing
Quoted 4 lines
on 64 bit.
Thanks,
Chuck