Lots of people have heard the word “ballooning” and had a thought about it. In the 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 of 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 applications running in your host system. Sometimes a host system which hosting these different applications can run out of memory or in need of memory… At that time, using this balloon device, the host system can request memory from the guest. which will cause an inflate operation of the balloon device inside the guest. Once the balloon is filled ( memory /pages ) by guests, it can give that to the host system. The vice versa operation is also going in this way.
Now you know, host<-> guest co-operation is required for smooth operation of ‘memory ballooning’. At the time of ‘inflate’ operation, think about ‘unused’ memory in the guest system. This memory is given back to the 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 with this.
What commands can be used to give/take memory from guests? 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
memballoon model='virtio' ========== virtio driver is used as balloon driver. If you want to disable ballooning use 'none'.
Now, check the memory inside the guest.
You will be seeing something 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 work!
I hope you enjoyed this article. Please feel free to ask your questions here or leave a comment.