Kernel as hypervisor: Andrea Arcangeli

News
Mar 24, 20088 mins

A Linux kernel developer explains the key overlaps between the hypervisor and the OS kernel. The KVM architecture uses Linux as both, which puts new capabilities at the hypervisor’s disposal.

You’re now with Qumranet which is the company behind KVM. Can you briefly tell me about the design of KVM and how that differs from previous virtualization approaches such as Xen and VMware?

I really like this approach because when you start doing really advanced virtualizations features like swapping the guest memory and swapping different parts of the address space you start using the same algorithms that the normal Linux kernel is using for swapping normal processes and this avoids duplication of algorithms, and when the kernel is optimized to do better swapping the virtual machine gets the same benefits.

You have Linux itself taking on the role of the hypervisor, so you don’t have a hypervisor and then a different OS running as the guest. So Linux is the lowest level OS on the machine.

Exactly. It’s especially useful with features like shared memory between guests or ballooning, and when you want to have guarantees that a certain number of virtual machines won’t run the hypervisor out of memory. You can just start a lot of swap and share the memory and balloon with the guest and everything works very nicely.

Or you can guarantee a certain virtual machine to get more RAM, when you want to prioritize different guests to have more memory or less memory. So having the kernel algorithms doing both these operations really is clean and efficient.

And features like, say, power management you would have to implement those for Linux anyway and so you end up with power management at the kernel level already working rather than having to do it in the hypervisor too?

Yes the same exact advantage you get for virtual memory, you get for power management. Like you said the Linux kernel already has many power management features so you don’t have to write all those things in the hypervisor.

So the more you grow into advanced virtualization the more the design pays off and the more the hypervisor will start to look like a real operating system, full-blown with all the drivers and knowledge about hardware, and not any more just a little hypervisor doing all the memory management for the virtualization.

And Qumranet is the company behind KVM. What kind of projects attracted you to the opportunity to work at Qumranet?

I was really impressed by Qumranet so let me tell how this started. I just saw a patch from Avi who is one of the top kernel developers at Qumranet and he posted his KVM initial patch on the linux-kernel mailing list, and immediately I was impressed by the design and how really nicely it was integrated with the kernel. So I started looking into it and I discovered about Qumranet as well and I was really, really impressed by all the work Qumranet has been doing.

And I was excited to join and it’s really a nice project they founded, KVM, and so they are working as well in the commercial products which are using KVM of the core engine of their virtualization package. Solid ICE is the main one and manages all the kinds of virtual machines you can have on the server. You can very easily migrate machines from one virtual server to another, or stop to get the machines to start new guest. And it’s just really a click and everything works very nicely.

So, additionally on top of Solid ICE there is a protocol called SPICE which allows you to very nicely use a virtual machine remotely with multimedia and desktop features so you can watch movies, you can watch Youtube, and it really feels immediate and like being not on a virtualized desktop but on real hardware. So this protocol is really efficient. The combination of Solid ICE and SPICE provide the best of virtualization solution which is really impressive.

So from the point of view of Qumranet, they’re interested in hosting large numbers of, say, Microsoft Windows guests on a single server, and so if you’ve got all those copies of the same guest OS you’ve got many, many pages of memory that might turn out to be identical from guest to guest. How do you handle that problem and figure out a way to save memory on the host?

Qumranet developed a model called the KSM, Kernel Shared Memory, and this model actually works for all kinds of processes, not only on the guest, which are being shared in the same system, on the same host. And this model simply takes all the pages which are the same in the contents of the memory and it shares them, marking them read-only in the page tables. So whenever one of the guest try to modify these pages a copy-on-write operation is executed and memory is copied to a new page. And this allows sharing a lot of memory, like you said, with Windows guests and as well with Linux. Not only for Windows guests, it works for all kind of operating systems running on the KVM virtual machine.

And the nice thing about having the swapping as well is you can add a lot of swap to the host, so in this case it’s the hypervisor for KVM. And when you have a lot of swap you have the guarantee but even if each guest will generate copy-on-write operations for all the shared pages, still the whole system won’t run out of memory. So you have guarantees that each guest will keep running just fine. So having the hypervisor being the kernel really provides nice guarantees of advanced features to the virtualization.

So some of the memory of the guest OS can get swapped out just as if that guest were a conventional process some of whose pages are getting swapped out?

Exactly.

So what’s next for KVM?

First of all we need to get some support for the mainline kernel so we don’t have to patch the mainline kernel to get these advanced features, because the more KVM keeps evolving the more the mainline kernel has to support these new features. And so we need nice integration between the mainline kernel and KVM. This includes MMU notifiers and ballooning support which we need for paravirtualization, as well as paravirtualization itself.

So we want to have really high performance not only for desktop but for servers too. And this is actually an interest not only of Qumranet but especially of the community at large. So having this paravirtualization in the timers, in the I/O, in the networking, allows for very high performance and this is something the mainline kernel must support as well, when running as the guest.

Most of these is all included but still we are working on performance and SMP, and many additional features which will be emerging soon.

I saw some of the discussion about MMU notifiers on the linux-kernel mailing list. Can you tell me about that feature and how that’s important for virtualization?

Oh yes. I actually developed it myself so I’m really qualified to answer. The MMU notifiers are a way that the kernel tells KVM whenever it stops mapping a certain page into the guest address space, so the kernel actually is swapping the page to disk but the page can only be freed if KVM knows this page has to be swapped out. So without the MMU notifiers, the swapping of the KWM virtual machine is not entirely reliable and to get 100% percent liable swapping we need them. We need the KVM virtual machine to know exactly when the kernel stops using this page.

The KVM virtual machine will as well stop using the page. And eventually when and KVM gets the machine to stop using the page the page will be freed immediately.

KVM, of course, facilitates running Microsoft Windows as a guest. Did Microsoft’s recent opening up of a bunch of specifications effect KVM development in any way?

I’m not very much involved with the Windows virtualization development. And I think there are some issue with optimizing certain APIC operations because for whatever reason Window is doing strange things with IO APIC, so we need some tricks to get higher performance but apart from that there’s not – – not real dependency on certain operating systems as guests.

We try to optimize the virtual machine so all the guests will run faster. So all the performance work done and hardware work done is not specific to certain operating systems . And KVM really tries to be as transparent as possible to each guest.

Thank you very much for being on the podcast, Andrea. Is there anything else you’d like to add?

I’m glad to be here and I hope people will like KVM as much as I do. And I hope they will find it useable and try Qumranet products because they are really impressive. So that’s all I want to say.

Thanks again Andrea.

Thank you very much. Bye.

Listen on the podcast page, or subscribe to the podcast.