qemu-kvm reclamation of memory from low-use guests

9,782

You can turn on automatic ballooning in a libvirt guest by editing the XML:

<memballoon model='virtio'>

The virtual memory balloon device takes a parameter autodeflate, which defaults to off. Set it to on to enable automatic ballooning.

<memballoon model='virtio' autodeflate='on'>

Note that there is no GUI option in virt-manager to enable or disable this setting.

If you're calling qemu manually (please save your sanity and don't) then add ,automatic=true to the balloon device, e.g. -device virtio-balloon,automatic=true.

Autoballooning requires qemu/kvm 1.3.1 or later.

Note that this probably won't solve all your memory contention problems; it's best to simply have enough RAM to run all your virtual machines.

Share:
9,782
Devon
Author by

Devon

Updated on September 18, 2022

Comments

  • Devon
    Devon almost 2 years

    Is there a way to transparently reclaim, or prevent usage of, memory from a qemu-kvm guest?

    Scenario A:

    A guest uses 8GB of RAM during peak hours, it returns back to 4GB of usage at night, but the guest is still claiming 8GB of RAM from the host.

    Scenario B:

    A guest uses 2GB of RAM, but has 6GB of RAM in page cache. The guest is claiming 8GB of RAM from the host, but up to 6GB of it could be RAM that could be have more importance in another guest system.


    My first thoughts on ballooning was that the guest would not "see" the ballooning effect, but when sending "balloon 2048", the memory inside the guest is actually reduced to ~2GB.

  • Piotr Jurkiewicz
    Piotr Jurkiewicz about 6 years
    There is no automatic=true option for device virtio-balloon. libvirt's autodeflate corresponds to deflate-on-oom=on.
  • Michael Hampton
    Michael Hampton almost 5 years
    This just kills your performance to no purpose. The cache was already available to the system if it actually needed it.