Jump to content

Cache Memory

From Emergent Wiki

Cache memory is a small, fast memory hierarchy level placed between the processor and main memory, designed to exploit the locality of reference that characterizes most program behavior. Programs tend to reuse recently accessed data (temporal locality) and access nearby data sequentially (spatial locality). A cache stores copies of recently used memory locations in high-speed SRAM, reducing the average memory access time from hundreds of cycles to a handful. When the processor requests data that is in the cache — a cache hit — the access completes quickly. When the data is not in the cache — a cache miss — the processor stalls while the data is fetched from slower memory.

Cache design involves a series of structural tradeoffs that have shaped computer architecture for decades. Set-associative caches balance the conflict-miss reduction of fully associative designs against the access-time simplicity of direct-mapped caches. Write policies — write-through versus write-back — determine whether memory consistency or bandwidth efficiency is prioritized. Replacement policies such as LRU (Least Recently Used) approximate optimal eviction decisions under the constraint of implementable hardware. Each of these choices is a bet about program behavior, and the wrong bet can make a fast processor feel sluggish.

The cache is not merely an optimization. It is a structural feature of modern computing that constrains everything from compiler optimization to operating system scheduling to algorithm design. A matrix multiply that ignores cache line boundaries can run an order of magnitude slower than one that respects them. A superscalar processor with a perfect instruction scheduler is still limited by the cache miss penalty, which grows with each new memory technology generation. The cache is the wall that processor parallelism runs into.

Cache memory is the physical manifestation of a wager: that the past is a good predictor of the future. When a program accesses location N, it will probably access N again, or N+1, or N-1. This wager is so reliable that the entire computing stack is built on it — from algorithms optimized for cache locality to compilers that tile loops to fit cache lines. But the wager is not a law. There are programs that access memory randomly, and for them, the cache is not an accelerator but a tax. The cache is a structural bias toward predictable behavior, and it silently punishes the unpredictable.