Virtualization & Containers

memory ballooning

Memory ballooning is a clever way for a hypervisor to reclaim unused memory from a virtual machine that does not want to give it back. The problem it solves comes from overcommit: a host often promises its VMs more total memory than it physically has, betting that they will not all need their full share at once. When the host does run short, it needs to take memory back from a VM — but the guest OS thinks all its memory is its own and will not volunteer any. The hypervisor cannot just snatch pages, because that could corrupt the guest. It needs the guest's cooperation.

The trick is a balloon driver installed inside the guest. When the host is under memory pressure, it tells this driver to inflate: the driver allocates a chunk of guest memory for itself and pins it, as if the guest were genuinely using it. From the guest OS's point of view that memory is now in use, so the guest stops touching it — and crucially, the driver then hands those now-idle physical frames back to the hypervisor, which can give them to a needier VM. When pressure eases, the host tells the driver to deflate, freeing the memory back to the guest. The balloon, in effect, applies polite pressure inside the guest so the guest itself decides what to give up.

Ballooning matters because it lets a host run more VMs than its raw RAM would allow, smoothing out the fact that VMs rarely all peak together. The honest caveat is that it is not magic memory creation: if every VM genuinely needs all its memory at once, ballooning cannot help and the host must fall back to slow disk swapping, which can hurt performance badly. Inflate the balloon too aggressively and you can even push a guest into thrashing. It is a tool for reclaiming idle memory, not for inventing memory that is not there.

A host has 64 GB but has promised 80 GB across its VMs. When free memory runs low, it asks an idle VM's balloon driver to grab 8 GB inside that guest. The guest, now seeing less free memory, releases caches it did not really need; those 8 GB of frames go to a busy VM that needed them.

The balloon driver applies pressure inside the guest so it frees memory the host can reuse.

Ballooning reclaims idle memory; it does not create memory. If guests truly need all their RAM simultaneously, overcommit fails and the host must swap to disk, which is far slower — ballooning relies on the bet that VMs do not all peak at once.

Also called
balloon driver氣球驅動程式