You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson explains virtual memory — what it is, why it is needed, and how it affects computer performance. This is part of OCR J277 Section 1.2.1.
Virtual memory is a section of secondary storage (typically the hard drive or SSD) that is used as an extension of RAM when physical RAM becomes full.
When all available RAM is in use, the operating system moves some data from RAM to a designated area on secondary storage called the page file (Windows) or swap space (Linux/macOS). This frees up RAM for the data that is currently needed.
Modern computers often run many programs simultaneously — a web browser, a word processor, a music player, and background services. Each program requires space in RAM.
If the total memory required by all running programs exceeds the amount of physical RAM, the computer would crash or be unable to open new programs — unless virtual memory is available.
Virtual memory acts as a safety net, allowing the computer to keep running even when RAM is full, by temporarily moving less-used data to secondary storage.
The process of using virtual memory involves swapping data between RAM and secondary storage:
The diagram below shows the swap flow between RAM and the page file on secondary storage:
graph LR
CPU["CPU"] -->|reads/writes| RAM["RAM<br/>(volatile, fast)"]
RAM -->|swap out<br/>least-recently-used pages| PF["Page File<br/>on HDD or SSD"]
PF -->|swap in<br/>on page fault| RAM
PT["Page Table"] -.->|maps virtual<br/>to physical| RAM
PT -.->|tracks paged-out| PF
Virtual memory divides memory into fixed-size blocks called pages:
| Concept | Description |
|---|---|
| Page | A fixed-size block of data (typically 4 KB) |
| Page table | A lookup table that maps virtual addresses to physical RAM addresses |
| Page file | The area on secondary storage used for virtual memory |
| Page fault | Occurs when the CPU tries to access a page that is not currently in RAM |
When a page fault occurs, the OS must:
If the computer relies too heavily on virtual memory, a problem called thrashing can occur:
| Memory Type | Typical Speed |
|---|---|
| RAM (DDR4) | ~25,000 MB/s |
| SSD | ~500-5,000 MB/s |
| HDD | ~100-200 MB/s |
Even the fastest SSD is significantly slower than RAM. An HDD used for virtual memory is hundreds of times slower than RAM, which is why thrashing causes such severe performance problems.
OCR Exam Tip: If asked why virtual memory slows down a computer, always mention that secondary storage is much slower than RAM, and that constant swapping (thrashing) causes delays.
| Advantages | Disadvantages |
|---|---|
| Allows the computer to run more programs than physical RAM alone would permit | Much slower than physical RAM |
| Prevents the system from crashing when RAM is full | Can cause thrashing if overused |
| Transparent to the user and applications | Uses secondary storage space |
| Managed automatically by the OS | Increases wear on storage (especially SSDs) |
| Solution | Explanation |
|---|---|
| Add more physical RAM | More RAM means less need for virtual memory |
| Close unnecessary programs | Frees up RAM space |
| Use an SSD instead of HDD | Faster secondary storage reduces swap delays |
| Reduce startup programs | Fewer programs loading at boot means more free RAM |
Key Vocabulary: virtual memory, page file, swap space, paging, page fault, thrashing, page table.
To see virtual memory in action, consider a budget laptop with only 4 GB of RAM (so about 3.5 GB usable after the OS) and an HDD for secondary storage. A student opens five applications in sequence and we will trace how the OS manages memory page by page.
Starting state. After the OS has loaded, RAM usage is 1.8 GB. Free RAM is 1.7 GB. The page file on the HDD is empty.
Step 1 — open Chrome with 8 tabs. Each tab consumes around 180 MB of RAM. Eight tabs = 1.44 GB. Total RAM usage rises to 3.24 GB; free RAM falls to 0.26 GB. No paging needed yet.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.