4

When I first saw the UI in VirtManager, I thought "Maximum" is the amount of ram that appears to the guest, and "Current" is the reserved RAM when the VM starts. I thought that VirtManager will automatically reserve more RAM when the guest request it up to the size of "Maximum".

But when I test it, it did not work that way. The guest always sees the "Current" value as its total RAM size. Then, why is there "Maximum"?

And the "Current" is not actually allocated either, because, even though I have set 4092MB, Task Manager on the host shows that it is using 920MB.

enter image description here

enter image description here

1 Answer 1

3

Maximum memory is the memory the guest is booted on - but it can't use all of it if current memory is capped at a lower value.

Some examples:

  • maximum memory = current memory = 4G: the guest is booted with 4G attached, and can use all of them (minus some RAM which is mapped/excluded by the emulated platform itself)
  • maximum memory = 8G, current memory = 4G: the guest is booted with 8G attached, but it find that 4G (max-cur) are actually reserved by the kernel (via the virt-balloon driver), so it can only use 4G (cur) at most.

This kind of reservation is to avoid hot-adding memory, which is more difficult than booting with more memory and claiming back / mark as no-use some part of the memory itself.

When observing your qemu-system-x86_64 processes from task manager (or ps or top) you only see the memory actually used by the guest (plus some memory needed for the emulator itself): for example, booting a basic linux kernel + userspace can be done with ~256M and, if no process are running inside the guest, you will see such low memory utilization for the emulator process itself (even if the guest has 4G of current / maximum memory assigned). In other words, linux kernel allocation is a copy-on-write affair: it is not done one-shot, but on actual demand by the kernel/userspace.

Caveat: Windows guests zero all memory at startup, effectively forcing a complete host-side memory allocation (up to current memory) at guest startup.

3
  • 1
    I am still not sure if the Maximum is actually reserved on the host or not. E.g., Maximum = 10GB, Current = 4GB, the Linux guest is using 1GB; Is the 9GB (or 6GB) useable by the host? If so, why limit the Maximum? Can't it be just always the same size of the host's total memory just in case a VM might need more RAM? If not, why set the Current lower than the maximum? It is not useable by others anyway, so the amount of Maximum - Current is wasted. Commented Nov 13, 2022 at 4:49
  • Yes, in your example, the host is free to use up to 9 GB for its own processes. This is know as memory overcommit: the kernel is optimistically granting more memory than it really have, "hoping" no process will use all the requested memory at the same time. See here for more details.
    – shodanshok
    Commented Nov 13, 2022 at 8:58
  • Regarding your VM, why set a specific limit with maximum memory? Because a) no guest will ever expect to deal with "infinite" memory (remember that maximum memory is the one provided to the guest upon initialization) and b) because the guest kernel could be set to ignore the balloon driver, effectively always using maximum memory even in the face of a lower current memory setting.
    – shodanshok
    Commented Nov 13, 2022 at 9:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .