What is virtual memory?
RAM (Random Access Memory) holds the data and instructions currently needed by running programs. However, RAM has a limited capacity. If the computer needs to keep more information available than can fit in physical RAM, the operating system can use part of a secondary storage device as virtual memory.
Cambridge syllabus focus
Topic 3.8: understand the purpose of virtual memory, why it is needed and how using secondary storage instead of RAM affects computer performance.
Why does a computer need virtual memory?
Imagine a student has a web browser, a presentation, an image editor and several documents open. Each program needs memory. If the working data cannot all fit into physical RAM, the operating system can move less-needed pages of memory to a reserved area on an SSD or HDD, freeing RAM for other data.
Check your understanding 1
Is virtual memory the same thing as installing more RAM?
Reveal answer
No. Virtual memory uses secondary storage and is slower than physical RAM. Adding RAM increases the amount of fast physical memory available.
How does virtual memory work?
Modern operating systems commonly manage memory in fixed-size blocks called pages. When a page that a program needs is not in RAM, a page fault occurs and the operating system retrieves it from secondary storage. If RAM has no suitable free space, another page may be moved out first.
- A program tries to access information.
- The required page is not currently in RAM.
- The operating system locates that page in secondary storage.
- Space is made in RAM if needed, possibly by moving another page out.
- The required page is loaded into RAM, and execution continues.
Worked example β too many applications open
A laptop has 8 GB of physical RAM. Its running applications and operating system need more memory than can comfortably remain in RAM. The operating system may move less-active memory pages to its virtual-memory area. When the user returns to an application, the required pages may need to be loaded back into RAM.
Result: the applications may remain usable, but switching between them can become noticeably slower because secondary storage takes longer to access.
Check your understanding 2
Why might returning to a background application take longer?
Reveal answer
Some of its pages may have been moved to secondary storage. They must be loaded back into RAM before the program can use them.
Why does virtual memory affect performance?
RAM is designed for fast access. Even an SSD is much slower for memory access than RAM, and an HDD is generally slower still. Repeatedly moving pages between RAM and storage creates extra work and delays. When a computer spends too much time moving pages rather than running programs, this is called thrashing.
| Feature | Physical RAM | Virtual-memory storage area |
|---|---|---|
| Location | RAM modules | Part of SSD or HDD |
| Speed | Very fast | Slower than RAM |
| Purpose | Holds actively used data and instructions | Holds pages not currently resident in RAM |
| Effect on performance | Supports rapid access | Frequent transfers can cause delays |
Does virtual memory make a computer faster?
Not inherently. Virtual memory can let programs continue running when physical RAM is insufficient, but it cannot provide the same access speed as RAM. Increasing physical RAM may reduce the need for swapping, depending on the workload.
Common Cambridge exam mistakes
It uses an area of secondary storage, managed by the operating system.
It helps manage memory shortages, but frequent transfers to storage can slow performance.
Only selected pages may be moved, and the backing storage can be an SSD or HDD.
The amount of physical RAM remains unchanged.
Original FutureLogic exam-style practice
These are original teaching questions, not official Cambridge examination questions. Suggested marks are indicative.
Question 1 β 2 marks
Define virtual memory.
Reveal model answer
Virtual memory uses an area of secondary storage (1) to hold data or instructions when insufficient physical RAM is available (1).
Question 2 β 3 marks
Explain why a computer may use virtual memory when several applications are open.
Reveal model answer
The applications require more memory than the available RAM can hold (1). The operating system moves less-needed pages to secondary storage (1), freeing space in RAM for currently needed data (1).
Question 3 β 3 marks
Explain why using virtual memory can reduce computer performance.
Reveal model answer
Secondary storage is slower to access than RAM (1). Pages must be transferred between storage and RAM (1), which introduces delays when the processor needs that data (1).
Question 4 β 2 marks
A student says, βVirtual memory is the same as adding more RAM.β Explain why this is incorrect.
Reveal model answer
Virtual memory uses secondary storage rather than installing additional physical RAM (1). Secondary storage is slower than RAM (1).
Quick quiz
- What does RAM stand for?
- When might virtual memory be needed?
- Where is virtual memory stored?
- What manages the movement of pages?
- Why can frequent paging cause delays?
- Does virtual memory increase installed RAM?
Quiz answers
Reveal all answers
- Random Access Memory.
- When available physical RAM is insufficient.
- In an area of secondary storage, such as an SSD or HDD.
- The operating system.
- Storage is slower than RAM, and transfers take time.
- No.
Final summary
RAM
Fast, limited physical memory.
Virtual memory
Uses secondary storage to hold pages.
Operating system
Manages page movement.
Performance
Frequent transfers can cause delays.