liveBook · Manning

Processor affinity

As explained in Latency

Processor affinity is a scheduling constraint that binds a thread or process to one or more specified processors or CPU cores.

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

How Latency covers it

How deep it goes
Explains affinity’s cache and NUMA rationale and names POSIX configuration, but stops short of API usage details or measurement procedures.
Examples
Uses POSIX pthread_setaffinity_np(), reserved CPUs, background daemons, kernel threads, and interrupts as implementation examples.
What it assumes
Assumes familiarity with threads, processes, CPU scheduling, caches, and task parallelism; introduces affinity through latency consequences.
What you can do after
Operate/configure application threads on selected CPUs and reason about the latency trade-offs of tighter scheduling placement.
How it connects
Connects processor affinity with task parallelism, cache locality, NUMA, scheduling delay, context switching, interrupts, and thread priority.

Also explained in

Compare how 2 books explain processor affinity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Latency. The section links point to the parts of the book it draws on.