I would like a certain Linux guest running in QEMU to release memory before the host is under memory pressure. How can I manually trigger the virtio balloon driver on a guest so that it releases as much memory as possible?

  • 1
    First, the size of the balloon is controlled by the host, not the client; as far as I can see there is no way to increase the balloon from the clients side. Second, what is "as much memory as possible"? The host may reclaim memory from the client even if the client has to clear its buffers and even start swapping.
    – ridgy
    Dec 28, 2017 at 17:24

1 Answer 1


Something like this seems to work: first reduce the amount of memory available to the guest, then (optionally) restore it to the original setting.

virsh --connect qemu:///system qemu-monitor-command --domain NAME --hmp 'balloon 512'
# Wait for the balloon driver to release some memory
sleep 2
virsh --connect qemu:///system qemu-monitor-command --domain NAME --hmp 'balloon 4096'

Or, as a proper script:


set -eu

# How many MB to temporarily reduce the guest memory to; don't set this too
# low or the OOM killer will start killing.

hmp() {
    virsh --connect qemu:///system qemu-monitor-command --domain "$domain" --hmp "$1"

original_memory=$(hmp "info balloon" | grep = | cut -d '=' -f 2)
hmp "balloon $reduced_memory" > /dev/null
# Wait for the balloon driver to release some memory before setting it back
sleep 2
hmp "balloon $original_memory" > /dev/null

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .