Hidden Costs: TLB Flushes & Cache Pollution

Beyond the direct costs of saving CPU registers and switching page tables, kernel context switches incur significant "indirect costs." These include Translation Lookaside Buffer (TLB) flushes, CPU cache pollution (L1-L3), CPU pipeline flushes, and branch predictor resets, which can collectively add substantial overhead and sometimes even exceed the direct costs.

The top 3

  1. Cache Pollution's Costliest Impact vs. TLB Flushes: Cache misses due to pollution often incur an order of magnitude higher cost than direct context switches or TLB flushes, especially with large data, as more data must move between RAM and CPU.
  2. Quantifying TLB Misses and Cache Pollution Latency: A single TLB miss can cost hundreds of CPU cycles, while the *indirect* cost of cache pollution during context switches can range from several microseconds to over a thousand microseconds, significantly impacting performance for larger datasets.
  3. Top CPU Optimizations Against TLB Flushes & Cache Pollution: Modern OS features like Address Space Identifiers (ASID) in Linux reduce TLB flush frequency by tagging entries, while architectural approaches like BEAM's user-space lightweight processes inherently bypass expensive kernel-level TLB flushes and mitigate cache pollution.

Sources

Open the full topic