Home

KVM Virtualization Reference

Kernel-based virtual machine for Linux systems

KVM Architecture

KVM transforms the Linux kernel into a type-1 hypervisor by leveraging hardware virtualization extensions. Understanding KVM's architecture is essential for optimal performance and effective troubleshooting.

Core Components

KVM Kernel Module

The KVM kernel module (kvm.ko, kvm-intel.ko, or kvm-amd.ko) provides the core virtualization infrastructure. It handles CPU and memory virtualization using Intel VT-x or AMD-V extensions.

Hardware Requirements

Memory Management

Memory Virtualization

KVM uses EPT (Intel) or NPT (AMD) for hardware-assisted memory virtualization. Guest virtual addresses are translated through two levels: guest virtual to guest physical, then guest physical to host physical.

Memory Overcommit Techniques

CPU Virtualization

vCPU Scheduling

Each vCPU runs as a kernel thread on the host. The Linux CFS scheduler handles vCPU scheduling, allowing integration with cgroups for resource control.

CPU Pinning

Pin vCPUs to specific physical CPUs for consistent performance:

virsh vcpupin myvm 0 0-3
virsh vcpupin myvm 1 4-7

I/O Virtualization

virtio Framework

virtio provides paravirtualized device drivers for optimal I/O performance. Guests using virtio drivers achieve near-native speeds compared to emulated devices.

virtio Devices

Device Passthrough (VFIO)

VFIO allows assigning PCI devices directly to VMs with IOMMU protection. Common use cases include GPU passthrough for machine learning or gaming.

Storage Architecture

Storage Backend Options

Networking Architecture

Network Modes

Performance Considerations

  • Use virtio drivers for all devices in production
  • Enable huge pages for memory-intensive workloads
  • Configure CPU topology matching to avoid NUMA penalties
  • Use multiqueue virtio-net for high-bandwidth networking
  • Consider PCI passthrough for GPUs and high-performance NICs