Study Atlas › Computer Science › Computer architecture

Memory hierarchy and caches

Small fast memories (registers, caches) sit in front of large slow ones (RAM, SSD) to exploit locality.

Edited by Alex C, EduAlx · Sources cited below

Explanation

Temporal locality: recently used data is reused. Spatial locality: nearby data is used next. L1 cache access is about 1 ns, RAM about 100 ns, SSD tens of microseconds. Cache misses are compulsory, capacity or conflict. Wilkes proposed caches ('slave memories', 1965).

Example

Iterating a 2D array row-by-row in C is much faster than column-by-column because of spatial locality.

How it works, step by step

  1. CPU requests an address
  2. Check L1, then L2, L3
  3. On miss, fetch a cache line from RAM
  4. Replace a line (LRU-like policy)

Open the interactive page with diagrams →

People behind it

References

  1. M. V. Wilkes, IEEE Trans. Electron. Comput. 1965, EC-14, 270–271.

Textbooks

Related topics

Pipelining and parallel processorsVon Neumann architectureBoolean logic and digital circuitsAutomata and formal languagesFile systems and storageString algorithms and pattern matchingVirtualisation and containersGreedy algorithms and minimum spanning treesCloud computingHeaps and priority queues