KVM or QEMU: Which Runs My Virtual Machine?
While working with Openstack on both VMware virtual machines (with no virtualization instruction set exposed) and physical machines, I found virtual machine instances can be deployed seamlessly. On a machine that does not have virtualization instruction set exposed, KVM falls back to QEMU silently. That is why could I try out OpenStack on virtual machines before my hardware was ready. Because both KVM and QEMU support the same libvirt APIs, you would not notice any difference using command line like virsh, or Virtualization Manager. That is the beauty of standard APIs with different implementations, similar to the standard vSphere APIs that are implemented by both vCenter and ESXi.
That being said, the performance difference between KVM and QEMU could be big. As you may have known, QEMU is really emulation therefore it’s much slower than KVM. If you are running something for testing, you may not notice the difference. But in production, you definitely want to use KVM over QEMU.
Lost VMs or Containers? Too Many Consoles? Too Slow GUI? Time to learn how to "Google" and manage your VMware and clouds in a fast and secure HTML5 App.
Anyway, I was curious whether if KVM is really running on my physical deployment. So I started to research a bit and here are my findings.
Because of the performance advantage, KVM is always preferred over QEMU. But KVM has to run with virtualization instruction set, meaning if the hardware support is not there it must be QEMU that runs your virtual machines.
On the machine you run KVM/QEMU, you can examine the cpuinfo as follows. If you see a non-zero value, it has virtualization support. It of course does not mean it has KVM running. The BIOS has to be configured as well.
[root@node1 ~]# egrep -c '(vmx|svm)' /proc/cpuinfo 24
If you see a zero value, it means it must be QEMU. If you install KVM/QEMU on a virtual machine that does not have virtualization set exposed, that is what you’ll see. Nowadays, it’s hard to find physical servers without virtualization instruction set. When you see zero value, check the BIOS.
[root@hq ~]# egrep -c '(vmx|svm)' /proc/cpuinfo 0
You can list the modules in the Linux Kernel using the lsmod command as follows. If KVM is running, you should be able to see something like the following; otherwise, nothing after the command.
[root@node1 ~]# lsmod | grep kvm kvm_intel 53484 6 kvm 316634 1 kvm_intel [root@hq ~]# lsmod | grep kvm
Also, when KVM is running, you should see the /dev/kvm in your filesystem as the following.
[root@node1 ~]# ls -al /dev/kvm crw-rw-rw-+ 1 root kvm 10, 232 Jun 14 16:10 /dev/kvm
When QEMU is running, you should not see the file as shown below.
[root@hq ~]# ls -al /dev/kvm ls: cannot access /dev/kvm: No such file or directory