Dev iconDevSep 30, 2026 ~1 min source read

What Actually Happens During a Linux Context Switch: Registers, TLB Flushes, and the True Cost of Multithreading

We are told to keep thread pools bounded, avoid context-switch storms, and prefer event loops or green threads for high concurrency. Yet if you ask a developer what a context switch actually costs, the answer is usually vague: "It takes a microsecond or two to save some registers." That answer hides a massive performance trap.

What Actually Happens During a Linux Context Switch: Registers, TLB Flushes, and the True Cost of Multithreading

Share this story

Send the public story page.

Useful takeaways from this story.

We are told to keep thread pools bounded, avoid context-switch storms, and prefer event loops or green threads for high concurrency.

Yet if you ask a developer what a context switch actually costs, the answer is usually vague: "It takes a microsecond or two to save some registers." That answer hides a massive performance trap.

The real destruction happens in the CPU caches, the Translation Lookaside Buffer (TLB), and the branch predictor.

Building the complete brief

The page is ready to read now. The fuller skim-friendly version will appear here automatically.

The useful part

We are told to keep thread pools bounded, avoid context-switch storms, and prefer event loops or green threads for high concurrency. Yet if you ask a developer what a context switch actually costs, the answer is usually vague: "It takes a microsecond or two to save some registers." That answer hides a massive performance trap. The real destruction happens in the CPU caches, the Translation Lookaside Buffer (TLB), and the branch predictor.

How it works

  • Here is the exact hardware and kernel mechanism that executes every time Linux stops one thread and runs another.
  • It contains one Program Counter (rip), one stack pointer (rsp), and one set of architectural registers.
  • When your operating system runs 500 threads across 8 physical cores, those threads are not executing simultaneously.
  • The Linux kernel rapidly multiplexes CPU execution time slices across runnable tasks.

Details worth keeping

Every backend engineer learns early on that threads are not free. Saving registers takes less than 50 nanoseconds. Cores A CPU core is a single instruction pipeline.

Keep reading in the app

Open the app view to save this story, compare related coverage, and continue from the same source.

Open in app