User-Space vs. Kernel: The Microsecond Latency Multiplier

User-space context switches can complete in nanoseconds, while kernel-level context switches, even for simple system calls, typically incur hundreds of nanoseconds to microseconds of overhead, representing a significant latency multiplier.

The top 3

  1. User-Space Context Switch: Nanoseconds vs. Kernel Microseconds: User-space context switches, like those in Go goroutines, can complete in hundreds of nanoseconds (e.g., ~200 ns), while kernel-level context switches typically incur overheads ranging from 1-5 microseconds, representing an order of magnitude difference.
  2. Top 3 Kernel Call Overheads: Privilege, TLB, Cache: The primary latency costs of kernel calls stem from switching CPU privilege levels (Ring 3 to Ring 0), flushing the Translation Lookaside Buffer (TLB), and saving/restoring the full CPU register set, which can also lead to cache pollution.
  3. High-Frequency Trading's Edge: User-Space Network Stacks: High-Frequency Trading (HFT) firms bypass the operating system kernel's network stack using technologies like DPDK and specialized NICs (e.g., Solarflare, Mellanox) to achieve sub-microsecond latency, avoiding 20-50 microseconds of kernel overhead.

Sources

Open the full topic