A1.1.4 · Computer hardware and operation
Primary memory
By the end you can
Explain what RAM, ROM, cache and registers are for, why cache comes in levels and why locality makes it work, what hits and misses do to speed, and what virtual memory is.
A CPU core can do billions of operations a second, but only if the data it needs is right there. is the memory the CPU can use directly, and it comes in several kinds because no single technology is fast, big and cheap all at once. The faster a memory is, the more it costs per byte, so computers use a little of the very fast kind and a lot of the slower kind.
The CPU works down the hierarchy below. at the top hold the handful of values being used this instant; each level further down is bigger, slower and cheaper per byte. The aim is to keep latency (the wait for each item) low and throughput (data delivered per second) high, by keeping what is needed next as close to the CPU as possible.
RAM#
(random access memory) holds whatever is in use right now: the operating system, the programs you have open and their data. When you open an app, it is copied from storage into RAM so the CPU can reach it quickly. RAM can be read and written as often as needed, and any location can be reached as quickly as any other (that is what “random access” means).
RAM is : switch off the power and everything in it is gone. That is why unsaved work is lost in a power cut, and why files must be saved to secondary storage. More RAM lets more programs stay open at once without slowing down.
When RAM fills up, the operating system can move the parts of programs that are not being used out to a reserved area of secondary storage, and bring them back when they are needed. This is . It stops the computer running out of memory, but storage is thousands of times slower than RAM, so a computer that leans on it heavily becomes sluggish, with the drive constantly busy. The real cure is more RAM.
ROM#
(read-only memory) holds instructions that must survive with the power off and rarely change. Its best-known job is the start-up firmware (BIOS, or its modern replacement UEFI): when you switch on, RAM is empty, so the CPU runs the firmware in ROM, which tests the hardware and then loads the operating system from storage into RAM. In phones, ROM-style storage also holds the core system software. Modern “ROM” is usually flash memory, so the firmware can still be updated occasionally.
RAM (volatile)
- Operating system
- Web browser
- Your unsaved essay
- Music player
ROM (non-volatile)
- Start-up firmware (BIOS/UEFI)
- Hardware self-test
Still here, power or not.
Working normally: programs and data in use live in RAM.
Cache#
Even RAM is slow compared with the CPU: fetching from RAM can take a couple of hundred clock cycles, during which the core would sit idle. is a small amount of very fast memory on the CPU chip that keeps copies of data and instructions the CPU has used recently or is likely to need soon. It works because of , two habits almost every program has:
- Temporal locality: data used recently is likely to be used again soon (a loop counter, the instructions of the loop itself).
- Spatial locality: data next to what was just used is likely to be used next (the next item of an array, the next instruction). So a cache loads a whole block of neighbouring bytes at a time, not just the one asked for.
Cache comes in levels:
- L1: the smallest (tens of kilobytes per core) and fastest, inside each core; usually split into one part for instructions and one for data.
- L2: bigger (hundreds of kilobytes to a few megabytes) and a little slower, usually one per core.
- L3: the biggest (several to tens of megabytes) and slowest cache, usually shared by all the cores, but still much faster than RAM.
The CPU looks in L1 first, then L2, then L3, then RAM. Finding the data in a cache is a ; not finding it is a , and the data has to come from further away. The (hits ÷ requests) is the measure of how well the cache is working.
A loop that works on the same 4 blocks over and over, like a counter and a few variables. After the first pass, everything is in L1.
L1
~4 cycles
served: 0
L2
~12 cycles
served: 0
L3
~40 cycles
served: 0
RAM
~200 cycles
Holds everything, but each trip is slow.
served: 0
L1 hit rate
-
Time with caches
-
If every request went to RAM
-
Cycle counts are typical round figures; real chips differ, but each level is always several times slower than the one before.
Making cache work better
A bigger cache holds more, so it misses less, but it costs more and can be slightly slower. Modern CPUs also prefetch: they notice patterns, such as reading through an array, and load the next blocks into cache before they are asked for.
Check yourself
Primary memory, cache and locality
Quick questions, made fresh every time and marked here. Do a few until they feel easy.
Exam practice
Paper 1-style questions
6 questions · 18 marks
Write your answer as you would in the exam, then show the mark points and tick each one your answer made. These are our own questions in the style of the exam, not past-paper questions.
1.Explain the purpose of cache memory.
[3]Explain: Give reasons: say what happens AND why, or how one thing causes another.
2.Distinguish between RAM and ROM.
[4]Distinguish: Make the differences between two things clear.
3.Explain why a CPU has several levels of cache (L1, L2, L3) rather than one.
[3]Explain: Give reasons: say what happens AND why, or how one thing causes another.
4.During a test, a CPU made 380 memory requests, and 342 of them were found in L1 cache. Calculate the L1 hit rate as a percentage.
[2]Calculate: Work out the number, showing the working.
5.Outline how locality makes cache memory effective.
[2]Outline: A brief account: the main points, without much detail.
6.A student’s laptop has 4 GB of RAM. It becomes very slow when many browser tabs are open, and the storage drive is busy the whole time. Suggest why this happens and what upgrade would help most.
[4]Suggest: Put forward a sensible answer for the situation given, with a reason. There may be several good answers.
Past papers
Old exam questions on this topic
From HL Paper 1, May 2014 to November 2025. These papers were set on the previous syllabus, so the wording may differ from today's exam, but the topic is the same. Find the questions and markschemes in your school's past-paper pack.
| Paper | Question | Marks | About |
|---|---|---|---|
| May 2025 TZ2 | 2(b) | 2 | When secondary storage extends primary memory |
| May 2023 TZ1 | 7 | 2 | RAM versus ROM |
| May 2023 TZ1 | 9 | 2 | An advantage of virtual memory (TZ2: a disadvantage) |
| November 2023 | 12(b) | 2 | Which memory holds a control program |
| November 2022 | 7 | 3 | Why a bigger cache improves performance |
| May 2019 | 5 | 4 | One advantage and one disadvantage of virtual memory |
| May 2019 | 14(a) | 2 | Two characteristics of RAM |
| November 2019 | 2 | 3 | Purpose of cache |
| November 2019 | 7 | 2 | What virtual memory is |
| November 2018 | 8(a) | 5 | RAM versus ROM; the OS managing primary memory |
| May 2017 | 4 | 2 | Why cache speeds things up |
| November 2016 | 2 | 2 | Purpose of cache; diagram of CPU, cache and RAM |
| May 2014 | 5 | 2 | RAM and ROM compared |
In a nutshell
- Primary memory is memory the CPU uses directly: registers, cache, RAM and ROM.
- RAM holds the programs and data in use. It is fast, read/write and volatile.
- ROM holds the start-up firmware that tests the hardware and loads the OS from storage into RAM. It is non-volatile.
- Cache is small, very fast memory between the CPU and RAM holding recently or frequently used data. L1 is smallest and fastest, then L2, then L3 (often shared by all cores).
- A cache hit avoids a slow trip to RAM; a miss costs time. Hit rate = hits ÷ requests.
- Caches work because of locality: recently used data is used again (temporal) and nearby data is used next (spatial).
- Virtual memory uses secondary storage as overflow when RAM is full: it keeps programs running, but slowly.
- The hierarchy trades speed against size and cost: the closer to the CPU, the faster, smaller and more expensive.
