Skip to content

Commit

Permalink
Update Xen's memory overhead formula
Browse files Browse the repository at this point in the history
Experiments show that using memory hotplug or populate-on-demand makes
no difference in required memory at startup. But PV vs PVH/HVM does make
a difference - PV doesn't need extra per-MB overhead at all.

On top of that, experimentally find the correct factor. Do it by
starting VM (paused) with different parameters and compare `xl info
free_memory` before and after.

memory / maxmem: difference
400  / 4000: 434
600  / 4000: 634
400  / 400: 405
400  / 600: 407
400  / 2000: 418
2000 / 2000: 2018
600  / 600: 607

All above are with 2 vcpus. Testing with other vcpus count shows the
1.5MB per vcpu is quite accurate.
As seen above, the initial memory doesn't affect the overhead. The
maxmem counts. Applying linear regression to that shows it's about
0.008MB per MB of maxmem, so round it up to 8192 bytes.
The base overhead of 4MB doesn't match exactly, but since the calculated
number is smaller, leave it at 4MB as a safety margin.

Fixes QubesOS/qubes-issues#9431
  • Loading branch information
marmarek committed Oct 22, 2024
1 parent f42f5b6 commit 7eea85e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions qubes/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1771,10 +1771,11 @@ def request_memory(self, mem_required=None):
try:
mem_required_with_overhead = mem_required + MEM_OVERHEAD_BASE \
+ self.vcpus * MEM_OVERHEAD_PER_VCPU
if self.use_memory_hotplug:
# extra overhead to account future hotplug memory
# 1 page per 1MB of RAM, see libxl__get_required_paging_memory()
mem_required_with_overhead += self.maxmem * 4096
maxmem = self.maxmem if self.maxmem else self.memory
if self.virt_mode != "pv":
# extra overhead to account (possibly future hotplug) memory
# 2 pages per 1MB of RAM, see libxl__get_required_paging_memory()
mem_required_with_overhead += maxmem * 8192
got_memory = qmemman_client.request_memory(
mem_required_with_overhead)
self.log.debug(f"mem required with overhead: {mem_required_with_overhead}")
Expand Down

0 comments on commit 7eea85e

Please sign in to comment.