Different hypervisors do things differntly. In this post, we take a look at some of the memory reclamation techniques employed by the most popular hypervisors today.

The below table sums things up nicely:

METHODESX(i)HYPER-VKVMXEN
Transparent page sharingYY
Memory BallooningYYYY
CompressY
SwappingYYY
Memory hot-addY
Transcendent memoryY

Transparent page sharing

When there are multiple virtual machines running on the same hypervisor, most of the time some of them might have identical sets of memory content (known as memory pages). These pages can be shared across these VMs.

Memory ballooning

Memory ballooning makes the guest operating system aware that it does not have enough memory from the host, so that the guest operating system frees some of its memory. This is done via a balloon driver.  When there is a memory crisis, hypervisor tells the balloon driver to request some memory from the guest operating system. The hypervisor knows that pages occupied by the balloon driver will never store data, so the pages of RAM backing the balloon driver can then be reallocated safely to other VMs

Memory compression

Pages are compressed and stored in a cache on the main memory itself. These pages can be accessed again just by a decompression rather than through disk I/O in the case of page swapping which can significantly improve application performance when the host is under memory pressure. If a page cannot be compressed, it will be swapped out.


Swapping

This is generally used as a last resort to reclaim memory. In this technique, the hypervisor creates a separate swap file for each virtual machine when it is powered on and swaps out guest physical memory thus freeing up host memory.

Memory Hot-Add(Dynamic Memory)

Each VM is configured with a small initial RAM when powered on. When the guest applications require more memory, a certain amount of memory will be hot-added to the VM and the guest OS. Ballooning is used to reclaim memory not being used.

Transcendent memory

The idle memory is collected into a pool and distributed based on the demand of running VMs. This approach requires the guest OS to be paravirtualized.