In server environments with many VMs; the Guest Additions can be used to share physical host memory between several VMs, reducing the total amount of memory in use by the VMs. If memory usage is the limiting factor and CPU resources are still available, this can help with packing more VMs on each host.
Starting with version 3.2, the Guest Additions of VirtualBox can change the amount of host memory that a VM uses while the machine is running. Because of how this is implemented, this feature is called "memory ballooning".
Note
VirtualBox supports memory ballooning only on 64-bit hosts, and it is not supported on Mac OS X hosts.
Note
Memory ballooning does not work with large pages enabled. To
turn off large pages support for a VM, run
VBoxManage modifyvm <VM name> --largepages off
Normally, to change the amount of memory allocated to a virtual machine, one has to shut down the virtual machine entirely and modify its settings. With memory ballooning, memory that was allocated for a virtual machine can be given to another virtual machine without having to shut the machine down.
When memory ballooning is requested, the VirtualBox Guest Additions (which run inside the guest) allocate physical memory from the guest operating system on the kernel level and lock this memory down in the guest. This ensures that the guest will not use that memory any longer: no guest applications can allocate it, and the guest kernel will not use it either. VirtualBox can then re-use this memory and give it to another virtual machine.
The memory made available through the ballooning mechanism is only available for re-use by VirtualBox. It is not returned as free memory to the host. Requesting balloon memory from a running guest will therefore not increase the amount of free, unallocated memory on the host. Effectively, memory ballooning is therefore a memory overcommitment mechanism for multiple virtual machines while they are running. This can be useful to temporarily start another machine, or in more complicated environments, for sophisticated memory management of many virtual machines that may be running in parallel depending on how memory is used by the guests.
At this time, memory ballooning is only supported through VBoxManage. Use the following command to increase or decrease the size of the memory balloon within a running virtual machine that has Guest Additions installed:
VBoxManage controlvm "VM name" guestmemoryballoon <n>
where
"VM name"
is the name or UUID of the
virtual machine in question and
<n>
is the amount of memory to
allocate from the guest in megabytes. See Section 8.13, “VBoxManage controlvm” for more information.
You can also set a default balloon that will automatically be requested from the VM every time after it has started up with the following command:
VBoxManage modifyvm "VM name" --guestmemoryballoon <n>
By default, no balloon memory is allocated. This is a VM setting,
like other modifyvm
settings, and
therefore can only be set while the machine is shut down; see Section 8.8, “VBoxManage modifyvm”.
Whereas memory ballooning simply reduces the amount of RAM that is available to a VM, Page Fusion works differently: it avoids memory duplication between several similar running VMs.
In a server environment running several similar VMs (e.g. with identical operating systems) on the same host, lots of memory pages are identical. VirtualBox's Page Fusion technology, introduced with VirtualBox 3.2, is a novel technique to efficiently identify these identical memory pages and share them between multiple VMs.
Note
VirtualBox supports Page Fusion only on 64-bit hosts, and it is not supported on Mac OS X hosts. Page Fusion currently works only with Windows guests (2000 and later).
The more similar the VMs on a given host are, the more efficiently Page Fusion can reduce the amount of host memory that is in use. It therefore works best if all VMs on a host run identical operating systems (e.g. Windows XP Service Pack 2). Instead of having a complete copy of each operating system in each VM, Page Fusion identifies the identical memory pages in use by these operating systems and eliminates the duplicates, sharing host memory between several machines ("deduplication"). If a VM tries to modify a page that has been shared with other VMs, a new page is allocated again for that VM with a copy of the shared page ("copy on write"). All this is fully transparent to the virtual machine.
You may be familiar with this kind of memory overcommitment from other hypervisor products, which call this feature "page sharing" or "same page merging". However, Page Fusion differs significantly from those other solutions, whose approaches have several drawbacks:
-
Traditional hypervisors scan all guest memory and compute checksums (hashes) for every single memory page. Then, they look for pages with identical hashes and compare the entire content of those pages; if two pages produce the same hash, it is very likely that the pages are identical in content. This, of course, can take rather long, especially if the system is not idling. As a result, the additional memory only becomes available after a significant amount of time (this can be hours or even days!). Even worse, this kind of page sharing algorithm generally consumes significant CPU resources and increases the virtualization overhead by 10-20%.
Page Fusion in VirtualBox uses logic in the VirtualBox Guest Additions to quickly identify memory cells that are most likely identical across VMs. It can therefore achieve most of the possible savings of page sharing almost immediately and with almost no overhead.
-
Page Fusion is also much less likely to be confused by identical memory that it will eliminate just to learn seconds later that the memory will now change and having to perform a highly expensive and often service-disrupting reallocation.
At this time, Page Fusion can only be controlled with VBoxManage, and only while a VM is shut down. To enable Page Fusion for a VM, use the following command:
VBoxManage modifyvm "VM name" --pagefusion on
You can observe Page Fusion operation using some metrics.
RAM/VMM/Shared
shows the total amount
of fused pages, whereas the per-VM metric
Guest/RAM/Usage/Shared
will return the
amount of fused memory for a given VM. Please refer to Section 8.35, “VBoxManage metrics” for information on how to query metrics.
Note
Enabling Page Fusion might indirectly increase the chances for malicious guests to successfully attack other VMs running on the same host, see Section 13.3.4, “Potentially insecure operations”.