Sunday, October 5, 2014

Para virtualizing KVM - An Ultimate Virtualization Experience from your Desktop/Laptop

Recently, We’d gone for some research, on how to improve virtualization performance with KVM. As a result, we made KVM as our default choice for Virtualization due to it’s better performance and stability.

My friends talked about the performance issues with KVM, while working with windows guests. Especially the graphics performance. Mouse movement is painfully slow and irregular. Also the network and disk performances are not any better.

Upon analysis, its concluded that by default KVM (Or any other Hypervisor for that reason), uses ‘Full Virtualization’, to run the guests. In such a scenario, Guest OS’s run as unmodified (Full Virtualization), where they are not aware about their underneath virtual environment. They simply assume, as they are running under a normal hardware platform. Such a ‘Fully Virtualized’ guest, demands more hardware resources and memory from the Hypervisor as they are not fine tuned for the virtualized environment, simply because unmodified guest OSs have been built with native hardware in mind.

KMV also supports ‘Para Virtualization’. ‘Para Virtualized’ guests are very well aware of their virtualized environment and adjust themselves accordingly. They put a less demand on resources from their hosted hypervisor. In other words, guest OS know it is running under a virtualized environment and cooperate with Host, to relinquish resources and memory to  more demanding guests.

The two scenarios have been detailed in the below figure.

image

‘Para Virtualization’ techniques, make use of ‘device drivers’ (Para Virtualized Drivers – PVDs) at two levels. One set will be installed inside ‘Guests’ and other will be used inside the Host OS/Hypervisor. These two sets of ‘device drivers’ cooperate each other, and work cohesively as a single unit, to provide the optimizations.

To make a Windows guest, Para virtualized, drivers are available for respective Hypervisor. Once installed your windows guest are become virtualization aware. For KVM these are called ‘VirtIO’ drivers.

When applied in our environments, the performance gain is unbelievable. It is running with a ‘Near Native’ performance, something similar to Xen or VMWare and outperforms other Type2 hypervisors like Virtual Box. We are presenting that as a case study in the below sections.

A Case Study:

Physical Host Specs:

CPU: Intel Pentium Dual Core CPU (2.6 GHZ, 2.6  GHZ)

               Intel-VT/AMD-V has been enabled in BIOS, to get the Hardware assisted virtualization support.

RAM: 4GB

HDD: (2 hard disks)

               SeaGate 250 GB (For Host OS installation, Swap space)

               Western Digital 1TB (To save guest disk images)

Host OS: Lubuntu 14.04

               Boot Time: 13 Seconds

               Startup Memory Usage: 175MB

               Shutdown Time: 4 Seconds

               Desktop: LXDE

One thing to note here that, your Host OS should be thinner as possible. We’ve chosen the best balance between ease of use and lightweightness, by selecting ‘Lubuntu14.04’ as the Host OS. Lubuntu is the lighter version of Ubuntu and one of the fastest Linux distribution.

Also it is better to have a secondary hard disk to keep your guest disk images, as Host OS does not have to compete with Guest OS’s while seeking data from hard disks. This gives the highest performance and long life to your drives, as it minimizes Read/Write head movements.

1. Install KVM and Management Tools

“sudo apt-get install qemu-kvm libvirt-bin python-spice-client-gtk virt-manager bridge-utils”

Add the current user to the ‘libvirtd’ group.

“sudo adduser `id -un` libvirtd”

2. Enable Nested Virtualization In KVM

echo 'options kvm_intel nested=1' >> /etc/modprobe.d/qemu-system-x86.conf

Download Para Virtualized Drivers for Windows:

Download SPICE Guest Tools here.

Purpose: Support Seamless integration with Host desktop, QXL GPU Para Virtualized drivers and guest tools.

Download Virtio Drivers (As ISO) here.

Purpose: Provides Para Virtualized Drivers for

Network Adapters (VirtIO Ethernet Adapter)

Block Storage         (VirtIO SCSI Driver)

PCI  Bus                    (VirtIO Serial)

RAM                          (VirtIO Memory Balloon Driver)

Create a Para Virtualized Windows Guest:

Open ‘Virt-Manager’ and start creating a windows guest.

Add ‘Nested Virtualization’ support.

image

Use ‘Virtio’ as Diskbus.

image

Use ‘Virtio’ as Network Adapter Device Model.

image

Use ‘Spice’ as Display Device and QXL as GPU.

image

Use PCI and Virtio Serial Bus.

image

To get the ‘VirtIO’ stuff work, you need to install Para Virtualized Drivers to the Windows Guest Machine. To accomplish that, first install the ‘SPICE Guest Tools’ EXE (You’ve downloaded earlier) inside the windows guest.

Once done, install other ‘VirtIO’ drivers, from the VirtIO ISO file (Downloaded earlier) for other devices (Network, Storage etc). Once completed you can open the ‘Device Manager’ to see the Para Virtualized Device Drivers (VirtIO) are in action. See the below figure.

image

When comes to performance, it truly runs with ‘Near Native’ speed. Opening applications like ‘Visual Studio' 2012’, Office 2007 are blazing fast. The folder/file browsing is so quick that, they will get opened as soon as you release your finger from the left mouse button. VirtualBox had took a noticeable amount of delay while performing the same operations. Also as number of guest increases, KVM simply outperform Virtualbox in terms of stability, speed and demand on hardware resources.

Especially you can run more number of guests with KVM, whose combined Virtual RAM requirement is more than the actual installed physical RAM, through a technique called ‘Memory Ballooning/Memory Overcommitting’. I’m planning to provide that idea in a separate article.

No comments:

Post a Comment