A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Memory Hierarchy

College Depth 93 in the knowledge graph ☐ I know this ☆ Set as goal
74topics build on this
353prerequisites beneath it
See this on the map →
Memory Organization and AddressingRegisters and Register Files→→Cache Line Organization and Byte OffsetCache Memory Design+3 more
memory-hierarchy cache DRAM storage locality

Core Idea

The memory hierarchy organizes storage into levels with increasing capacity and decreasing speed moving away from the CPU: registers → L1/L2/L3 cache → main memory (DRAM) → secondary storage (SSD/HDD). The hierarchy exploits temporal locality (recently accessed data will likely be accessed again) and spatial locality (data near recently accessed data will likely be accessed soon). The goal is to provide the illusion of a large, fast, cheap memory by keeping frequently used data at the top of the hierarchy.

How It's Best Learned

Look up actual latency and capacity numbers for each hierarchy level in a modern processor. Trace what happens when a CPU reads a value: which levels are checked in order and how data is brought up through the hierarchy on a miss. Relate to time-space-complexity trade-offs in algorithms.

Common Misconceptions

Explainer

From your understanding of memory organization and registers, you know that the CPU needs data to execute instructions, and that registers provide the fastest possible storage — but only a handful of them exist. The fundamental problem the memory hierarchy solves is that we want memory that is simultaneously fast, large, and cheap, but no single technology delivers all three. Fast memory (like the SRAM used in registers) is expensive and physically large per bit. Cheap, dense memory (like DRAM) is orders of magnitude slower. The hierarchy is an engineering compromise that layers these technologies to approximate the ideal.

The levels of the hierarchy, from fastest to slowest, are: registers (sub-nanosecond access, tens of words), L1 cache (~1 nanosecond, tens of kilobytes), L2 cache (~5 nanoseconds, hundreds of kilobytes), L3 cache (~20 nanoseconds, megabytes), main memory/DRAM (~100 nanoseconds, gigabytes), and secondary storage (microseconds to milliseconds, terabytes). Each level is roughly 10–100x slower than the one above it, but also 10–1000x larger. The key insight is that programs do not access memory uniformly — they revisit the same data and nearby data repeatedly. This predictable behavior is what makes the hierarchy work.

The hierarchy exploits two patterns in how programs access data. Temporal locality means that data accessed recently is likely to be accessed again soon — think of a loop counter or a frequently called function. Spatial locality means that data near a recently accessed address is likely to be accessed next — think of iterating through an array element by element. When the CPU reads a value, the hardware automatically copies not just that value but an entire block of nearby data (a cache line) into the faster levels. If the program exhibits good locality, most accesses are served from cache, and the system performs as if all memory were as fast as SRAM.

When a requested value is found in a cache level, it is called a hit; when it is not found, it is a miss, and the hardware must fetch it from a slower level below. The performance of the entire system depends on the hit rate — the fraction of accesses served from each cache level. A well-designed hierarchy with programs that have good locality achieves hit rates above 95% at L1, meaning the CPU rarely waits for slow main memory. This is why the memory hierarchy is arguably the single most important architectural idea in modern computing: it makes the processor's raw speed usable by hiding the latency of the vast, cheap storage behind small, fast buffers that exploit the predictable patterns of real programs.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Boolean Algebra and Fundamental Laws → Logic Gates Fundamentals → Implementing Boolean Functions with Gates → Karnaugh Map Simplification → Combinational Circuit Design → Flip-Flops and Latches → Binary Counters: Design and Analysis → Binary Arithmetic → Fixed-Point Number Representation → Two's Complement Representation → Overflow and Underflow Detection → Binary Adders: Half-Adders and Full-Adders → Full Adder and Carry Propagation → Carry Lookahead Adder Design → Half Adder Circuit Design → Multiplication Circuit Design → Sequential Circuit Design → Registers and Register Files → Instruction Set Architecture (ISA) → Assembly Language Basics → Memory Organization and Addressing → Memory Hierarchy

Longest path: 94 steps · 353 total prerequisite topics

Prerequisites (2)

Leads To (5)