Reclaiming memory and memory issues

Completed

To maintain full isolation, guest OSs are kept unaware that they are running inside VMs. VMs are also kept unaware of the states of other VMs running on the same physical host. Furthermore, with multiple levels of page mapping, VMs remain oblivious of any physical memory shortage. Therefore, when the hypervisor runs multiple VMs at a physical host, and the physical memory turns stressed, none of the VMs can automatically help in freeing up memory.

The hypervisor deals with the situation by applying a reclamation technique. As its name suggests, a reclamation technique attempts to reclaim inactive real memory pages at VMs and make them available for the hypervisor when experiencing a memory shortage. This video describes a couple of techniques that can be used to reclaim memory from guest OSs:

One of the popular reclamation techniques is the ballooning process introduced in VMware ESXi, which has been the basis for similar techniques in other hypervisors.

The ballooning process in VMware ESXi.

Figure 4: The ballooning process in VMware ESXi

In VMware ESXi, a balloon driver must be installed and enabled in each guest OS as a pseudo-device driver. The balloon driver regularly polls the hypervisor through a private channel to obtain a target balloon size. As illustrated in Figure 4, when the hypervisor experiences a memory shortage, it inflates the balloon by setting a proper target balloon size. The left side of Figure 4 shows four real memory pages mapped to four physical pages, of which only two pages are actually active (the red and the yellow ones). Without involving the ballooning process, the hypervisor is unaware of the other two inactive pages (the green and the dark-blue ones) because they are still mapped to physical pages. Consequently, the hypervisor will not be able to reclaim inactive pages unless it is informed by the guest OSs it is managing. With memory ballooning, however, the hypervisor can set the balloon target size to an integer number (say 2 or 3). When recognized by the balloon driver at the guest OS, the driver checks out the pages, locates the two inactive pages, and pins them (see the right side of Figure 4). The pinning process is carried out by the guest OS via ensuring that the pinned pages cannot be read/written by any process during memory reclamation. After pinning the inactive pages, the balloon driver transmits to the hypervisor the addresses of the pinned pages. Subsequently, the hypervisor proceeds safely with reclaiming the respective physical pages and allocating them to VMs. Last, to unpin pinned pages, the hypervisor deflates the balloon by setting a smaller target balloon size and communicates that to the balloon driver. When the balloon driver receives the communication, it unpins the pinned pages so the guest OS can utilize them. More information about the ballooning process can be found in the VMware ESXi documentation.

Check your knowledge

1.

True or false? The hypervisor can automatically reclaim pages when deactivated by guest OSs.

2.

Consider the following memory state as imposed by two VMs running on a single physical host:

Diagram showing the memory state of a hypervisor with blocks corresponding with two virtual machines, VM1 and VM2. From left to right, the hypervisor shows a pinned page from VM1, then a pinned page from VM2, then a pinned page from VM1, then two pinned pages from VM2, and lastly a pinned page from VM1. VM1 has a sub block with one pinned page and one unlinked pinned page. VM2 has a sub block with two unlinked pinned pages.
Assume that the shown hypervisor employs a ballooning process.

How would the hypervisor recognize inactive pages to reclaim them?

3.

How many pages in total can the hypervisor reclaim when applying the ballooning process?