Learning Objectives
By the end of this chapter, you will be able to:
- Define the memory hierarchy as a speed cost capacity trade-off.
- Describe the five levels from registers to offline storage.
- Explain volatile versus non-volatile and RAM versus ROM.
- State why locality makes a small fast layer effective.
- Choose a memory mix for a business task.
The Memory Hierarchy
Computers use many kinds of memory. The memory hierarchy organizes them by two truths: faster costs more per byte, so fast memory stays small. The hierarchy is a pyramid. The top is tiny and fast. The bottom is huge and slow.
flowchart TB
R[Registers: bytes, inside CPU] --> C[Cache L1 L2 L3: KB to MB]
C --> M[Main memory RAM: GB]
M --> S[Secondary storage: SSD HDD: TB]
S --> T[Tertiary and offline: tape cloud archives]
Do not memorize levels as a list. Group them by what they do for the CPU.
A. Hot: what the CPU touches this nanosecond
Registers sit inside the CPU. A few dozen bytes. Hold the instruction, addresses, and operands for this cycle. Volatile. Fastest and most expensive per byte.
Cache sits on or next to the CPU. L1 is smallest and fastest inside each core, L2 larger per core, L3 shared across cores. All SRAM. Holds recently used blocks from RAM so the CPU avoids a slow RAM trip. Also volatile.
B. Warm: what the CPU will touch this second
Primary memory or RAM is on the motherboard. 8 to 64 GB typical. Holds the OS, apps, and working data. DDR4 or DDR5 DRAM. Volatile. The working desk for the CPU. See types of memory for DRAM versus SRAM detail.
ROM and firmware live beside RAM as a separate purpose. Small, non-volatile. Holds BIOS and UEFI startup instructions. Types include PROM, EPROM, EEPROM and Flash. They start the machine, they do not hold your bills.
C. Cold: what the organization keeps for months and years
Secondary storage is HDD, SSD, USB drives. Non-volatile. Much larger and cheaper per GB, much slower. A 1 TB SSD costs far less per GB than 32 GB of RAM, and both cost far less per GB than cache.
Tertiary and offline is tape, external archives, and cloud cold storage. Cheapest per TB, sequential and slow. Built for retention and disaster recovery, not for active work.
| Level | Typical size | Speed vs CPU | Cost per GB | Volatile? |
|---|---|---|---|---|
| Registers | Bytes | Nearest | Highest | Yes |
| Cache L1 L2 L3 | KB to tens of MB | Very close | Very high | Yes |
| RAM | 8 to 64 GB | Close | Moderate | Yes |
| SSD | 256 GB to 4 TB | Distant | Low | No |
| HDD | 1 to 20 TB | Distant and mechanical | Lowest | No |
| Tape and archive | TB to PB | Far | Lowest | No |
Analogy: the fact you are thinking of now is in registers. Notes open on the desk are cache. Books on the shelf are RAM. The library across town is secondary storage. Archives in another city are tape. You keep what you need next closest.
Primary memory close up: RAM and ROM
| Aspect | RAM | ROM |
|---|---|---|
| Keeps without power | No | Yes |
| Read and write | Both | Mainly read |
| Purpose | Running programs and current data | Firmware such as BIOS and UEFI |
| Size | GB | MB |
| Technology | DRAM for RAM, SRAM for cache | PROM, EPROM, EEPROM, Flash |
DRAM uses one transistor and one capacitor per bit, needs refresh thousands of times per second, is cheap and dense, and is your main memory. SRAM uses six transistors per bit, needs no refresh, is fast and costly, and is your cache. Flash is EEPROM erased in blocks, and it powers BIOS chips and SSDs.
Why the hierarchy works: locality
Programs reuse the same instructions and data and access neighbors. Temporal locality says recently used data will be used again soon. Spatial locality says neighbors will be touched next, such as the next items in a bill list. Because of locality, a small cache holding the hot blocks gives most of the speed of all fast memory at a small fraction of the cost. Without locality, the pyramid would fail.
Self-check
Nepal worked example: a cooperative server that respects the pyramid (NPR, BS 2081)
A savings cooperative in Bharatpur plans a server on 2081-09-10 to handle day end posting and member queries.
Options quoted:
- 32 GB DDR4 RAM upgrade from 16 GB: NPR 9,600
- 1 TB NVMe SSD to replace 1 TB HDD: NPR 11,500
- 4 TB HDD for audit archives from BS 2076 to 2081: NPR 12,000
The team reasons in groups. Hot is already sized: the CPU has 12 MB L3 cache, enough for tight posting loops. Warm is short: with only 16 GB, posting for 8,000 members pages to disk and misses the nightly window. Adding RAM to 32 GB keeps the working set warm. Cold is split: NVMe for active ledgers and member DB for speed, 4 TB HDD for append only archives for audit retention.
Result: spend NPR 9,600 plus 11,500 for active performance, plus NPR 12,000 for cheap cold retention. Total NPR 33,100. The alternative of adding only more Hot cache is impossible; registers and L3 cannot be bought by the GB. The pyramid tells you where money converts to speed and where cheap retention belongs.
Example 1: In a cooperative, Warm and Cold must separate for audit. Ask: can we replay every posting from 2081-09-10 from Warm NVMe plus Cold HDD archive without a gap? If Warm alone holds the only copy, a power loss on a volatile layer breaks the audit trail.
Example 2: In a retail chain, Hot and Warm decide queue time, Cold decides recovery. Ask: does the NVMe plus 32 GB keep five tills responsive at peak, and does the nightly Cold copy let a failed till rebuild by morning without losing bills?
Summary
- The hierarchy trades speed and cost: smaller, closer, faster costs more per byte.
- Hot is registers and cache. Warm is RAM and firmware. Cold is SSD, HDD, and archive.
- DRAM is dense and cheap for Warm. SRAM is fast and costly for Hot. Flash as EEPROM serves firmware and SSDs.
- Locality lets a small Hot layer deliver most of the speed of an all fast machine.
Key Takeaways
- Volatile loses data without power: registers, cache, RAM. Non-volatile keeps it: ROM, SSD, HDD, tape.
- Cache bridges the gap between a GHz CPU and slower RAM.
- Do not store audit records only in a volatile layer.
- Tape and cloud archive are not slow failures. They are cheap retention by design.
Discussion Questions
- Why cannot we build a machine with only registers, even if budget allowed?
- What locality explains why scanning 100 bills in order benefits from cache?
- Which level would you enlarge first when nightly posting slips the window?
Exercises
Short answer
- Define the memory hierarchy and state the speed cost capacity trade-off in one line each.
- Differentiate RAM and ROM on volatility, read and write, and purpose.
- State temporal and spatial locality with one business example each.
Long answer
- Explain the memory hierarchy with a diagram, describing Hot, Warm, and Cold with Nepal examples.
- A cooperative must choose between adding RAM versus adding an SSD on 2081-09-10 with NPR 33,100. Advise using the Hot Warm Cold framework and locality.


