processor affinity
When you work at one desk, your papers, pens, and notes are all laid out within reach; move to a fresh desk and you must fetch everything again before you can be productive. A CPU core is like that desk, and its cache is the laid-out workspace. Processor affinity is the scheduler's preference to keep a process running on the same core it ran on before, so it can reuse the data already sitting warm in that core's cache.
Why the preference exists: each core has its own fast cache holding recently used data and instructions. While a process runs, it warms that cache with its working set. If the scheduler then moves the process to a different core, the new core's cache is cold for that process — it must reload everything from slower memory, and the old core's cache holding that data is wasted (or must be invalidated). So migrating a process has a real hidden cost, and affinity is the policy of avoiding that cost when reasonable. Affinity comes in two strengths: soft affinity is a best-effort preference the OS can override to balance load, while hard affinity lets a program pin itself to specific cores and refuse to move.
Why it matters and the tension: affinity directly improves performance by raising cache hit rates, especially for memory-heavy workloads, and it interacts with hardware layout (NUMA systems, where a core accesses its local memory faster, make affinity matter even more). But affinity pulls against load balancing: keeping every process glued to its home core can leave one core overloaded while another idles. Real schedulers treat affinity as a strong hint, not an absolute rule, migrating only when the imbalance is bad enough to be worth the cache cost.
A database thread runs on core 2 and fills its cache with index pages. If the scheduler keeps it there (affinity), its next burst hits warm cache and runs fast. If load balancing instead moves it to idle core 5, it starts with a cold cache and the first thousand accesses go to slow memory before it warms up again.
Affinity keeps a process near its warm cache; migrating it pays a cold-cache penalty.
Affinity is a performance heuristic, not a correctness requirement — a process runs correctly on any core. Pinning with hard affinity can backfire by preventing load balancing, so use it only when you have measured a real cache benefit.