core: move maxmem default initialization to property itself

Also fix (for now?) units - memory_total is int bytes while maxmem in
megabytes.

QubesOS/qubes-issues#1737
This commit is contained in:
Marek Marczykowski-Górecki 2016-02-10 17:51:16 +01:00 committed by Wojtek Porczyk
parent 2f3762ee68
commit 62759fb1f6

View File

@ -177,7 +177,8 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
default=qubes.config.defaults['memory'],
doc='Memory currently available for this VM.')
maxmem = qubes.property('maxmem', type=int, default=None,
maxmem = qubes.property('maxmem', type=int,
default=(lambda self: self.app.host.memory_total / 1024 / 1024 / 2),
doc='''Maximum amount of memory available for this VM (for the purpose
of the memory balancer).''')
@ -431,12 +432,6 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
assert hasattr(self, 'qid')
assert hasattr(self, 'name')
# Not in generic way to not create QubesHost() to frequently
# XXX this doesn't apply, host is instantiated once
if self.maxmem is None and not self.app.vmm.offline_mode:
total_mem_mb = self.app.host.memory_total/1024
self.maxmem = total_mem_mb/2
# Linux specific cap: max memory can't scale beyond 10.79*init_mem
# see https://groups.google.com/forum/#!topic/qubes-devel/VRqkFj1IOtA
if self.maxmem > self.memory * 10: