Why doesn't VirtualBox allocate memory from the host's swap?

Discussions related to using VirtualBox on Windows hosts.
Post Reply
CutterX
Posts: 24
Joined: 17. Aug 2013, 15:51

Why doesn't VirtualBox allocate memory from the host's swap?

Post by CutterX »

Hi,

When I launch a VM and there isn't enough free memory on the host, VirtualBox pauses the VM and gives an error. I've noticed that the host's swap file isn't used to allocate the missing memory. Why?
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Why doesn't VirtualBox allocate memory from the host's swap?

Post by socratis »

Because actual, physical, non-swappable memory must be used.
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
ChipMcK
Volunteer
Posts: 1095
Joined: 20. May 2009, 02:17
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Windows, OSX
Location: U S of A

Re: Why doesn't VirtualBox allocate memory from the host's swap?

Post by ChipMcK »

so that the guest OS may do its own paging/swapping if it is capable
CutterX
Posts: 24
Joined: 17. Aug 2013, 15:51

Re: Why doesn't VirtualBox allocate memory from the host's swap?

Post by CutterX »

socratis wrote:Because actual, physical, non-swappable memory must be used.
Please could you elaborate? I would be interested in knowing why.
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Why doesn't VirtualBox allocate memory from the host's swap?

Post by socratis »

There's nothing to elaborate on. The memory needs to be locked in order to reduce latency and to prevent paging and swapping, which are really, really slow processes.

If your host runs out of memory, close some applications on the host, buy more RAM for the host, or reduce the amount of RAM assigned to the guest.

Read the following threads. They actually deal with the same problem as yours: All three of them are a great reading.
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
CutterX
Posts: 24
Joined: 17. Aug 2013, 15:51

Re: Why doesn't VirtualBox allocate memory from the host's swap?

Post by CutterX »

Thank you both for your answers.
The threads you've linked discuss immediate versus gradual memory allocation, but they don't touch the subject of swapping. Sure, swapping is slower but isn't it better than crashing the VM?
ChipMcK wrote:so that the guest OS may do its own paging/swapping if it is capable
It shouldn't prevent the guest from swapping, even though I assume it could be very slow to swap on both the host and the guest simultaneously. Just a hypothesis.
Last edited by socratis on 28. May 2018, 11:08, edited 1 time in total.
Reason: Removed unnecessary verbatim quote of the whole previous message.
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Why doesn't VirtualBox allocate memory from the host's swap?

Post by socratis »

The threads that I linked to, talk about memory allocation in general, do not simply focus on the "when", but focus on the "why", the kind of memory that needs to be allocated.

What I was hoping that you'd get from those threads is that if you want to prevent your VM crashing mid-running, would be to force the allocation of the RAM when the VM starts, and not rely on the lazy memory allocation algorithm. That way you will know from the get-go that you don't have enough RAM on your host.

And no, swapping is not an option. There are some processes that require specific features from the allocated memory; VirtualBox requires the memory to be available and non-swappable.
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Post Reply