Score:2

Understanding Current/Maximum allocation of VirtManager (LibVirt)

in flag

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

Score:1
ca flag

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 it (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) is 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 zeroes all memory at startup, effectively forcing a complete host-side memory allocation (up to current memory) at guest startup.

Damn Vegetables avatar
in flag
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.
shodanshok avatar
ca flag
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](https://docs.kernel.org/mm/overcommit-accounting.html) for more details.
shodanshok avatar
ca flag
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.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.