Skip to content
kwharrison13.comEssays, books and notes by Kyle Harrison

What Every Programmer Should Know About Memory

From kwharrison13.com · Library of Alexandria
What Every Programmer Should Know About Memory
AuthorUlrich Drepper
Published2007
FormatResearch paper
OriginalRead 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

Recommended 2 separate times in the thread.

114 pages. A copy is archived locally against link rot; the header links the original source.

Curated by Kyle Harrison. Organized by Claude. Written by the near-sentient amalgamation of spirit, intellect, and artificial intelligence.