Projects/auto-ballooning: Difference between revisions

From KVM
No edit summary
No edit summary
Line 29: Line 29:
'''Guest kernel:'''
'''Guest kernel:'''


git://repo.or.cz/linux-2.6/luiz-linux-2.6.git virtio-balloon/pressure-notification/rfc.v1
[http://repo.or.cz/w/linux-2.6/luiz-linux-2.6.git git://repo.or.cz/linux-2.6/luiz-linux-2.6.git] virtio-balloon/pressure-notification/rfc.v1


'''QEMU:'''
'''QEMU:'''


git://repo.or.cz/qemu/qmp-unstable.git balloon-automatic/handle-all-events/rfc.v1
[http://repo.or.cz/w/qemu/qmp-unstable.git git://repo.or.cz/qemu/qmp-unstable.git] balloon-automatic/handle-all-events/rfc.v1


== Testing ==
== Testing ==

Revision as of 15:39, 16 January 2014

Automatic Ballooning

Introduction

The balloon feature allows KVM guests to reduce their memory size (thus relinquishing memory to the host) and to increase back (thus taking memory from the host).

This feature is mainly intended to support memory over-committed hosts. That is, hosts that are running VMs whose total memory size is greater than what the host has physically available. For example, a 2G host running two VMs each with 2G would be over-committed.

The balloon feature is important to support memory over-commitment because it allows for reducing a guest's memory size if needed. Suppose, in the example above, that one of the guests is using 1G and its other 1G is free. We could use the balloon to reduce this guest's size from 2G to 1G, this would free 1G in the host allowing the other VM to use it. Of course, if the reduced guest wants to run an application that consumes more than the 1G it currently has, it has to grow again.

That's the problem with the current balloon feature, it's entirely manual. Someone (or some tool) is supposed to be watching the pressure in the host and guest and then operate the balloon accordingly. This is just not doable in practice.

The balloon has to be automatic in order to be really useful. It could like this: when the host is under pressure, VMs with spare memory automatically reduce their size by some megas. When a VM get into memory pressure (maybe because they relinquished memory to host) it increases its size by some megas. That's exactly what the automatic ballooning patch series does.

KVM Forum 2013 presentation slides

They can be found here. But note that much has changed since this talk.

Patches and Git trees

Latest RFC version posted upstream

Guest kernel: RFC PATCH 0/4 virtio_balloon: add pressure notification via a new virtqueue

QEMU: RFC PATCH balloon: add automatic ballooning support

Git trees

Guest kernel:

git://repo.or.cz/linux-2.6/luiz-linux-2.6.git virtio-balloon/pressure-notification/rfc.v1

QEMU:

git://repo.or.cz/qemu/qmp-unstable.git balloon-automatic/handle-all-events/rfc.v1

Testing

Setup:

  1. Install kernel 3.10 or higher in your host. Make sure the kernel options CONFIG_CGROUPS and CONFIG_MEMCG are enabled
  2. Build QEMU from the Git trees section
  3. Build and install the guest kernel from the Git trees section

Then start qemu with:

# qemu [...] -device virtio-balloon,automatic=true

To see automatic ballooning in action, do the following:

  1. Generate pressure in your host (like running several VMs in parallel); or connect to QMP and issue the balloon-inject-host-pressure command
  2. You can monitor automatic ballooning activity by issuing info balloon in QEMU's monitor (also, I have debug code enabled that will dump a lot of info to stdout when "info balloon" is issued)
  3. After the guest has shrinked a bit, you can generate pressure in the guest to see it increasing its size again