qmemman: move /proc/meminfo parsing to qmemman_algo
Just cosmetics, to make code layout more coherent.
This commit is contained in:
parent
24b3baf063
commit
9c609a23bf
@ -11,7 +11,6 @@ class DomainState:
|
|||||||
self.memory_actual = None
|
self.memory_actual = None
|
||||||
self.mem_used = None
|
self.mem_used = None
|
||||||
self.id = id
|
self.id = id
|
||||||
self.meminfo_updated = False
|
|
||||||
self.last_target = 0
|
self.last_target = 0
|
||||||
|
|
||||||
class SystemState:
|
class SystemState:
|
||||||
@ -41,27 +40,6 @@ class SystemState:
|
|||||||
if self.domdict.has_key(id):
|
if self.domdict.has_key(id):
|
||||||
self.domdict[id].memory_actual = domain['mem_kb']*1024
|
self.domdict[id].memory_actual = domain['mem_kb']*1024
|
||||||
|
|
||||||
def parse_meminfo(self, meminfo):
|
|
||||||
dict = {}
|
|
||||||
l1 = string.split(meminfo,"\n")
|
|
||||||
for i in l1:
|
|
||||||
l2 = string.split(i)
|
|
||||||
if len(l2) >= 2:
|
|
||||||
dict[string.rstrip(l2[0], ":")] = l2[1]
|
|
||||||
|
|
||||||
try:
|
|
||||||
for i in ('MemTotal', 'MemFree', 'Buffers', 'Cached', 'SwapTotal', 'SwapFree'):
|
|
||||||
val = int(dict[i])*1024
|
|
||||||
if (val < 0):
|
|
||||||
return None
|
|
||||||
dict[i] = val
|
|
||||||
except:
|
|
||||||
return None
|
|
||||||
|
|
||||||
if dict['SwapTotal'] < dict['SwapFree']:
|
|
||||||
return None
|
|
||||||
return dict
|
|
||||||
|
|
||||||
#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
|
||||||
@ -117,8 +95,7 @@ class SystemState:
|
|||||||
niter = niter + 1
|
niter = niter + 1
|
||||||
|
|
||||||
def refresh_meminfo(self, domid, val):
|
def refresh_meminfo(self, domid, val):
|
||||||
self.domdict[domid].meminfo = self.parse_meminfo(val)
|
qmemman_algo.refresh_meminfo_for_domain(self.domdict[domid], val)
|
||||||
self.domdict[domid].meminfo_updated = True
|
|
||||||
|
|
||||||
def is_balance_req_significant(self, memset_reqs):
|
def is_balance_req_significant(self, memset_reqs):
|
||||||
total_memory_transfer = 0
|
total_memory_transfer = 0
|
||||||
|
@ -1,3 +1,26 @@
|
|||||||
|
import string
|
||||||
|
|
||||||
|
def parse_meminfo(self, meminfo):
|
||||||
|
dict = {}
|
||||||
|
l1 = string.split(meminfo,"\n")
|
||||||
|
for i in l1:
|
||||||
|
l2 = string.split(i)
|
||||||
|
if len(l2) >= 2:
|
||||||
|
dict[string.rstrip(l2[0], ":")] = l2[1]
|
||||||
|
|
||||||
|
try:
|
||||||
|
for i in ('MemTotal', 'MemFree', 'Buffers', 'Cached', 'SwapTotal', 'SwapFree'):
|
||||||
|
val = int(dict[i])*1024
|
||||||
|
if (val < 0):
|
||||||
|
return None
|
||||||
|
dict[i] = val
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if dict['SwapTotal'] < dict['SwapFree']:
|
||||||
|
return None
|
||||||
|
return dict
|
||||||
|
|
||||||
def is_suspicious(dom):
|
def is_suspicious(dom):
|
||||||
ret = False
|
ret = False
|
||||||
if dom.meminfo['SwapTotal'] < dom.meminfo['SwapFree']:
|
if dom.meminfo['SwapTotal'] < dom.meminfo['SwapFree']:
|
||||||
@ -8,11 +31,11 @@ def is_suspicious(dom):
|
|||||||
print 'suspicious meminfo for domain', dom.id, 'mem actual', dom.memory_actual, dom.meminfo
|
print 'suspicious meminfo for domain', dom.id, 'mem actual', dom.memory_actual, dom.meminfo
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def recalc_mem_used(domdict):
|
def refresh_meminfo_for_domain(dom, xenstore_key):
|
||||||
for domid in domdict.keys():
|
meminfo = parse_meminfo(xenstore_key)
|
||||||
dom = domdict[domid]
|
dom.meminfo = meminfo
|
||||||
if dom.meminfo_updated:
|
if meminfo is None:
|
||||||
dom.meminfo_updated = False
|
return
|
||||||
if is_suspicious(dom):
|
if is_suspicious(dom):
|
||||||
dom.meminfo = None
|
dom.meminfo = None
|
||||||
dom.mem_used = None
|
dom.mem_used = None
|
||||||
@ -20,8 +43,6 @@ def recalc_mem_used(domdict):
|
|||||||
dom.mem_used = dom.meminfo['MemTotal'] - dom.meminfo['MemFree'] - dom.meminfo['Cached'] - dom.meminfo['Buffers'] + dom.meminfo['SwapTotal'] - dom.meminfo['SwapFree']
|
dom.mem_used = dom.meminfo['MemTotal'] - dom.meminfo['MemFree'] - dom.meminfo['Cached'] - dom.meminfo['Buffers'] + dom.meminfo['SwapTotal'] - dom.meminfo['SwapFree']
|
||||||
|
|
||||||
def prefmem(dom):
|
def prefmem(dom):
|
||||||
if dom.meminfo_updated:
|
|
||||||
raise AssertionError('meminfo_updated=True in prefmem')
|
|
||||||
CACHE_FACTOR = 1.3
|
CACHE_FACTOR = 1.3
|
||||||
#dom0 is special, as it must have large cache, for vbds. Thus, give it a special boost
|
#dom0 is special, as it must have large cache, for vbds. Thus, give it a special boost
|
||||||
if dom.id == '0':
|
if dom.id == '0':
|
||||||
@ -40,7 +61,6 @@ def balloon(memsize, domdict):
|
|||||||
donors = list()
|
donors = list()
|
||||||
request = list()
|
request = list()
|
||||||
available = 0
|
available = 0
|
||||||
recalc_mem_used(domdict)
|
|
||||||
for i in domdict.keys():
|
for i in domdict.keys():
|
||||||
if domdict[i].meminfo is None:
|
if domdict[i].meminfo is None:
|
||||||
continue
|
continue
|
||||||
@ -110,7 +130,6 @@ def balance(xenfree, domdict):
|
|||||||
total_mem_pref = 0
|
total_mem_pref = 0
|
||||||
total_mem_pref_acceptors = 0
|
total_mem_pref_acceptors = 0
|
||||||
|
|
||||||
recalc_mem_used(domdict)
|
|
||||||
donors = list()
|
donors = list()
|
||||||
acceptors = list()
|
acceptors = list()
|
||||||
#pass 1: compute the above "total" values
|
#pass 1: compute the above "total" values
|
||||||
|
Loading…
Reference in New Issue
Block a user