KVM and QEMU – do you know the connection?
If you were to ask someone “what is the most popular open source hypervisor” chances are that the answer will be KVM. Indeed KVM (or Kernel-based Virtual Machine) has played a key role in the open source Linux based virtualization environment. However is it really a hypervisor? Moreover, can KVM by itself run virtual machines? We will delve more into such questions in this blog. We will also understand the relationship between KVM and QEMU (Quick EMUlator).
KVM and QEMU – the process ID check
You can use libvirt and the associated Virtual Machine Manager GUI to start a virtual machine. In the GUI, you can choose the ‘Virt Type’ as either KVM or QEMU. I started a VM, once with QEMU as the Virt Type and once with KVM. In both cases, I did a grep of the process ID to see if there was any difference. Note: I used Ubuntu 13.10 for my experiments.
When I started the VM with KVM as the Virt Type the process ID details showed an interesting attribute “accel=kvm” as highlighted below.
When I started the same Virtual Machine with QEMU as the Virt Type, the process ID showed “accel=tcg”.
Note that in both the cases the same binary is executed to start the VM, namely, qemu-system-x86_64. The main difference is the acceleration type.
KVM and QEMU – understanding hardware acceleration
To understand hardware acceleration, we must understand how Virtual Machine CPU works. In real hardware, the Operating System (OS) translates programs into instructions that are executed by the physical CPU. In a virtual machine, the same thing happens. However, the key difference is that the Virtual CPU is actually emulated (or virtualized) by the hypervisor. Therefore, the hypervisor software has to translate the instructions meant for the Virtual CPU and convert it into instructions for the physical CPU. This translation has a big performance overhead.
To minimize this performance overhead, modern processors support virtualization extensions. Intel support a technology called VT-x and the AMD equivalent is AMD-V. Using these technologies, a slice of physical CPU can be directly mapped to the Virtual CPU. Hence the instructions meant for the Virtual CPU can be directly executed the physical CPU slice.
KVM is the Linux kernel module that enables this mapping of physical CPU to Virtual CPU. This mapping provides the hardware acceleration for Virtual Machine and boosts its performance. Moreover, QEMU uses this acceleration when Virt Type is chosen as KVM.
Then what is TCG? If your server CPU does not support virtualization extension, then it is the job of the emulator (or hypervisor) to execute the Virtual CPU instruction using translation. QEMU uses TCG or Tiny Code Generator to optimally translate and execute the Virtual CPU instructions on the physical CPU.
KVM and QEMU – Type 1 or Type 2 hypervisor
The web pages of KVM and QEMU clearly show that KVM needs QEMU to provide full hypervisor functionality. By itself, KVM is more of a virtualization infrastructure provider.
QEMU by itself is a Type-2 hypervisor. It intercepts the instructions meant for Virtual CPU and uses the host operating system to get those instructions executed on the physical CPU. When QEMU uses KVM for hardware acceleration, the combination becomes a Type-1 hypervisor. This difference is quite clear from the description on the QEMU website.
KVM and QEMU – the x86 dependency
Since KVM is really a driver for the physical CPU capabilities, it is very tightly associated with the CPU architecture (the x86 architecture). This means that the benefits of hardware acceleration will be available only if the Virtual Machine CPU also uses the same architecture (x86).
If a VM needs to run Power PC CPU but the hypervisor server has an Intel CPU, then KVM will not work. You must use QEMU as the Virt Type and live with the performance overhead.
KVM and QEMU – the conclusion
Based on the discussion above, it is quite clear that QEMU plays a very critical role in Linux based Open Source virtualization solutions. For all practical applications, QEMU needs KVM’s performance boost. However, it is clear that KVM by itself cannot provide the complete virtualization solution. It needs QEMU.
=====================================================================
KVM: Bare-Metal Hypervisor?
I need to turn to you, knowledgeable readers, for help in answering some questions. In a followup to yesterday's announcement by Red Hat about its virtualization roadmap, I asked the company some questions about the new Enterprise Hypervisor.
Specifically, I wanted some details about how KVM would work as a standalone hypervisor, since my understanding is that it's hosted inside the Linux kernel (i.e., a Type II hypervisor). The response I got from Navin Thadani, senior director, virtualization business at Red Hat, threw me for a bit of a loop. He says KVM is a bare-metal hypervisor (also known as Type I), and even tries to make the case that Xen is a hosted hypervisor. Here's his comment in full:
It is a myth that KVM is not a Type-1 hypervisor. KVM converts Linux into a Type-1 hypervisor. There is only one kernel that is used (and that is the Linux kernel, which has KVM included). On the flip side, I can make an argument that Xen is not a Type-1 hypervisor, because the CPU and memory is scheduled by the hypervisor, but IO is scheduled by Dom0, which is a guest (so it's not bare metal). In the KVM architecture, the CPU, memory, and IO are scheduled by the Linux kernel with KVM.
On the other hand, other folks fall into the "KVM is a hosted hypervisor" camp, exemplified by this snippet from Brian Madden:
Xen folks attack KVM, saying it's like VMware Server (the free one that was called "GSX") or Microsoft Virtual Server because it's really a Type 2 hypervisor that runs on top of another OS, rather than a "real" Type 1 hypervisor. KVM responds "So what? Why should we rewrite an OS from scratch when something like Linux is available? And if you want to use a KVM machine as a dedicated VM host, then fine, just don't install anything else on that box."
So, is KVM hosted or not? Is Xen hosted or not? Is Red Hat full of hot air, or are they onto something? I'll be honest and say that I just don't know. Thadani upset my hypervisor apple cart with this comment. But, with your help, I'll get to the bottom of it. Weigh in in the comments below, or e-mail me directly. As a follow-up, tell me what difference you think it makes in the grand scheme of things ("it" being whether KVM is hosted or not, and the same thing about Xen). I'll post comments as they come in. If you do not want your name used with your comments, let me know.
Simply: Kvm is not an application of the system, after you enable the module kvm.ko it modifies the kernel so that the kvm kernel on this hardware. So like a bare metal.
No comments:
Post a Comment