Mac – How does VirtualBox’s memory usage work

memoryvirtual machinevirtualbox

I've been running several VM's with VirtualBox, and the memory usage reported from various perspectives, and I'm having trouble figuring how much memory my VMs actually use. Here is an example:

  • I have a VM running Windows 7 (as the Guest OS) on my windows XP Host machine.
  • The Host Machine Has 3 GB of RAM
  • The Guest VM is setup to have a base memory of 1 GB
  • If I run Task Manger on the Guest OS, I see memory usage of 430 MB
  • If I run Task Manger on the host OS, I see 3 processes that seem to belong to VirtualBox:
    1. VirtualBox.exe (1), using 60 MB of memory (This one seems to have the most CPU usage)
    2. VirtualBox.exe (2), using 20 MB of memory
    3. VBoxSvc.exe, using 11.5 MB of memory
  • While running the VM, the Host OS's memory usage is about 2 GB
  • When I shut down the VM, the Host OS's it goes back to memory usage goes down to about 900 MB

So clearly, there are some huge differences here. I really don't understand how the GuestOS can use 400+ MB, while the Host OS only shows about 75 MB allocated to the VM. Are there other processes used by VirtualBox that aren't as obviously named?

Also, I'd like to know if I run a machine with 1 GB, is that going to take 1 GB away from my host OS, or only the amount of memory the Guest machine is currently using?

Update:

Someone expressed distrust over my memory usage numbers, and I'm not sure if that distrust was directed at me, or my Host OS's Task Manager's reporting (which is perhaps the culprit), but for any skeptics, here is a screenshot of those processes on the host machine:

VirtualBox task manager

Best Answer

To understand the process architecture of VirtualBox see
The VirtualBox architecture :

Once you start a virtual machine (VM) from the GUI, you have two windows (the main window and the VM), but three processes running. Looking at your system from Task Manager (on Windows) or some system monitor (on Linux), you will see these:

  1. VirtualBox, the GUI for the main window;
  2. Another VirtualBox process that was started with the -startvm parameter, which means that its GUI process acts as a shell for a VM;
  3. VBoxSVC, the service mentioned above, which is running in the background to keep track of all the processes involved. This was automatically started by the first GUI process.

As regarding memory, the User Manual states:

Base memory

This sets the amount of RAM that is allocated and given to the VM when it is running. The specified amount of memory will be requested from the host operating system, so it must be available or made available as free memory on the host when attempting to start the VM and will not be available to the host while the VM is running. This is the same setting that was specified in the "New Virtual Machine" wizard, as described with guidelines under the section called “Creating a virtual machine” above.

This means that the guest takes out of the host:

  • As much memory as it was declared with
  • Each VM is also a VirtualBox executable, so you need to add its memory.

It’s always possible that the VirtualBox manual is several versions behind, and that the latest memory optimizations technique are not documented.

In addition, VirtualBox may be optimizing memory usage by not allocating the entire defined VM memory.

Allocating memory as required is an optimization that can save a lot on physical memory, but memory-intensive processes in the VM may be slowed down by the frequent need by VirtualBox to request more host memory.

Related Question