What Every Programmer Should Know About Memory
| Author | Ulrich Drepper |
|---|---|
| Published | 2007 |
| Format | Research paper |
| Original | Read the original |
TL;DR — Ulrich Drepper’s 2007 paper on how RAM, CPU caches, TLBs and NUMA systems work, and how programmers should write code that uses them well.
Drepper, then at Red Hat, dated version 1.0 on 21 November 2007. His abstract argues that memory access, not CPU speed, has become the limit for most programs, and that caches cannot work well without help from the programmer. The title is a nod to David Goldberg’s paper on floating-point arithmetic, and he thanks the staff of LWN for editing the text.
The 114 pages build from hardware up. Section 2 explains commodity hardware and RAM types, static and dynamic, down to DRAM access protocols. Section 3, the longest groundwork, covers CPU caches: associativity, measured cache effects, multiprocessor coherence and instruction caches. Section 4 covers virtual memory, page tables and TLBs, including the cost of virtualization, and Section 5 covers NUMA systems.
Section 6 is the practical core: laying out data to use whole cache lines (with a worked matrix-multiplication example), optimizing instruction and TLB use, hardware and software prefetching, the costs of threads sharing cache lines and of atomic operations, and NUMA programming on Linux. Section 7 covers tools such as oprofile and cache simulators, and Section 8 looks ahead to transactional memory and vector operations. Operating-system detail is Linux-only by design.
What it is: A long, self-published technical reference that has been widely read since its release. Specific hardware details, such as front-side buses, are dated; the principles of caches and locality still apply.
Where this came from
- Will Manidis’s “most underrated PDF” thread, July 2023 — routing record: The Most Underrated PDF on the Internet (July 2023)
Recommended 2 separate times in the thread.
114 pages. A copy is archived locally against link rot; the header links the original source.