UNDER THE HOOD, KVM AND QEMU WORKING TOGETHER
There are a lot of questions about how KVM and QEMU works… What is the difference between them? How they work together? How is doing these technologies to achieve a powerful experience in virtualization? You need to read this.
KVM ( Kernel-based Virtual Machine) is a virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V). The kernel component of KVM is included in mainline Linux, as of 2.6.20. KVM is open source software. KVM has played a key role in the open source Linux based virtualization environment.
QEMU (Quick EMUlator) is a generic and open source machine emulator and virtualizer. Is a free and open-source hosted hypervisor that performs hardware virtualization QEMU emulates central processing units through dynamic binary translation and provides a set of device models, enabling it to run a variety of unmodified guest operating systems
So In real hardware, the Operating System translates programs into instructions that are executed by the physical CPU. In a virtual machine is the same but the difference is that the Virtual CPU is virtualized by the hypervisor and the hypervisor needs to translate the instructions for the Virtual CPU and convert it into instructions for the physical CPU. This translation has a big performance overhead.
To minimize this overhead,processors support virtualization extensions. Intel support a technology called VT-x and the AMD equivalent is AMD-V. Using these, a slice of physical CPU can be directly mapped to the Virtual CPU. So the instructions or 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. In fact QEMU uses this acceleration when Virt Type is chosen as KVM. When working together, KVM access irectly to the CPU and memory, and QEMU emulates the hardware resources like hard disk, video, USB, etc,
If your server CPU does not support virtualization extension, you will not be able to use KVM and it is the job of the 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 but you will have a performance overhead.
KVM needs Qemu (emulator) for full hypervisor functionality. QEMU is self-sufficient and KVM is really a Linux kernel module for exploiting VT-extenstions to act as driver for the physical CPU capabilities.
So, we can say QEMU needs KVM’s performance boost and KVM by itself cannot provide the complete virtualization solution, it needs QEMU.