qmemman: use the fact that balloon driver retries

Apparently even if there is not enough xen memory to balloon up,
balloon driver will try to fulfill the request later, when
some memory is freed. Thus, in do_balloon, do not limit mem_set
to the available memory.
This commit is contained in:
Rafal Wojtczuk 2010-09-09 10:36:13 +02:00
parent 87d1e973c7
commit 5a33ed71ce

View File

@ -12,6 +12,7 @@ class DomainState:
self.mem_used = None self.mem_used = None
self.id = id self.id = id
self.meminfo_updated = False self.meminfo_updated = False
self.last_target = 0
class SystemState: class SystemState:
def __init__(self): def __init__(self):
@ -64,6 +65,7 @@ class SystemState:
#the below works (and is fast), but then 'xm list' shows unchanged memory value #the below works (and is fast), but then 'xm list' shows unchanged memory value
def mem_set(self, id, val): def mem_set(self, id, val):
print 'mem-set domain', id, 'to', val print 'mem-set domain', id, 'to', val
self.domdict[id].last_target = val
self.xs.write('', '/local/domain/' + id + '/memory/target', str(val/1024)) self.xs.write('', '/local/domain/' + id + '/memory/target', str(val/1024))
#can happen in the middle of domain shutdown #can happen in the middle of domain shutdown
#apparently xc.lowlevel throws exceptions too #apparently xc.lowlevel throws exceptions too
@ -118,24 +120,12 @@ class SystemState:
self.domdict[domid].meminfo = self.parse_meminfo(val) self.domdict[domid].meminfo = self.parse_meminfo(val)
self.domdict[domid].meminfo_updated = True self.domdict[domid].meminfo_updated = True
def adjust_inflates_to_xenfree(self, reqs, idx):
i = idx
memory_needed = 0
while i < len(reqs):
dom, mem = reqs[i]
memory_needed += mem - self.domdict[dom].memory_actual
i = i + 1
scale = 1.0*self.get_free_xen_memory()/memory_needed
dom, mem = reqs[idx]
scaled_req = self.domdict[dom].memory_actual + scale*(mem - self.domdict[dom].memory_actual)
return int(scaled_req)
def is_balance_req_significant(self, memset_reqs): def is_balance_req_significant(self, memset_reqs):
total_memory_transfer = 0 total_memory_transfer = 0
MIN_TOTAL_MEMORY_TRANSFER = 150*1024*1024 MIN_TOTAL_MEMORY_TRANSFER = 150*1024*1024
for rq in memset_reqs: for rq in memset_reqs:
dom, mem = rq dom, mem = rq
memory_change = mem - self.domdict[dom].memory_actual memory_change = mem - self.domdict[dom].last_target
total_memory_transfer += abs(memory_change) total_memory_transfer += abs(memory_change)
return total_memory_transfer > MIN_TOTAL_MEMORY_TRANSFER return total_memory_transfer > MIN_TOTAL_MEMORY_TRANSFER
@ -155,22 +145,10 @@ class SystemState:
return return
self.print_stats(xenfree, memset_reqs) self.print_stats(xenfree, memset_reqs)
wait_before_first_inflate = False
i = 0 for rq in memset_reqs:
while i < len(memset_reqs): dom, mem = rq
dom, mem = memset_reqs[i]
memory_change = mem - self.domdict[dom].memory_actual
if memory_change < 0:
wait_before_first_inflate = True
else:
if wait_before_first_inflate:
time.sleep(self.BALOON_DELAY)
wait_before_first_inflate = False
#the following is called before _each_ inflate, to account for possibility that
#previously triggered memory release is in progress
mem = self.adjust_inflates_to_xenfree(memset_reqs, i)
self.mem_set(dom, mem) self.mem_set(dom, mem)
i = i + 1
# for i in self.domdict.keys(): # for i in self.domdict.keys():
# print 'domain ', i, ' meminfo=', self.domdict[i].meminfo, 'actual mem', self.domdict[i].memory_actual # print 'domain ', i, ' meminfo=', self.domdict[i].meminfo, 'actual mem', self.domdict[i].memory_actual