KVM Performance Tuning: virtio, CPU Pinning, Hugepages and I/O Threads
Get near bare-metal performance from KVM guests with virtio devices, host-passthrough CPUs, vCPU pinning, NUMA alignment, hugepages and I/O threads.
Published November 27, 2026
Out of the box, a KVM guest already runs CPU-bound code at near-native speed. Where VMs lose performance is I/O, memory access across NUMA nodes, and noisy neighbours fighting over the same cores. This guide covers the tuning knobs in order of impact, so you fix the biggest bottleneck first.
The concept
Start with paravirtualised devices. Emulated hardware such as an IDE disk or e1000 NIC requires many VM exits per operation, because QEMU must emulate every register access. virtio devices are designed for virtualization: guest and host share ring buffers in memory, and a single notification can move many requests. Switching to virtio-blk/virtio-scsi and virtio-net is usually the largest single win.
Next comes the CPU model. The default generic CPU model hides features such as AVX2 or AES-NI so VMs can migrate between different hosts. If migration across mixed hardware is not a requirement, host-passthrough exposes every feature of the real CPU. For latency-sensitive workloads, pin each vCPU to a dedicated physical core and keep the host's own processes off those cores.
Memory tuning matters on big guests. Hugepages (2 MiB or 1 GiB) cut TLB misses for memory-heavy applications such as databases, and NUMA alignment ensures a VM's vCPUs and memory sit on the same socket, avoiding slower cross-socket memory access.
Why virtio matters
The virtio data path
CPU pinning and NUMA
Use lscpu -e or numactl -H to see which cores belong to which NUMA node and which logical CPUs are hyperthread siblings. Pin a VM's vCPUs to cores on one node, pin the emulator thread elsewhere, and bind memory to the same node.
<vcpu placement="static">4</vcpu>
<cputune>
<vcpupin vcpu="0" cpuset="2"/>
<vcpupin vcpu="1" cpuset="3"/>
<vcpupin vcpu="2" cpuset="4"/>
<vcpupin vcpu="3" cpuset="5"/>
<emulatorpin cpuset="0-1"/>
</cputune>
<numatune><memory mode="strict" nodeset="0"/></numatune>
<cpu mode="host-passthrough"><topology sockets="1" cores="4" threads="1"/></cpu>Tuning knobs ranked
| Knob | Typical gain | Cost / trade-off |
|---|---|---|
| virtio disk + NIC | Large | Needs drivers (built into Linux; virtio-win for Windows) |
| host-passthrough CPU | Medium (SIMD, crypto) | Live migration only between identical CPUs |
| vCPU pinning | Lower latency and jitter | Less flexible consolidation |
| Hugepages | Medium for memory-heavy apps | Memory reserved up front |
| I/O threads | Higher disk throughput | Extra host threads to pin |
| vhost-net / multiqueue | Higher network throughput | More host CPU usage |
Practical examples
Enable 2 MiB hugepages for a VM
Reserve pages on the host, then tell libvirt to back guest memory with them.
echo 'vm.nr_hugepages = 4096' | sudo tee /etc/sysctl.d/80-hugepages.conf # 8 GiB
sudo sysctl --system
virsh edit db01 # add inside <domain>:
# <memoryBacking><hugepages/></memoryBacking>Dedicated I/O thread for a disk
Moves disk emulation off the main QEMU loop.
<iothreads>1</iothreads>
<disk type="file" device="disk">
<driver name="qemu" type="qcow2" cache="none" io="native" iothread="1" discard="unmap"/>
<source file="/var/lib/libvirt/images/db01.qcow2"/>
<target dev="vda" bus="virtio"/>
</disk>Multiqueue virtio-net
One queue per vCPU lets network processing scale across cores.
<interface type="network">
<source network="default"/>
<model type="virtio"/>
<driver name="vhost" queues="4"/>
</interface>
<!-- inside the guest: ethtool -L eth0 combined 4 -->Common mistakes
- Tuning before measuring. Use fio, iperf3 and perf kvm stat to find the real bottleneck first.
- Giving a VM more vCPUs than physical cores on a NUMA node, forcing cross-node memory access.
- Pinning vCPUs to both siblings of hyperthreads used by other busy VMs.
- Reserving hugepages and then forgetting them, leaving gigabytes unusable by the host.
- Using cache=writeback on a host without a battery-backed or power-loss-protected disk for critical data.
Key takeaways
- virtio for disk and network is the biggest single improvement.
- host-passthrough exposes the full CPU feature set when migration flexibility is not needed.
- Pinning and NUMA alignment reduce latency and jitter for demanding guests.
- Hugepages and I/O threads help memory- and disk-heavy workloads.
FAQ
How close to bare metal can KVM get?
CPU-bound work is typically within a few percent. With virtio, pinning and hugepages, I/O-heavy workloads can also come close; PCI passthrough (VFIO) removes almost all overhead for a specific device.
What is VFIO passthrough?
Assigning a physical PCIe device (GPU, NIC, NVMe) directly to a guest using the IOMMU. The guest drives the hardware itself, with near-native performance.
Should I disable KSM?
KSM (kernel same-page merging) saves memory when many similar VMs run, at a CPU cost. Disable it for latency-sensitive hosts or if you do not overcommit memory.