How to increase/decrease kvm guest memory dynamically?

It is possible !!! RHEL includes balloon driver ( from 5.5 onwards) for kvm guests. The virtio_balloon driver is loaded automatically with RHEL kernels. If a user attempts to balloon a KVM guest the balloon command ( #virsh setmem) will successfully allow a user to change the memory assignment of the guest. # virsh setmem … Read more

Memory ballooning and virtio_balloon driver in qemu-kvm

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
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 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.

KVM "cpu0 unimplemented perfctr wrmsr: 0x186 data 0x130079" messages are seen in logs

Usally I look into /var/log/messages file for troubleshooting issues and I have noticed below messages in my fedora 14 system logs. I was discarding it as I know it is harmless, but today I thought of blogging it because so many are worried about it. [terminal] Nov19 13:27:02 humbles-lap kernel: [903605.793414] kvm: 1541: cpu0 unhandled … Read more

"KVM is disabled by BIOS" messages are seen in logs even-though processor support Virtualization

“KVM is disabled by BIOS” message appears in logs .. Once I noticed, I am not able to use virtualization in my test system . I know my test system support Full virtualization , still no luck.. If you came across something like this , you have to isolate the possibilites one by one . … Read more

Xen and Kvm

Hey Guys , Thought of sharing some bits on most popular open source virtualization technologies .. Yeah .. it is “Xen” and “Kvm“. Mainly I am focusing more on the hypervisor loading process and features. Xen Xen originated as a research project at the University of Cambridge, led by Ian Pratt, senior lecturer at Cambridge … Read more

What is virtualization ? and different types of virtualization

What is virtualization? In philosophy virtual means, “something that is not real”. In computer science virtual means, “a hardware environment that is not real”. Here we duplicate the functions of physical hardware and present it to an operating system (OS). The technology that is used to achieve  this environment can be called as Virtualization technology, … Read more

How can I increase a virtual image disk space if it is created on a file image

This is a very useful method in your real life.. I have come across to increase the space in virtual machine when it created on a file image .. You can try any of the below to increase the space depending on the virtual guest’s storage .. That being said , it is possible to … Read more

How can we do pci pass-through or device assignment with kvm?

This is a very interesting feature which provides you the capability of passing a “PCI” device to a guest system bypassing the HOST . Below Red Hat kbase gives you information about doing pci pass-through with XEN. http://kbase.redhat.com/faq/docs/DOC-17364 With KVM , pci pass-through can be achieved by two ways. * virt-manager* Command line method. PCI … Read more