LinuxInsight - kvmhttp://www.linuxinsight.com/taxonomy/term/52/0
enFinally user-friendly virtualization for Linuxhttp://www.linuxinsight.com/finally-user-friendly-virtualization-for-linux.html
<p>The upcoming 2.6.20 Linux kernel is bringing a nice virtualization framework for all virtualization fans out there. It's called KVM, short for Kernel-based Virtual Machine. Not only is it user-friendly, but also of high performance and very stable, even though it's not yet officialy released. This article tries to explain how it all works, in theory and practice, together with some simple benchmarks.</p>
<p><strong>A little bit of theory</strong></p>
<p>There are several approaches to virtualization, today. One of them is a so called paravirtualization, where the guest OS must be slightly modified in order to run virtualized. The other method is called "full virtualization", where the guest OS can run as it is, unmodified. It has been said that full virtualization trades performance for compatibility, because it's harder to accomplish good performance without guest OS assisting in the process of virtualization. On the other hand, recent processor developments tend to narrow that gap. Both Intel (<a href="http://www.intel.com/technology/virtualization/">VT</a>) and AMD (<a href="http://www.amd.com/us-en/Processors/ProductInformation/0,,30_118_8796_14287,00.html">AMD-V</a>) latest processors have hardware support for virtualization, tending to make paravirtualization not necessary. This is exactly what KVM is all about, by adding virtualization capabilities to a standard Linux kernel, we can enjoy all the fine-tuning work that has gone (and is going) into the kernel, and bring that benefit into a virtualized environment.</p>
<p>Under KVM's model, every virtual machine is a regular Linux process scheduled by the standard Linux scheduler. A normal Linux process has two modes of execution: kernel and user. KVM adds a third mode: guest mode (which has its own kernel and user modes).</p>
<p><span class="inline inline-none"><img src="http://www.linuxinsight.com/files/images/kvm_architecture.png" alt="" title="" class="image image-_original " width="440" height="226" /></span></p>
<p>KVM consists of two components:</p>
<ul>
<li>a device driver for managing the virtualization hardware; this driver exposes its capabilities via a character device <code>/dev/kvm</code>
</li><li>a user-space component for emulating PC hardware; this is a lightly modified QEMU process
</li></ul>
<p><a href="http://fabrice.bellard.free.fr/qemu/">QEMU</a> is a well known processor emulator written by French computer wizard <a href="http://fabrice.bellard.free.fr/">Fabrice Bellard</a>.</p>
<p><strong>KVM in practice: Windows XP as a guest OS</strong></p>
<p>Although KVM is still in development, I decided to play a little bit with it. I used 2.6.20-rc2 kernel, together with already available Debian packages: <a href="http://packages.debian.org/unstable/misc/kvm">kvm</a> and <a href="http://packages.debian.org/unstable/misc/qemu">qemu</a>. So, after I have recompiled the kernel and installed packages, everything was ready. I suppose that this, together with the fact than no proprietary software or binary kernel modules is needed, explains why I call it user-friendly.</p>
<p>But, there's more, see how easy it's to install (proprietary!) guest OS:<br />
<code><br />
qemu-img create hda.img -f qcow 6G<br />
kvm -no-acpi -m 256 -cdrom winxpsp2.iso -hda hda.img -boot d<br />
</code><br />
First step was to create a virtual disk drive (a simple file on the host OS). I have chosen QEMU's copy-on-write format. This means the file will grow as needed, not taking much disk space, unless it's really needed (up to maximum 6GB). With the virtual drive ready, the installation could begin. Actually, I did one more (non-mandatory) step before those two, I dumped the installation CD on the disk so that the installation goes faster because disk can seek much faster than CD/DVD device (a simple <code>cp /dev/cdrom image.iso</code> should do the job). I used the <code>-no-acpi</code> switch, because ACPI support in QEMU is still experimental and there were some problems with the Windows installer.</p>
<p>And that's it, I suppose it doesn't get simpler than that, in short time I had Windows installed and running. Why Windows, some of you may ask? Well, I couldn't find a reason to have another Linux virtualized under this one, at the moment. Also, I always wanted to have a handy virtualized Windows environment for some experimental purposes. Not dual-booting it, which is PITA for everyday use, but something that could be easily started from time to time. For example to see how this web page looks in IE7, and stuff like that...</p>
<p><strong>Some benchmarking</strong></p>
<p>OK, so with Windows XP installed in no time, I had plenty of time left to do some simple benchmarks. Nothing comprehensive or scientific, I remind you, just a few quick tests so that you have rough idea how KVM works in practice. I've also included few other interesting cases, because it was easy to do. Once I had installed Windows OS, it could be run even under unmodified QEMU, no problem. And with a little additional effort I also compiled kqemu, QEMU accelerator module written by QEMU's original author, unfortunately a closed-source product. Finally, the choice of the applications that I ran has fallen to only two of them, <a href="http://www.futuremark.com/download/pcmark2002/">PCMark2002</a> and <a href="http://en.wikipedia.org/wiki/Super_PI">Super PI</a> (ver 1.1e) with the sole reason that I had numbers from those two applications from the times when I had Windows XP installed natively (but that was few months ago, and I have since deleted it). Before I forget, the tests were run on an Intel E6600 processor.</p>
<p><span class="inline inline-none"><img src="http://www.linuxinsight.com/files/images/pcmark2002_cpu.png" alt="" title="" class="image image-_original " width="260" height="250" /></span> <span class="inline inline-none"><img src="http://www.linuxinsight.com/files/images/pcmark2002_memory.png" alt="" title="" class="image image-_original " width="260" height="250" /></span></p>
<p>I think it's pretty obvious how much improvement both kqemu and KVM bring over QEMU emulator alone. Also, it seems that kqemu still commands a slight lead over KVM, but I'm sure that KVM performance will only improve over time, it's really young compared to all other virtualization products.</p>
<p><span class="inline inline-none"><img src="http://www.linuxinsight.com/files/images/super_pi.png" alt="" title="" class="image image-_original " width="260" height="250" /></span></p>
<p>Running Super PI is another story, KVM is the fastest one here, running at 84% of the native speed, which is a great result. Stock QEMU is so slow at this task, that graph above is hard to decipher, so I'll list all the results here (time to generate first million digits of pi, less is better): QEMU: 492.5 sec, kqemu: 28.5 sec, KVM: 25.5 sec, native: 21.5 sec.</p>
<p><strong>Conclusion</strong></p>
<p>While still in the early development stages, KVM shows a real potential. It's fun working with it, and I suppose we'll hear more and more good news about it in the following months. At the time when this technology gets incorporated in the mainstream Linux distributions (in not so distant future) virtualization will become a real commodity. And not only for data centers and server consolidation purposes, but also on Linux desktops everywhere. Mostly thanks to a really great work on behalf of QEMU &amp; KVM developers. But, you can start playing with it today...</p>
<p>Resources:<br />
<a href="http://kvm.sourceforge.net/">KVM: Kernel-based Virtual Machine for Linux</a><br />
<a href="http://fabrice.bellard.free.fr/qemu/">QEMU: open source processor emulator</a><br />
<a href="http://fabrice.bellard.free.fr/qemu/qemu-accel.html">QEMU Accelerator Module</a><br />
<a href="http://article.gmane.org/gmane.linux.kernel/458485">KVM: the original announcement on the linux-kernel list</a></p>
<div class="image-clear"></div><table id="attachments" class="sticky-enabled">
<thead><tr><th>Attachment</th><th>Size</th> </tr></thead>
<tbody>
<tr class="odd"><td><a href="http://www.linuxinsight.com/files/kvm_whitepaper.pdf">kvm_whitepaper.pdf</a></td><td>118.89 KB</td> </tr>
<tr class="even"><td><a href="http://www.linuxinsight.com/files/xp_under_qemu.png">xp_under_qemu.png</a></td><td>114.08 KB</td> </tr>
</tbody>
</table>
http://www.linuxinsight.com/finally-user-friendly-virtualization-for-linux.html#commentsbenchmarkskvmsystemvirtualizationWed, 27 Dec 2006 11:02:56 +0000admin797 at http://www.linuxinsight.com