Processor affinity is a scheduling constraint that binds a thread or process to selected processors or CPU cores. By preventing migration, it can reduce scheduling movement, cache invalidation, and memory-access latency while preserving locality in the working set. section 9.3.2 section 7.5.1
Affinity matters most in latency-sensitive task-parallel workloads. Keeping a thread on its assigned core can preserve cache state; on NUMA systems, deliberate placement can also keep computation near its memory. section 9.3.2
Reserving CPUs for a low-latency service
A service can use a thread-affinity interface such as POSIX pthread_setaffinity_np() to restrict application threads to selected CPUs. Reserving other CPUs for background processes helps prevent daemons and kernel activity from competing with those threads, although interrupts and deferred kernel work can still introduce latency. section 7.5.1 section 7.5.2
Use processor affinity as a measured latency technique, not as a universal optimization:
- Bind related task-parallel work to suitable cores when migration costs and cache disruption matter. section 9.3.2
- Avoid assuming affinity removes scheduling overhead: excessive threads, context switches, background tasks, and interrupts can still delay execution. section 7.5.1 section 7.5.2
- Combine affinity with sensible thread counts and, where appropriate, thread priorities; tighter placement can trade flexibility for lower interference. section 7.5.1

