Intermediate Topic 25 of 51 Computer Architecture & Logic
Memory Hierarchy
Tiers of storage trading speed for capacity.
How it works
The memory hierarchy arranges storage in layers from small, fast and expensive to large, slow and cheap: registers, L1, L2 and L3 caches, main memory (DRAM), SSDs and hard disks, and network or tape storage. It works because programs exhibit temporal and spatial locality, so most accesses hit the fast upper levels. Each level holds a subset of the one below it.
Step-by-step walkthrough
- Registers are fastest and smallest, about one cycle.
- L1 cache takes a few cycles.
- L2 and L3 hold more but are slower.
- Main memory takes hundreds of cycles.
- Disk is millions of times slower but huge and persistent.
- Locality of reference makes the hierarchy effective.
Where it is used
Processor and operating-system design, database buffer pools, file-system caches and performance tuning all use the hierarchy. Choosing data layouts that favor locality can yield large speedups.
Common pitfall
Ignoring locality, for example striding through a large 2D array by column instead of by row, can make code orders of magnitude slower. Access time differences are huge, roughly a nanosecond for cache and 100 nanoseconds for DRAM. Assuming memory is uniformly fast leads to poor performance. Measure with profilers and cache counters.
Where it fits in the course
Memory Hierarchy is topic 25 of 51 in Computer Architecture & Logic, rated Intermediate. It follows Addressing Modes. The next topic is Cache Memory.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Computer Architecture & Logic quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Computer Architecture & Logic quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Memory Hierarchy?
Where do people use Memory Hierarchy?
What is the most common mistake with Memory Hierarchy?
What should I learn before this topic?
How can I practice it?
Is Memory Hierarchy hard to learn?
How long does it take to learn Memory Hierarchy?
Which topics are related to Memory Hierarchy?
What should I study after Memory Hierarchy?
Related topics
- Addressing Modes (Computer Architecture & Logic)
- Cache Memory (Computer Architecture & Logic)
- Assembly Language (Computer Architecture & Logic)
- Cache Mapping (Computer Architecture & Logic)
- GPU Memory Hierarchy (Concurrency & Parallelism)
- Manual Memory Management (Languages & Compilers)
- Memory Barriers (Concurrency & Parallelism)