Pcornel
Browse topics
Options
Recent
Favorites
Virtualization · Technical reference

CPU Affinity

Direct answer

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.

When to use this

Use this when deciding whether to restrict a VM's vCPUs to certain cores, or when a VM behaves oddly after affinity was set.

First 30 seconds

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.

Operational verification

affinity mask → scheduler restricted → pCPUs

Context & applicabilityCommon mistakes · platform/version boundaries
Common mistakes
Common mistakes
  • Setting affinity to "fix" performance without measuring.
  • Affinity on VMs in DRS/HA clusters, blocking migration.
  • Forgetting the setting after hardware changes.
Platform / version applicability
virtualization-hardware
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformvirtualization-hardware
Key commandqm config 101 | grep affinity
Scope / prerequisiteUse this when deciding whether to restrict a VM's vCPUs to certain cores, or when a VM behaves oddly after affinity was…
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

1 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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 references

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.

observation · 1
Key points
  • Affinity limits the scheduler and can raise ready time.
  • Affinity can block DRS and live migration.
  • Licensing affinity is a legal, not technical, reason.
Key checks
  • virsh vcpupin <vm> — vCPU affinity
  • taskset -pc <pid> — process affinity
  • qm 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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
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
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docvirtualization-hardware current

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%
Confirmation

Confirm action

Continue?