Tuning KVM

From KVM
Revision as of 12:23, 29 September 2009 by AviKivity (talk | contribs) (cpu, networking, storage tuning tips)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

CPU Performance

Modern processors come with a wide variety of performance enhancing features such as streaming instructions sets (sse) and other performance-enhancing instructions. These features vary from processor to processor.

QEMU and KVM default to a compatible subset of cpu features, so that if you change your host processor, or perform a live migration, the guest will see its cpu features unchanged. This is great for compatibility but comes at a performance cost.

To pass all available host processor features to the guest, use the command line switch

 qemu -cpu host

if you wish to retain compatibility, you can expose selected features to your guest. If all your hosts have these features, compatibility is retained:

 qemu -cpu qemu64,+ssse3,+sse4.1,+sse4.2,+x2apic

Networking

QEMU defaults to user-mode networking (slirp), which is available without prior setup and without administrative privileges on the host. It is also unfortunately very slow. To get high performance networking, switch to a bridged setup via the -net tap command line switches.

 qemu -net nic,model=virtio,mac=... -net tap,ifname=...

QEMU also defaults to the RTL8139 network interface card (NIC) model. Again this card is compatible with most guests, but does not offer the best performance. If your guest supports it, switch to the virtio model:

 qemu -net nic,model=virtio,mac=... -net tap,ifname=...

Storage

QEMU supports a wide variety for storage formats and back-ends. Easiest to use are the raw and qcow2 formats, but for the best performance it is best to use a raw partition. You can create either a logical volume or a partition and assign it to the guest:

 qemu -drive file=/dev/mapper/ImagesVolumeGroup-Guest1,cache=none,if=virtio

QEMU also supports a wide variety of caching modes. Writeback is useful for testing but does not offer storage guarantees. Writethrough (the default) is safer, and relies on the host cache. If you're using raw volumes or partitions, it is best to avoid the cache completely, which reduces data copies and bus traffic:

 qemu -drive file=/dev/mapper/ImagesVolumeGroup-Guest1,cache=none,if=virtio

As with networking, QEMU supports several storage interfaces. The default, IDE, is highly supported by guests but may be slow, especially with disk arrays. If your guest supports it, use the virtio interface:

 qemu -drive file=/dev/mapper/ImagesVolumeGroup-Guest1,cache=none,if=virtio