How does VirtualBox's memory usage work?

38

14

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

DrFredEdison

Posted 2009-11-06T18:43:20.307

Reputation: 729

Possible duplicate: http://superuser.com/q/17266/302

– Rowland Shaw – 2014-11-07T14:23:46.867

In Task manager, turn on some of the other memory columns (View->Select Columns...). Memory is counted in many different ways in Windows. For instance, "commit size" can be dramatically higher than "Memory Usage." Exactly which to use and how to interpret them is a different story. – lilbyrdie – 2010-11-06T14:43:07.443

I was wondering the exact same thing earlier today when running two VBox VMs at once. – MartW – 2009-11-06T22:03:45.643

Answers

12

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.

harrymc

Posted 2009-11-06T18:43:20.307

Reputation: 306 093

1This entire conversation and all the answers are just variations on a confusion between virtual memory and physical memory. – David Schwartz – 2015-11-02T11:33:49.080

@DavidSchwartz: This post and answers are entirely about physical memory allocation. Don't be misled by the "virtual" in "virtual machine" - a VM is a physical object. – harrymc – 2015-11-02T11:49:29.783

@harrymc I wish that were true. But it's not. As just a single example, take this quote "my vm takes up 1.2 GB. on task manager it only shows 60MB. so therefore i would claim that task manager doesn't show all the memory that my vm is using" -- His VM is taking up 1.2 GB of virtual memory and task manager is showing it using 60MB of physical memory. And this quote, "I have two VMs, one 1GB in size, the other 2GB in size" must be talking about virtual memory because it's extremely improbable the physical memory usage is that round. And so on. And so on. And so on. – David Schwartz – 2015-11-02T11:51:14.497

@harrymc And the first answer talks about commit charge, which measures virtual memory usage. The second answer just explains that the answerer is confused about why the physical usage is less than the expected virtual usage (duh, of course). And so on. – David Schwartz – 2015-11-02T11:52:51.523

@DavidSchwartz: You are hairsplitting here. The RAM definition in the VM does not produce virtual memory, but denotes a physical memory limit. Let's not continue with this exchange, as it is not useful for the readers.

– harrymc – 2015-11-02T12:10:06.370

@harrymc Well, unfortunately, none of this is likely to be useful to anyone because it's so full of this confusion. The RAM definition in the VM specifies the amount of physical memory the VM acts as if it had, but this results in that amount of virtual memory being used by the process on the host that emulates that physical memory. – David Schwartz – 2015-11-02T12:12:08.187

@harrymc, so what you are saying is that task manager does NOT show in the process list how much memory virtual box is using? – Trevor Boyd Smith – 2011-05-31T14:43:03.837

@TrevorBoydSmith: All I am saying is that there is more than one process involved and to choose correctly the columns in task manager. – harrymc – 2011-05-31T15:41:35.360

2my vm takes up 1.2 GB. on task manager it only shows 60MB. so therefore i would claim that task manager doesn't show all the memory that my vm is using. unless you can somehow show me how to tweak task manager to show 1.2gb. – Trevor Boyd Smith – 2011-05-31T16:42:53.593

@TrevorBoydSmith: Which column in task manager is the 60MB in ? You could click the column twice to sort in descending order to locate the real process. – harrymc – 2011-05-31T19:26:11.460

in task manager you add "memory" column. then you sort by name to find vbox process and it is 60mb. or you short by mem usage and see that 60mb is vbox process (and other processes with lots of mem usage). – Trevor Boyd Smith – 2011-05-31T21:32:50.777

@TrevorBoydSmith: You mean "Memory - Working Set" ? – harrymc – 2011-06-01T06:11:07.833

I am in winxp. winxp task manager has "Mem Usage" column. – Trevor Boyd Smith – 2011-06-01T12:28:23.363

Sorry about this. It would also be helpful to post the screenshot of the Performance tab in task manager. – harrymc – 2011-06-01T12:53:33.893

The VM sizes are visible in the performance tab (vista/64). But I have two VMs, one 1GB in size, the other 2GB in size, and I don't see any process with such big number in taskbar, just like OP. The "virtualbox/vboxsvr" etc processes eat 40-70MB, and there is a svchost of 190MB, that's it. But performance column shows 71% occupied of 6GB, so that is about right. Note that the VMs have significant programs running so it is not a matter of memory not being committed by the VM till first accessed. – Marco van de Voort – 2011-10-09T20:10:44.880

@Marco: What you are seeing is probably VirtualBox only allocating memory as required. This is an optimization that can save a lot on memory usage, but may slow down memory-intensive processes in the VM. – harrymc – 2011-10-10T06:10:47.833

8

It's not VirtualBox specific - see this : http://serverfault.com/questions/19935/virtual-machine-memory-usage-not-appearing-in-taskmanager

– MartW – 2009-11-06T22:05:52.877

12

The only place in Task Manager that seems to reflect the full amount is on the performance tab - the Total Commit Charge value roughly keeps pace with the amount allocated to the VM. I just closed one with 1536MB allocated, and the commit charge went down from about 2.4GB to 0.8GB. You can monitor to some extent this against Virtual Box using the Performance Monitor, and choosing the Process : Private Bytes counters for VirtualBox, VBoxSvc, and also VirtualBox#1, #2, etc (one for each running VM). There's also the Memory : Committed Bytes counter for everything.

MartW

Posted 2009-11-06T18:43:20.307

Reputation: 1 852

The OP doesn't seem to be particularly interested in what's been allocated though but is asking about what's being used. So I'm not sure how this relates to his question. – David Schwartz – 2015-11-02T12:20:18.007

5

This looks to be a Windows problem. View the third post here: http://forum.sysinternals.com/pe-is-not-showing-all-memory-used-by-virtualbox_topic23886.html

Using a program like VMMap definitely does show that the memory you tell VBox to use is actually being used. No idea why it's not visible to task manager or process explorer.

RandomInsano

Posted 2009-11-06T18:43:20.307

Reputation: 286

2

Those entries you see in TaskManager are not for your virtual machine, they are for the VirtualBox GUI. The performance tab will clearly show you how much of your total memory is being used, but with no granularity regarding processes. I personally would like to see VBox use only what it needs, but agree it's important for it to be able to use as much as it expects, hence the ring-fencing.

Rob Vanstone

Posted 2009-11-06T18:43:20.307

Reputation: 21

1

Could be related to the VirtualBox Guest Additions.

My Ubuntu install is currently using ~20MB as reported by WinXP. This is with VBoxAdditions.

My Lubuntu install is currently using ~90MB as reported by WinXP. Just installed it; VBoxAdditions haven't been installed.

Memory usage does vary by what the VM is doing. I have my Ubuntu install running ziproxy; when I do something that talks to ziproxy, memory usage spikes a few megabytes as the VM comes into use.

In general, though, virtualization has advanced far enough that the specs apparent to the guest don't need to be wholly allocated from the host. Seems to use dynamic allocation, and strong paging.

helping-hand

Posted 2009-11-06T18:43:20.307

Reputation: 11

1

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?

You're looking at what is being used on the host, not what is being allocated. The guest is not using 400+ MB of the host's RAM (yet).

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?

It will reserve 1GB of RAM, however it may wind up actually using significantly less than that. If the guest doesn't use some of that memory, host RAM can be used for many other purposes (such as caching clean disk pages), even though it's reserved for the guest. And even if the guest does use some of that memory, if it doesn't access it for sufficiently long, it can still get ejected from physical memory through opportunistic swapping.

Unfortunately, you've waded into an extremely complex issue and it would take many pages to really explain it. There is a lot of incorrect information in the answers to this question.

David Schwartz

Posted 2009-11-06T18:43:20.307

Reputation: 58 310

0

You can see it using SysInternals' great application VMMap:

  1. First, you need to find the right process, so start for example Process Hacker or SysInternals' Process Explorer
  2. Display the list of processes as a tree
  3. Locate the process VBoxSVC.exe, it should have several child processes VBoxHeadless.exe if a VM is running
  4. If multiple VMs are running, there will be multiple branches of VBoxHeadless.exe processes, pick the right branch by checking process' command line, it contains an identifier of your VM
  5. You're interested in the lowest VBoxHeadless.exe in the branch (i.e. it doesn't have any more childs, just a parent, so it's a leaf), remember its PID
  6. Start VMMap
  7. Select the right VBoxHeadless.exe process by its PID and click OK

In my case, all reported Private bytes, Working set and Committed memory by VMMap almost exactly match the amount of memory assigned to the VM in VirtualBox.

Dawid Ferenczy Rogožan

Posted 2009-11-06T18:43:20.307

Reputation: 346