Kernel

Memory ballooning and virtio_balloon driver in qemu-kvm

 

Lots of people have heard this word “ballooning” and had a thought about it ..  In computer world, this word is mostly aligned with ‘virtualization’.. I will try to explain ‘memory ballooning’ in this blog.

In simple terms a virtual environment composed with  2 things.

1) HOST and 2) GUEST..  Let me explain these 2 terms in a layman language. Virtualization is used to run another operating system inside your computer. The operating system running in your hardware can be called ‘HOST’ and the other operating system running in your HOST is called GUEST.

I have to answer that, guest memory is derived from Host memory. That is obvious. I am not explaining more about it, only because I just dont want to invite more confusion here..

coming into the word ‘balloon’, we all know there can be two actions inflate/deflate wrt to balloon. Inflate means ‘you are filling something in it”, deflate do opposite action.. Now, how these all terms fit into virtualization..

The guest system will include a balloon ( a balloon driver ex: virtio_balloon) which can be inflated or deflated.. Why we need that? as I mentioned above, guest memory is part of the host memory.. There will be different application running in your host system. Sometimes host system which hosting these different applications can run out of memory or in need of memory.. .. At that time, using this balloon device , host system can request memory from the guest. which will cause an inflate operation of balloon device inside guest. Once the balloon is filled ( memory /pages ) by guest , it can give that to the host system. The vice versa operation is also goes in this way..

Now you know, host<-> guest co-operation is required for smooth operation of ‘memory ballooning’ .. At time of ‘inflate’ operation, think about ‘unused’ memory in guest system. This memory is given back to host. How-ever inflate operation can increase memory pressure in the guest..or you may see high ‘swapping’ in your guest..

The operation chain can look like this:

  • Request ( from host ) to reclaim memory =====> “inflate” operation inside the guest ::
  • Then guest send this memory back to host/hypervisor..

In qemu-kvm setup , virtio_balloon is the balloon driver which will be loaded in the guest system for the balloon device..

Inflate  and Deflate operation ( In my bad art skills ? 🙂 ) :

1) Inflate operation of virtio balloon driver:

 

 

 

 

 

 

 

 

 

2) Deflate operation of virtio balloon driver

 

 

 

 

 

 

 

 

 

 

Now, there can be some questions like, Is it the hot memory add feature? I cannot agree on this.

What commands can be used to give/take memory from guest ? in libvirt, qemu-kvm setup you can use ‘virsh setmem’ command for the same purpose..

Demo:

[root@humbles-lap misc]# virsh dumpxml 1
524288 ========== This is the maximuim memory set for this guest
524288 ========== current allocated memory

memballoon model=’virtio’ ========== virtio driver is used as balloon driver. If you want to disable ballooning use ‘none’.


Now, check the the memory inside the guest..

You will be seeing somthing near to ‘524288’..

Once you confirmed above, try to set memory as shown in below example:

#virsh setmem 24161

Now check the memory inside your guest..

This is how virtio_ballon or balloon drivers works !

Hope you enjoyed this article .. Please feel free to ask your questions here or leave a comment..

3 thoughts on “Memory ballooning and virtio_balloon driver in qemu-kvm”

  1. Hello and thank you for this article) Can you explain me the next feature? When im decreasing memory with the help of virsh, the amount of memory in guest machine decreases too. But still, on the host system there is no visible released memory from guest system. Is it reserved only for serious accidents? How can i see the amount of this RAM?

Leave a Reply

Your email address will not be published. Required fields are marked *