Computer Organisation and Architecture · Memory Hierarchy and Locality
Need for Cache and Speed Gap Between CPU and Main Memory
Overview
The CPU is much faster than main memory, but it must fetch every instruction and datum from main memory before executing it, so the CPU's effective speed is limited by main-memory speed.
Small, very fast storage placed on or near the CPU — first registers, then cache — is used to bridge this gap.
Key concepts
- Memory hierarchy speeds: CPU speed > main memory speed > secondary memory (hard disk) speed. Main memory is not as fast as the CPU.
- Fetch–execute dependency: To execute anything, the CPU must first read the instruction/data from main memory, so the CPU cannot run faster than memory can feed it.
- Bus: A set of wires connecting the CPU and memory. A main-memory request must go onto the bus, and going through the bus (and the memory itself) is what makes the access slow compared with the CPU's own logic.
- Registers: Very fast storage placed on the same chip as the CPU. Being on-chip, they avoid the bus/main-memory delay and are very fast compared with main memory.
- Prefetching: The instruction is already present in the registers before execution begins, so the CPU can get it quickly and execute faster.
- Register limitation: Register storage is very small — it can hold only a few instructions, not an entire program. This capacity/cost limit motivates the next level of the hierarchy, cache.

How it works
- The CPU wants to read an instruction or datum; it must first fetch it from main memory, then execute it.
- The request goes onto the bus to reach main memory; the bus trip and the memory access make this far slower than the CPU's own logic.
- Because every instruction waits on this fetch, the CPU's speed effectively falls to the speed of main memory.
- To avoid the bus/main-memory delay, very fast storage is used: registers, placed on the same chip as the CPU.
- If the instruction is prefetched — already in the registers before execution begins — the CPU gets it at register speed and executes faster.
- Registers solve the speed problem but hold only a few instructions, not a whole program; this drives the need for the next level of the hierarchy (cache).
Formulas
-
Gap factor = (main memory access time) / (CPU instruction execution time) =
-
CPU instruction execution time s (1 ps)
-
Main memory access time s (1 ns)
-
Gap factor: the CPU could execute about 1000 instructions in the time of one main-memory access, so without fast storage the CPU idles and its effective speed equals main-memory speed.
Worked examples
Effect of the speed gap on CPU performance
- Given: CPU executes one instruction in s; one main-memory read takes s.
- Step 1: Every instruction must first be read from main memory, so each instruction costs at least s of memory time.
- Step 2: Compare: — the memory access is 1000 times slower than the CPU's execution step.
- Step 3: The CPU's speed falls to the speed of main memory; the fast CPU sits idle waiting on the bus/memory.
- Step 4: Fix with registers on the CPU chip: if the instruction is prefetched into a register, the CPU gets it at register speed (no bus trip to main memory) and executes faster.
Comparison
| Level | Relative speed | Location | Cost / capacity issue |
|---|---|---|---|
| CPU (execution) | Fastest ( s per instruction, illustrative) | — | — |
| Registers | Very fast (on-chip, no bus delay) | Same chip as CPU | Very small; costly; holds only a few instructions, not a whole program |
| Main memory | Slow relative to CPU ( s access, illustrative) | Off-chip, reached over the bus | Large capacity, but access through the bus limits CPU speed |
| Secondary memory (hard disk) | Slowest | Off-chip | Large capacity, much slower than main memory |
Revision summary
- CPU speed > main memory speed > secondary memory (hard disk) speed; main memory is not as fast as the CPU.
- The CPU must read instructions/data from main memory before executing, so CPU speed is bounded by main-memory speed.
- The delay comes from having to go onto the bus (a set of wires) to reach main memory.
- Registers on the CPU chip are the first fix: very fast compared with main memory, and prefetched instructions execute faster.
- Registers solve the speed problem but fail on capacity/cost — only a few instructions, not the entire program — which drives the need for cache.
Previous-year exam insights
- Average memory access time (AMAT) = hit time + miss rate × miss penalty;
for a two-level hierarchy AMAT = H1·T1 + (1−H1)·T2, and hit ratio + miss ratio = 1. - Locality of reference: temporal locality (a recently accessed item is likely to be accessed again soon) and spatial locality (items near a recently accessed address are likely to be accessed soon) are the principles that make cache effective.
- Cache is placed between CPU and main memory and holds recently used blocks; on a hit the CPU is served at cache speed, on a miss the block is fetched from main memory (plus a block-transfer cost) and the CPU stalls for the miss penalty.
- The speed gap is bridged by a hierarchy (registers → cache → main memory → secondary storage) in which each level is larger, cheaper per bit and slower than the level above; the goal is to give the illusion of the fastest level's speed at the largest level's capacity/cost.
- Effective/overall access time with a cache: = h· + (1−h)·( + ) when a miss includes the cache lookup, or = h· + (1−h)· when it does not;
efficiency/speedup = / . - Registers are the fastest and smallest level, are managed by the compiler/ISA (not by hardware replacement), and their number is fixed by the architecture; cache is managed by hardware and is transparent to the programmer.