Lesson 4
Computer Systems Lesson 4
Computer Systems Lesson 4 of 5

The memory problem

Why do we need registers, cache, RAM and ROM when one type of memory would be simpler? The answer is a fundamental engineering trade-off between speed, cost and capacity.

35-45 minutes Core content Core GCSE CS content Interactive hierarchy

A modern CPU can execute billions of instructions per second. A standard NVMe SSD can transfer data at roughly 7 GB per second. That sounds fast - but at 4 GHz, the CPU would exhaust a 7 GB/s connection in microseconds while waiting for the next instruction. The CPU is orders of magnitude faster than any storage medium we can affordably attach to it.

The solution: A hierarchy of memory types, each optimised for a different balance of speed, cost and capacity. The faster the memory, the smaller and more expensive it is - so we use tiny amounts of it very close to the CPU and larger, slower amounts further away.

The memory hierarchy

Click each level to see what it is, where it sits, and why we need it. The bars show relative capacity - notice how the fastest memory is also the smallest.
Registers
~1 ns access
Bytes in size
Registers are inside the CPU itself. Access time is under 1 nanosecond - one clock cycle. They hold the data the CPU is currently working on: the instruction being executed, the address being accessed, the result just calculated. There are typically 8-32 general-purpose registers plus the named ones (PC, MAR, MDR, CIR, ACC). Total storage: a few hundred bytes at most.
L1 Cache
~4 ns access
32-64 KB per core
L1 cache is the first level of cache, split into instruction cache (I-cache) and data cache (D-cache). Each CPU core has its own L1 cache. Access time is 4-5 clock cycles - fast enough that the CPU rarely has to wait. Typical size: 32 KB to 64 KB per core.
L2 Cache
~12 ns access
256 KB - 1 MB
L2 cache is larger but slower than L1. It acts as a second check before going to L3 or RAM. May be per-core or shared between a pair of cores depending on the chip design. Access time is typically 10-15 clock cycles.
L3 Cache
~40 ns access
4 MB - 64 MB
L3 cache is shared across all cores on the CPU. It is the last resort before main memory. A cache miss here triggers a slow trip to RAM. L3 size varies enormously - a budget laptop might have 4 MB while a server CPU might have 128 MB. Access time: 30-50 clock cycles.
RAM
~60 ns access
8 GB - 128 GB
Random Access Memory (RAM) holds the currently running programs and their data. It is volatile - its contents are lost when power is removed. Access time is roughly 60-100 nanoseconds, meaning the CPU waits 60-200 clock cycles each time it needs to fetch from RAM. This is why cache is so critical - every cache hit avoids this wait.
SSD/HDD
50-100 us access
256 GB - 8 TB
Secondary storage holds data that persists when power is off. Even an NVMe SSD at 7 GB/s is roughly 1000x slower than RAM in latency terms. When a program needs data not in RAM (a page fault), it must wait for a disk access - typically causing a noticeable pause.
Bars represent relative capacity (not to scale) Speed decreases as capacity increases Cost per GB increases as you move up
Speed
Increases as you move up the hierarchy. Registers and L1 cache are fastest.
💰
Cost per byte
Also increases going up. 1 GB of cache costs far more than 1 GB of SSD.
📦
Capacity
Decreases going up. Registers hold bytes; SSDs hold terabytes.

RAM and ROM - two very different jobs

Students often mix these up. They are both types of memory, but they serve completely different purposes. The key distinction is volatility and writability.
RAM
Random Access Memory
Volatile - contents lost when power is removed
Readable and writable - the CPU can read from and write to it freely
Holds currently running programs, the operating system, and working data
More RAM means more programs can run simultaneously without paging to disk
Uses DRAM (Dynamic RAM) technology in main memory; SRAM in cache
ROM
Read-Only Memory
Non-volatile - contents survive when power is removed
Read-only in normal operation - cannot be changed by running programs
Stores the BIOS/UEFI firmware - the startup instructions that run before the OS loads
Resistant to accidental overwriting - critical for system integrity
Modern "ROM" is often flash memory (EEPROM) - technically writable but treated as read-only
Volatile vs Non-volatile: what happens when power is cut?
RAM
Currently holds: "Word document, browser tabs, game state"
POWERED ON
ROM / SSD
Stores: "BIOS, installed programs, saved files"
POWERED ON
Exam focus

A common 2-mark question: "State one difference between RAM and ROM." The best answers contrast volatility (RAM is volatile, ROM is non-volatile) or writability (RAM can be written to during normal operation, ROM cannot). Avoid vague answers like "RAM is faster" without context - speed is not the defining distinction between them.

When RAM fills up: virtual memory

Physical RAM is limited - a typical laptop has 8 or 16 GB. But you can have Chrome, Photoshop, Word, Spotify and a game open at the same time, using more memory than physically exists. The operating system solves this with virtual memory: when RAM is full, it quietly moves the least-recently-used pages of data out to a reserved area on the SSD or hard drive (the swap file or pagefile). This frees a RAM slot for the active programme. If the swapped-out page is needed again, it is swapped back in - evicting something else if necessary.
Secondary storage in this lesson: the SSD/hard drive is simply "a large, non-volatile storage device - much slower than RAM but far larger." A dedicated lesson covers how they work internally.
Virtual Memory Simulator
8 RAM slots - open programmes until RAM fills, then watch the OS swap
0
RAM used
0
Swaps
Fast
Performance
Physical RAM - 8 slots
Swap file (SSD) - pages moved here when RAM is full
Empty - nothing swapped yet
Open a programme to begin. When all 8 RAM slots are filled, the OS will start swapping.
Notice the swap count and performance indicator as you fill RAM beyond 8 programmes.
The performance cost of swapping is severe. RAM access takes around 60-100 nanoseconds. Even an NVMe SSD takes 20-100 microseconds - that is up to 1000x slower. Older hard drives are slower still. When a computer is "thrashing" (swapping constantly), the CPU spends more time waiting for the disk than actually processing. This is why a computer with too little RAM feels sluggish even with a fast CPU.
Exam focus

Virtual memory allows programs to run when physical RAM is full by using secondary storage as an extension of RAM. The cost is significantly reduced performance, as disk access is much slower than RAM access. A larger amount of physical RAM reduces how frequently virtual memory is used, improving multitasking performance. Do not confuse virtual memory with ROM or cache.

True or False?
1. RAM is non-volatile - its contents survive a power cut.
2. L1 cache is slower than L3 cache but holds more data.
3. More RAM means the CPU runs at a faster clock speed.
4. A cache miss means the required data was found in cache.
5. ROM typically stores the firmware that runs when a computer starts up.
Lesson 4 Quiz
4 questions on memory
Question 1 of 4
Why do CPUs use a hierarchy of memory types rather than a single type of fast memory?
Question 2 of 4
A user installs more RAM in their computer. Which of the following is the most likely improvement?
Question 3 of 4
What does it mean if there is a "cache miss"?
Question 4 of 4
Which type of memory stores the BIOS/UEFI firmware and retains it when the computer is switched off?
out of 4 correct
Think deeper

Virtual memory allows an operating system to use part of secondary storage (SSD/HDD) as if it were RAM. Given what you know about the memory hierarchy, what are the trade-offs of using virtual memory?

Benefit: Allows programs to run even when physical RAM is full - the OS pages less-used data to disk, freeing RAM for active processes. This means more programs can run simultaneously than physical RAM would otherwise allow.

Trade-offs: Storage is thousands of times slower than RAM. When the OS has to "swap" data between RAM and disk, performance degrades dramatically - this is why a computer with insufficient RAM feels sluggish. Additionally, SSDs have a limited number of write cycles, so heavy virtual memory use can reduce SSD lifespan over time.
Revision
Computer Systems Flashcards
27 key terms across all 5 lessons. Filter by topic, flip to reveal, mark as known.
Open flashcards
Lesson 4 - Teacher Resources
The memory problem
Teacher mode (all pages)
Shows examiner notes on the Exam Practice page
Suggested starter (5 min)
"You have 16 GB of RAM in your laptop. Your SSD is 1 TB. Why not just use the SSD as RAM and have 1 TB of working memory?" Give 2 minutes for group discussion. Most students know SSD is slower but cannot explain why it matters at CPU speed. The answer - latency in nanoseconds vs microseconds - sets up the entire lesson. Why speed, cost, and capacity are always in tension.
Lesson objectives
1Explain the memory hierarchy and state why each level exists: registers are fastest but tiny, RAM is larger but slower, SSD is larger still but orders of magnitude slower.
2Compare RAM and ROM by volatility, typical use case, and whether they can be written to at runtime.
3Describe virtual memory, why the OS uses it when RAM is full, and what the performance cost is.
4Explain the role of cache in the memory hierarchy and link it to the concept of locality of reference.
Key vocabulary (board-ready)
Memory hierarchy
The pyramid of storage types ordered from fastest/smallest/most expensive (registers, L1 cache) to slowest/largest/cheapest (SSD, HDD). Data moves up the hierarchy as needed, down as it becomes less used.
Volatile
Memory that loses all stored data when power is removed. RAM is volatile - every open document and running program disappears when the computer is switched off.
Non-volatile
Memory that retains data without power. ROM, SSD, HDD, and flash storage are all non-volatile.
RAM (Random Access Memory)
The computer's working memory. Programs and data currently in use are loaded into RAM so the CPU can access them quickly. Volatile and significantly faster than SSD.
ROM (Read-Only Memory)
Memory containing permanent firmware (e.g. BIOS/UEFI) written at manufacture. Non-volatile; cannot be modified by programs at runtime.
Virtual memory
A technique where the OS uses a portion of the SSD/HDD as an extension of RAM when physical RAM is full. Significantly slower - SSD access is thousands of times slower than RAM.
Locality of reference
The observation that programs tend to access the same memory locations repeatedly (temporal locality) and nearby locations in sequence (spatial locality). Cache exploits this to achieve high hit rates.
Suggested lesson plan
0-5 min: Starter: "Why not use 1 TB SSD as RAM?" Group discussion. Collect answers. Bridge into the speed-cost-capacity tension that defines the memory hierarchy.
5-18 min: Memory hierarchy: registers - cache - RAM - SSD - HDD. Draw the pyramid. Label with approximate speeds (ns vs microseconds vs milliseconds) and typical sizes.
18-30 min: RAM vs ROM: volatility, use cases, runtime writability. Common misuse: "My computer has 8 GB of memory" - is that RAM or ROM? Why does the distinction matter?
30-42 min: Virtual memory: OS page file, what happens when RAM fills up, performance penalty. Demonstrate: open many applications until the computer slows down. What is the OS doing?
42-52 min: Locality of reference and cache: temporal vs spatial locality. Why cache works. Hit rates in practice. Students calculate average access time given hit rate and miss penalty.
52-60 min: Exit tickets. Address the most common confusion between RAM, cache, and virtual memory.
Discussion prompts
A laptop with 8 GB RAM runs perfectly for essay writing. The same laptop struggles with ten 4K video clips in a video editor. What is happening at the memory level, and why does adding RAM (not a faster CPU) fix it?
ROM contains the BIOS - the code that runs before the operating system even loads. Why must this code be non-volatile? What would happen if the BIOS were stored in RAM?
When RAM runs out and the OS starts using virtual memory, programs do not crash - they just become very slow. Why does using SSD as overflow RAM cause such a dramatic slowdown compared to physical RAM?
Locality of reference explains why cache works. If programs accessed memory completely randomly, cache would be almost useless. What is it about how programs actually execute that means they tend to reuse the same data repeatedly?
Common misconceptions
X"RAM is where you store things permanently" - RAM is volatile working memory. Files are stored on SSD/HDD. Students consistently confuse storage and memory - use the desk/filing cabinet analogy firmly.
X"More RAM always makes computers faster" - RAM only improves performance when existing RAM is full and virtual memory is being used. Adding RAM to a system with spare RAM makes no difference.
X"ROM cannot be changed at all" - modern EEPROM and flash-based ROM (used for BIOS/UEFI) can be updated via firmware flash. The key point is it cannot be written by running programs under normal conditions.
X"Virtual memory is just more RAM" - virtual memory uses SSD storage, which is 10,000-100,000 times slower than RAM. It prevents crashes but at a severe performance cost. It is not equivalent to physical RAM.
Exit ticket questions
Place these memory types in order from fastest to slowest: RAM, register, L1 cache, SSD.
[1 mark - register, L1 cache, RAM, SSD]
What is the key difference between RAM and ROM in terms of volatility?
[2 marks - RAM is volatile (loses data when powered off) / ROM is non-volatile (retains data without power)]
Explain why a computer slows down significantly when virtual memory is being used.
[2 marks - virtual memory uses SSD/HDD / SSD is thousands of times slower than RAM / swap operations introduce major latency]
Describe what "locality of reference" means and why it allows cache to be effective.
[2 marks - programs tend to reuse same memory locations or access nearby locations / cache stores recently used data so repeated accesses are fast]
Homework idea
A school is upgrading its computer lab. Each PC has 8 GB of RAM and a 256 GB SSD. The budget allows either upgrading to 16 GB RAM OR replacing the SSD with an NVMe drive. Write a recommendation (150 words) explaining which upgrade you would choose, justifying your answer using what you know about the memory hierarchy, virtual memory, and typical school use cases.
Classroom tips
The desk/filing cabinet analogy is the most effective for RAM vs storage: RAM is your desk (fast to access, limited space, cleared when you go home), SSD is the filing cabinet (much more space, slower to retrieve, contents persist). Use it consistently throughout.
Virtual memory is often misunderstood as a feature rather than a workaround. Emphasise that using virtual memory is a sign that the system is under pressure - the OS is making the best of a bad situation.
For memory hierarchy speeds: students do not need exact figures, but they should know the order of magnitude. Registers ~0.3 ns. L1 ~1 ns. RAM ~50-100 ns. SSD ~50,000 ns. HDD ~10,000,000 ns. The jumps between levels are enormous.
The average access time calculation (hit_rate x hit_time + miss_rate x miss_penalty) is explicitly assessable at A-Level and appears as a 3-mark question. Introduce it for higher-attaining students at GCSE.