Use this when deciding whether to restrict a VM's vCPUs to certain cores, or when a VM behaves oddly after affinity was set.
CPU Affinity
CPU affinity restricts which physical cores a VM's vCPUs may run on. It can isolate workloads or satisfy licensing, but it limits the scheduler, can block live migration and often hurts more than it helps.
1. Affinity restricts which pCPUs a VM may use.
2. Useful for licensing or NUMA.
3. Reduces scheduler flexibility.
4. Document it.
5. Breaks easily on hosts with different topology.
affinity mask → scheduler restricted → pCPUs
Context & applicabilityCommon mistakes · platform/version boundaries
- Setting affinity to "fix" performance without measuring.
- Affinity on VMs in DRS/HA clusters, blocking migration.
- Forgetting the setting after hardware changes.
Operational reference
Fast context before you go deeper.
qm config 101 | grep affinityVerification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Checks Verify boundary
virsh vcpupin vm01
qm config 101 | grep affinity
Remove affinity unless there is a measured reason (licensing, NUMA testing).
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Affinity limits the scheduler and can raise ready time.
- Affinity can block DRS and live migration.
- Licensing affinity is a legal, not technical, reason.
virsh vcpupin <vm>— vCPU affinitytaskset -pc <pid>— process affinityqm config <vmid> | grep affinity— Proxmox affinity
ReferenceWhy it matters1 section · depth on demand
Trade-offs
Affinity can isolate a workload or meet per-core licensing rules, but:
- it prevents the scheduler from moving vCPUs to idle cores,
- it can block vMotion/live migration and DRS,
- it must be maintained when host hardware changes.
Prefer shares and reservations; use affinity only with a clear reason.
ReferenceImportant terms & boundaries1 section · depth on demand
In depth
CPU affinity restricts which physical CPUs a VM (or its vCPUs) may run on, without exclusive ownership. It can isolate noisy VMs or satisfy licensing, but it also prevents the scheduler from balancing load and often blocks live migration (VMware disables vMotion/DRS for VMs with affinity).
virsh vcpupin vm1 --live # show
taskset -cp <qemu-pid> # current host affinity
qm set 120 --affinity 0-7 # Proxmox 7.3+
Prefer resource controls (shares, reservations) over affinity unless the requirement is hard.
ReferenceConfiguration & state1 section · depth on demand
Commands
# KVM/libvirt
virsh vcpupin vm01 0 4
virsh vcpupin vm01
# Proxmox (8.x)
qm set 101 --affinity 4-7
Documented example, not captured output. Affinity prevents the scheduler from balancing load and blocks live migration on some platforms.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in CPU Virtualization → CPU Affinity. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://libvirt.org/docs.html · confidence 94%