CS05-03 Computer Science Watch
Virtual memory
In this lesson
In this video you'll learn about virtual memory for GCSE Computer Science. Watch first: {{video:CS05-01}}
By the end: Explain that virtual memory is a section of secondary storage used as if it were extra RAM when RAM is full; describe how data and instructions not currently in use are moved from RAM to virtual memory to free space, and moved back into RAM when needed; and explain why this slows the computer down.
What it covers
- WHY IT IS NEEDED: RAM is full - too many programs open, or programs too large - and the computer still needs to load more
- WHAT IT IS: a section of SECONDARY STORAGE (a hard drive or SSD) set aside and used as if it were extra RAM
- HOW IT WORKS: data and instructions that are not currently being used are moved out of RAM into virtual memory, freeing space in RAM; when they are needed again they are moved back into RAM (and something else may be moved out)
- That the CPU still only works on what is IN RAM - virtual memory is a holding area, not a place the CPU runs things from
- WHY IT IS SLOW: secondary storage is much slower to read and write than RAM, so every transfer costs time; when transfers happen constantly the computer slows badly (the name 'disk thrashing' may be given once, as a label, not as examinable vocabulary)
- The honest fix: adding more RAM reduces the need for virtual memory
- PRECISE WORDS, which is where OCR's 2023 marks went: data moves between RAM (not 'primary storage') and secondary storage (not 'memory'); primary storage is too wide a word because it also includes ROM and cache
- APPLICATION: a system with no secondary storage, or one that never fills its RAM, does not need or cannot have virtual memory - OCR examined exactly this with an embedded system
Key words
About this video
Virtual Memory (Secondary Storage as RAM) | GCSE Computer Science
How virtual memory uses secondary storage as extra RAM, how data moves between them, and why it slows a computer down.
OCR J277 GCSE. Memory and storage 3 of 6.
Full Memory and storage playlist: https://www.youtube.com/playlist?list=PLN6LILUAa4Zs
More at https://scholafly.com
Watch first: RAM, ROM and types of memory - https://youtu.be/uyM_YCx5vAU
Video code: CS05-03 (search "ScholaFly CS05-03")
Videos in this chapter:
CS05-00 Memory and storage - Intro: https://youtu.be/HP7hdjSfVjI
CS05-01 RAM, ROM and types of memory: https://youtu.be/uyM_YCx5vAU
CS05-02 Cache: https://youtu.be/GZUhJCGdqMY
CS05-03 Virtual memory: https://youtu.be/BUkacndz4Nc
CS05-04 Secondary storage: magnetic, solid state and optical: https://youtu.be/5Amsjf0nS8E
CS05-05 Choosing the right storage: https://youtu.be/79gK1sMFliI
CS05-06 Cloud storage: https://youtu.be/8bnzEUvDMfQ
#GCSEComputerScience #MemoryAndStorage #VirtualMemory
For teachers
This GCSE Computer Science lesson teaches virtual memory. By the end, students should be able to explain that virtual memory is a section of secondary storage used as if it were extra RAM when RAM is full; describe how data and instructions not currently in use are moved from RAM to virtual memory to free space, and moved back into RAM when needed; and explain why this slows the computer down. It works through four worked examples and the mistakes examiners report, and suits Foundation and Higher tier students.
Exam board specification references:
Cambridge OCR Level 1/Level 2 GCSE (9-1) in Computer Science
- 1.2.1 Primary storage (memory)
Read the transcript
Picture a desk with room for four open books, and you need a fifth. You could stop. Or you could put a book you are not reading right now on the floor beside you, open the new one, and swap them back when you need the first one again. It works, and no book is ever lost. But every swap means bending down to the floor, and if you keep swapping, you spend more time bending than reading.
Memory and storage has six videos, and this is video three of six, the one about running out of RAM. If RAM feels hazy, go back to RAM, ROM and types of memory first.
Swap the desk for RAM, and the floor for secondary storage, the slower, bigger store such as a hard drive or an SSD. Not every exam board asks for this topic. Find your own board's line here, and if yours treats it as optional, this video is background for you. RAM has a fixed size. Open too many programs, or programs that are too big, and RAM fills up while the computer still needs to load more. Virtual memory is a section of secondary storage, set aside and used as if it were extra RAM. The operating system, the software that runs the computer itself, does the moving. Its wider job of sharing out memory belongs to the chapter called Software, systems and languages. Now, when RAM is full, which data should be moved out to make room? Data and instructions that are not being used right now. Whatever is in use has to stay where the processor can work on it.
Next, the moves themselves, one at a time, with both ends named every time. First, data and instructions not in use are moved out of RAM into virtual memory, on secondary storage. That frees space in RAM. Then the new program or data loads into the space that was freed. Later, when the moved data is needed again, it is moved back from secondary storage into RAM. Something else not in use may be moved out to make room for it. The processor never runs anything from virtual memory. It can only work on what is in RAM, which is why the data has to come back first. One examiner's report, on a question about how an operating system uses virtual memory when main memory runs short, says: Few candidates were able to accurately describe how inactive processes could be temporarily moved out of RAM to secondary storage to free up space in RAM until such time as they were required again. That sentence is a full answer in itself. The fix is to name all three moves: out of RAM, to secondary storage, and back when needed. Here is a statement with one wrong word in it: data is moved back into primary storage when it is needed. What should replace primary storage in that statement, and why? RAM. Primary storage also includes ROM and cache, and nothing is ever moved into ROM, so it is not precise enough. One examiner's report on a correct-the-statement question gives the same reason: The final statement was often changed to primary storage, which was not enough because primary storage would include ROM and cache, therefore not being precise enough to describe how VM works. Instead of primary storage, write RAM at one end and secondary storage at the other, and never memory on its own.
Back to the books on the floor. Each swap cost a bend, and virtual memory has the same kind of cost. Secondary storage is much slower to read and write than RAM. Every move into or out of virtual memory takes time. When moves happen constantly, the computer slows badly, because it spends more time moving data than running programs. That is sometimes called disk thrashing. Virtual memory does not make a computer faster. It lets the computer keep going when RAM is full, and the price is speed. A laptop with a small amount of RAM runs smoothly with one program open. With ten open, it crawls. Why does the laptop slow down, and which upgrade would help most? RAM fills, virtual memory is used, and every move to and from secondary storage is slow. More RAM is the upgrade, because less then has to be moved out.
Now turn it round, because some systems never use virtual memory at all. Virtual memory needs two things to exist: RAM that can fill up, and secondary storage to move data into. A car's cruise control keeps its own speed and the distance to the car in front in a small RAM. It has no hard drive and no SSD. Why will the cruise control not use virtual memory? Give two reasons. Its RAM never fills, because it only ever holds a few values. And with no secondary storage, there is nowhere to create virtual memory. One examiner's report on a similar embedded system notes: Many candidates were able to identify that VM is used when a system is short of RAM, they were then able to apply this to the given system, that is that the current system will not run out of RAM. The same report goes further: Some of the stronger responses included an acknowledgement that the embedded system is unlikely to have secondary storage and therefore cannot create VM. The habit that report rewards is checking both conditions. Ask whether RAM can run short, then ask whether there is any secondary storage at all. One last line to draw. Virtual memory is on this computer's own drive, a few centimetres from the processor. Cloud storage is on someone else's computer, somewhere else, reached over the internet. One examiner's report records the mix-up in a single sentence: A common misconception was to confuse virtual storage with cloud storage. So the name does the work. Call it virtual memory every time, and keep it inside the computer, on its own drive.
Four questions to finish, and the desk and the floor are still a fair picture. A new statement: virtual memory is used when ROM is full. Which word is wrong? ROM. Virtual memory is used when RAM is full. Next, where is virtual memory, and what gets moved into it? It is a section of secondary storage. Data and instructions not in use right now are moved into it out of RAM. Now, why does heavy use of virtual memory slow a computer down? Every move to and from the disk is much slower than RAM, so the time adds up, like bending to the floor for every book. One more: a smart doorbell has a little RAM and no storage drive. Can it use virtual memory? It cannot. With no secondary storage, there is nowhere to put virtual memory.
If you could walk a friend through virtual memory, from RAM filling up to the data coming home again, this one's yours. Tap the thumbs up so it comes off your list. If it is still blurry, save it, give it a day and look again, and draw the two-way arrow yourself when you do.
Next in the chapter: Secondary storage: magnetic, solid state and optical, and how each one stores a one or a zero.
For more, visit scholafly.com, or watch the next video.
Related terms
For: OCR GCSE J277, Edexcel GCSE 1CP2
On the specification
| Board | Spec | Statement |
|---|---|---|
| OCR GCSE J277 | 1.2.1 | Primary storage (memory) |
| Edexcel GCSE 1CP2 | missing | the plan names no spec point for this board |
For teachers
This GCSE Computer Science lesson teaches virtual memory. By the end, students should be able to explain that virtual memory is a section of secondary storage used as if it were extra RAM when RAM is full; describe how data and instructions not currently in use are moved from RAM to virtual memory to free space, and moved back into RAM when needed; and explain why this slows the computer down. It works through four worked examples and the mistakes examiners report, and suits Foundation and Higher tier students.