01: Why Computers Need a Memory Hierarchy
I'm starting this DDR series with a question that comes before the timing tables: why do computers need several kinds of memory? Registers are fast, and a solid-state drive can hold a lot of data. Why can't one of them do the whole job?
To work that out, I need to compare how long data takes to arrive, how much can move at once, how much fits, and what happens when power is removed. Those are separate requirements.
What I need to understand first
Memory is not a single box. A modern system normally has several levels:
- Registers inside each processor core.
- One or more levels of cache, usually built from Static Random Access Memory (SRAM).
- Main memory, usually built from Dynamic Random Access Memory (DRAM), such as Double Data Rate (DDR) Synchronous DRAM.
- Persistent storage, such as a solid-state drive.
- Sometimes a still larger remote or archival layer.
The levels near the processor are fast but small and expensive per bit. The levels farther away are larger and cheaper per bit, but slower. The hierarchy is an engineering compromise, not an accidental collection of parts.
The tradeoffs I need to compare
Latency
Latency is the delay between asking for data and receiving it. A register can be available as part of a processor operation. An access that reaches DRAM takes much longer. An access that reaches an SSD takes longer again.
Bandwidth
Bandwidth is the amount of data that can be transferred over time. A road can have a long travel time but still carry many cars per hour if it has many lanes. Memory is similar: the first data may take time to arrive, while a burst of following data can be transferred quickly.
Capacity
Capacity is how much information the memory can store. Registers are measured in a small number of words per core. Caches are commonly measured in kilobytes or megabytes. Main memory is measured in gigabytes, and storage may be measured in terabytes.
Cost and physical limits
Fast memory cells generally use more transistors, more chip area, or more demanding circuitry. Large memories also have longer wires, bigger decoders, greater power, and more opportunities for faults. A technology that is excellent for a few registers may be uneconomical for billions of bytes.
A very short historical path
Early computers explored several physical ways to hold information. Mercury delay lines represented information as circulating acoustic pulses. Williams tubes stored charge patterns on cathode-ray-tube screens. Magnetic-core memory stored bits using tiny magnetized rings threaded by wires. Core memory became important because it was nonvolatile, robust for its time, and supported random access, but building and wiring large arrays was labor-intensive.
Semiconductor memory eventually made dense, automated manufacturing possible. SRAM offered speed, while DRAM achieved much greater density by using a small cell that must be refreshed. DRAM became the practical choice for main memory. Synchronous DRAM later placed its interface under a clock, and DDR SDRAM increased interface bandwidth by transferring data on both clock edges.
This history shows a pattern that continues today: memory changes when an older design can no longer balance density, speed, power, manufacturing, and system complexity.
Following one load through the hierarchy
Suppose a processor executes a load instruction for data in a virtual address space. Here is a simplified cache-miss path; translation and cache lookup can overlap in a real processor.
- The processor calculates the load address and checks its translation and permissions.
- The cache hierarchy looks for the cache line containing the requested bytes.
- If the last-level cache misses and no other cache supplies the line, the request reaches the memory controller.
- The controller maps the physical address to its supported channel, rank, bank, row, and column fields. The applicable generation and platform also determine subchannel and bank-group selections; bank groups already exist in DDR4.
- It schedules the DRAM commands and receives the returned data burst or bursts.
- The cache fills the line, and the load supplies its destination register.
Registers are selected operands and destinations of instructions. They are not a cache that checks an address and reports a "register miss."
If address translation finds that the page is not resident, the processor raises a page fault. The operating system handles it and may need storage I/O before the load can be retried. That is a separate path, not a DRAM chip forwarding a miss to an SSD.
The hierarchy works because programs tend to reuse recently accessed data and access nearby addresses. These behaviors are called temporal and spatial locality. They are not perfect, but they are common enough to make caching effective.
Where the simple hierarchy needs more care
The hierarchy is not only a vertical list of technologies. It is a collection of managed copies. The same cache line may exist in a core cache, a shared cache, DRAM, and a storage-backed page. Hardware coherence, operating-system paging, and storage writeback decide which copy is current. Capacity, latency, bandwidth, persistence, and consistency are therefore different questions.
Latency also has a distribution. A DRAM access that hits an open row with an idle channel is not equivalent to one waiting behind writes, refresh, a row conflict, or another socket's traffic. Average latency can look healthy while rare long delays break a real-time deadline. Bandwidth has a similar boundary: CPU-to-cache bandwidth, memory-channel bandwidth, and storage throughput cannot be compared without naming where bytes were measured.
The working set matters more than the program's total allocation. A 10 GB process can run mostly from cache if it repeatedly touches a small region, while a 500 MB random stream can put steady pressure on DRAM. Prefetching can hide some latency but can also consume bandwidth and displace useful data.
Modern systems can have Non-Uniform Memory Access (NUMA): the same kind of DRAM is closer to one processor or controller than another. “It is in DRAM” does not imply one latency. Likewise, adding capacity can reduce paging and transform performance even if the DRAM data rate never changes.
Finally, volatile and nonvolatile are independent of speed. DRAM loses ordinary contents without refresh and power; an SSD retains data but has much longer access latency. A hierarchy exists because these properties do not line up along one simple “better” axis.
Computers need a memory hierarchy because every memory technology makes tradeoffs. Registers and caches provide speed, DRAM provides practical working capacity and bandwidth, and storage provides inexpensive persistence. DDR makes sense only when I see where it sits in that hierarchy and which problem it is intended to solve.
Comments
Post a Comment