liveBook · Manning

CPU cache

As explained in Latency

A CPU cache is a small, fast memory that stores copies of data likely to be accessed by a CPU.

A CPU cache is small, fast memory that stores data near the processor. Modern CPUs use multiple cache levels: nearer caches are smaller, faster, and more expensive than larger, slower levels. section 3.4

Caches matter because DRAM access can stall execution. An L1 cache may respond in approximately one nanosecond and hold up to 100 KiB, while the last-level cache (LLC) reaches megabytes or tens of megabytes with roughly an order-of-magnitude higher latency. section 3.4 section 11.4

Apply the hierarchy when optimizing latency:

  • Keep the application’s working set comfortably within the LLC when low latency is the priority. section 3.4
  • Treat cache misses as potential execution stalls; out-of-order and speculative execution can hide some memory-access latency but do not eliminate it. section 11.4
  • Place data and CPU work near the relevant NUMA node because local memory access is faster than remote access on NUMA systems. section 3.4

Latency-sensitive working set

A low-latency service benefits when its frequently accessed data fits within the LLC rather than repeatedly reaching DRAM. Hardware may continue along a predicted path during a memory stall, committing the work when prediction succeeds and discarding it when prediction fails. section 3.4 section 11.4

Figure 3.4 UMA and NUMA architectures. The left side of the figure represents a UMA architecture where all CPU cores have the same access latency to DRAM. The right side represents a NUMA architecture with two nodes. CPUs that are in the same node can access NUMA node local memory faster than memory in a remote node.
Figure 3.3: UMA and NUMA architectures. The left side of the diagram represents a UMA architecture where all CPU cores have the same access latency to DRAM. The right side, on the other hand, represents a NUMA architecture with two nodes. CPUs that are in the same node can access NUMA node local memory faster than memory in a remote node.

Compare UMA and NUMA layouts to understand how CPU proximity and memory placement affect access latency. section 3.4

How Latency covers it

How deep it goes
Explains cache levels, approximate capacities and latencies, working-set fit, and interactions with execution stalls.
Examples
Uses L1 latency and capacity, LLC size, DRAM slowdown, NUMA locality, and speculative branch execution as concrete cases.
What you can do after
Evaluate/understand why fitting frequently accessed data within the LLC can improve latency and reduce memory stalls.
How it connects
Connects CPU cache with DRAM, NUMA, memory latency, out-of-order execution, speculative execution, and data placement.

Also explained in

Compare how 3 books explain CPU cache →

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.