Ballooning in VM memory management

Shradha Gupta
3 min readMar 15, 2021

While performing some tests related to vmware DRS, on some highly loaded virtual machines, I happened to come across a kernel dump with vmmemctl stacks. The stack corresponds to a very common feature in virtualization called memory ballooning. It is hypervisor’s way of performing memory management without having to over-provision the VMs.

To perform this memory management, a special balloon device driver is loaded and configured in every guest OS by the hypervisor. This driver is the key for managing memory pressure experienced by any guest operating system.

Memory management with the balloon driver

In events were the memory requirement from a guest is high and the hypervisor does not have enough free resources to handle the request from this guest, it connects with the balloon drivers on all the other guests. The hypervisor in such conditions, instructs the balloon drivers to inflate. Inflation of this balloon is essentially the key to relinquishing the memory that is not actively used by the respective VMs.

In the inflation operation the hypervisor instructs the balloon driver in guest OS to request for as much memory as possible from the allocation pool of this guest. The idea is that under such increased memory pressure inside the VM, the guest OS would be forced to perform pageout operation to the disk for all the memory that is not actively being used by this guest. The result of this operation is that the guest has now assigned to the balloon driver, a chunk of free memory that was previously not being used actively by the same guest. The Balloon driver gives this memory to the hypervisor, which could now be used to handle the memory request from the guest/VM that had requested for the same.

Inflation of the balloon under high pressure.

This inflated balloon of memory in the VM can also be reassigned to the VM, when the memory load on the host decreases and the VM now needs more physical memory. This happens through a process called deflation. Deflation is a request to the respective balloon driver in the VM to contract its memory footprint. This means the balloon driver returns the memory back to the Guest OS, so that the guest could use it for the other processes that are requesting it.

Note that the inflate and deflate calls in the guest are only allowed by the hypervisor, as the device driver is specifically installed by the hypervisor. This technique of memory ballooning assumes co-operation by the guest OS, so that the hypervisor can manage memory efficiently based on the need of the hour.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response