Stop your KVM guests from drifting off their CPU pins
By Saket Jain Published Linux/Unix
Stop your KVM guests from drifting off their CPU pins
Technical Briefing | 7/24/2026
I spent a week chasing ghost performance issues on a cluster of KVM nodes. The monitoring tools said the CPU load was fine, but application latency kept spiking in a pattern that looked suspiciously like a cache miss or a context switch nightmare. Turns out, the Linux scheduler was moving my vCPUs between physical cores every few milliseconds because I had not explicitly told it not to. KVM is great, but it assumes you know how to map your hardware topology better than it does.
Why the scheduler is your worst enemy here
The kernel scheduler is built to be a good citizen, shuffling threads around to keep physical cores busy. But when you are running a high-load guest, that shuffling destroys your L1 and L2 cache hits. If your vCPU jumps from core 0 to core 12, your data is gone from the cache. On a busy host, this becomes a performance tax you cannot afford.
virsh vcpupin <domain> 0 0-3
- Check your host topology first using lscpu to identify actual physical core pairs
- Avoid pinning vCPUs to hyper-threads if you need consistent latency for critical workloads
- Use virsh emulatorpin to keep the management thread from competing with your actual guest processes
Once you pin the vCPUs in the XML config, stop using virsh for real-time adjustments if you want things to survive a reboot. Edit the domain XML properly and attach it. And check your host kernel boot parameters; if you do not add isolcpus to the GRUB command line, the host kernel might still try to steal those cores for background tasks, rendering your pinning useless.
