CSSE 132 Mini-reading
Memory Hierarchy in 10 Minutes
Review the speed, cost, and persistence tradeoffs among SRAM, DRAM, solid-state drives, and hard disks—and see why caching helps.
Why This Matters
A computer needs tiny, extremely fast memory close to the CPU as well as large, inexpensive storage for files. CSSE 132 uses this topic to explain why a program can access a register quickly but loading data from storage is much slower. Worksheet 09 also asks you to compare these technologies and calculate the benefit of a cache.
Core Idea
The memory hierarchy is a tradeoff: technologies that are faster are usually more expensive per byte and therefore used in smaller amounts. A computer combines them rather than choosing only one kind of memory.
| Technology | Typical role | Key tradeoff |
|---|---|---|
| SRAM | Registers and caches | Very fast, but expensive |
| DRAM | Main memory | More dense and less expensive than SRAM, but slower |
| SSD | Persistent storage | Fast storage with no moving parts, but higher cost and limited write life |
| Hard disk | Persistent storage | Low cost and high capacity, but mechanical delays make it slower |
Volatile memory loses its contents when power is removed. SRAM and DRAM are volatile, so neither replaces an SSD or hard disk for keeping files after shutdown. SSDs and hard disks are nonvolatile storage.
Worked Examples
Example 1: SRAM versus DRAM
Static RAM (SRAM) uses latches and flip-flops to hold each bit. It is always active, which makes it very fast but costly: the slides describe it as using six transistors per bit. That cost limits SRAM to places where speed matters most, such as the register file and caches.
Dynamic RAM (DRAM) stores a bit using a capacitor. A capacitor leaks charge, so DRAM must be periodically refreshed. That is what dynamic means here. DRAM uses fewer components per bit, allowing much more main memory at a lower cost, though with slower access.
Example 2: SSD versus hard disk
An SSD uses flash memory and has no moving parts, so it is faster and more reliable than a hard disk. Flash storage has an important constraint: data is read and written in pages, but a page can be written again only after its entire block has been erased. Repeated writes also wear out flash blocks over time.
A hard disk stores data on rotating platters. To read a sector, the drive may need to move its head to the correct track (seek time), wait for the sector to rotate underneath it (rotational latency), and then transfer the bits:
Taccess = Tavg seek +
Tavg rotation + Tavg transfer
Seek time and rotational latency are why a hard disk is much slower than memory, even when the requested sector contains only a small amount of data.
Example 3: Why a cache helps
A cache uses fast memory to mirror a useful piece of slower memory. First check the cache. A hit finds the requested data there; a miss requires both the cache check and the slower access.
Suppose cache access takes 500 ns = 0.5 µs, a disk access
takes 10 ms = 10,000 µs, and the hit rate is
99.129% = 0.99129. The miss rate is
1 - 0.99129 = 0.00871.
Tavg
= hit rate × Tcache + miss rate ×
(Tcache + Tdisk)
= 0.99129(0.5) + 0.00871(0.5 + 10,000)
≈ 87.6 µs
Even with a 10 ms disk, most requests finish in 0.5 µs. The small miss rate still matters because each miss is so expensive.
Common Mistakes
Calling DRAM permanent storage
DRAM holds main memory, but it is volatile. Powering down loses its contents.
Forgetting the cache check on a miss
A miss takes the cache-access time and the slow-memory time because you discover the miss only after checking the cache.
Using the hit rate for slow accesses
Only misses pay the slow-access cost. Compute miss rate as
1 - hit rate.
Thinking SSDs have no limitations
They avoid mechanical delays, but flash blocks must be erased and wear out after repeated writes.
Quick Reference
| Concept | Remember |
|---|---|
| SRAM | Very fast, expensive, volatile; registers and caches |
| DRAM | Volatile main memory; capacitors require refresh |
| SSD | Nonvolatile flash storage; pages, blocks, erase-before-rewrite, wear |
| Hard disk | Nonvolatile rotating storage; seek + rotation + transfer |
| Cache miss rate | 1 - hit rate |
| Average cache time | hit rate × Tfast + miss rate × (Tfast + Tslow) |
Check Yourself
Try these before opening the answers. The numbers differ from Worksheet 09.
- Which technology is normally used for main memory: SRAM or DRAM? Why is it not normally used for persistent storage?
- What makes DRAM dynamic?
- Name the three components of a hard disk's access time.
- A cache takes
1 µsto access, slow storage takes1,000 µs, and the cache hit rate is 98%. What average access time results if every request checks the cache first? - Why can an SSD be faster than a hard disk yet still have a write-related disadvantage?
Answers
Show the answers
- DRAM. It is denser and less expensive than SRAM, but it is volatile, so its contents disappear when the system loses power.
- Its capacitors leak charge and therefore must be periodically refreshed.
- Average seek time, average rotational latency, and average transfer time.
0.98(1) + 0.02(1 + 1,000) = 21 µs. The miss rate is 2%, and each miss includes both the cache check and slow-storage access.- An SSD has no moving parts, but flash must erase a whole block before a page can be rewritten, and repeated writes wear out flash blocks.
Next Step
Complete Worksheet 09. For its cache calculation, convert all times to the same unit first, then label which term represents a hit and which represents a miss.