Virtual Memory
Definition
Virtual memory is the use of secondary storage (typically an HDD or SSD) as a temporary extension of RAM, when physical RAM is full.
Key Fact
Virtual memory is used when the amount of RAM needed to hold all running programs and data exceeds the physical RAM available.
Why It’s Needed
Modern computers often have many programs open simultaneously (Multitasking and Scheduling). Each program requires space in RAM. When all RAM is occupied:
- Without virtual memory → the computer cannot open more programs
- With virtual memory → the OS moves inactive data to disk, freeing up RAM
How It Works
- The OS identifies data in RAM that has not been used recently
- That data is transferred to a reserved area of the hard disk (the virtual memory / page file / swap space)
- The RAM space freed up is now available for the active program
- When the data on disk is needed again, the OS swaps it back: , Some other inactive data is moved to disk , The required data is moved back into RAM
- This two-way swapping process is called swapping (or paging)
RAM Hard Disk
┌──────────────┐ ┌──────────────┐
│ Program A │ │ │
│ Program B │◄────▶│ Page File │
│ [FREE SPACE]│ │ (swap space) │
└──────────────┘ └──────────────┘
▲ swapping ▲
Effect on Performance
Performance Impact
Using virtual memory slows the computer down significantly.
Why? Secondary storage (HDD/SSD) has much slower access times than RAM:
- RAM access: ~nanoseconds
- HDD access: ~milliseconds (thousands of times slower)
The CPU must wait while data is swapped. Excessive use of virtual memory (called thrashing) can make a system feel unresponsive.
Solution: Add more physical RAM, this reduces or eliminates the need for virtual memory.
Summary
| Aspect | Detail |
|---|---|
| What it is | Secondary storage used as extra RAM |
| When used | When physical RAM is full |
| How | Inactive data is swapped from RAM to disk and back |
| Benefit | Allows more programs to run than RAM alone could support |
| Drawback | Significantly slower than real RAM |
| Fix | Install more physical RAM |
Exam Questions
Q: What is virtual memory?
Virtual memory is the use of secondary storage as additional primary memory when the computer has no more available RAM.
Q: How does virtual memory work?
When RAM is full, the OS moves inactive data from RAM to a reserved area on the hard disk, freeing up RAM for currently needed data. When the data on disk is needed again, another inactive block is swapped to disk to make room.
Q: Why does using virtual memory slow the computer down?
Because secondary storage devices have much slower access times than RAM. The CPU must wait while data is transferred between RAM and the disk.
Exam Tip
Don’t confuse virtual memory (disk used as RAM) with RAM itself. Virtual memory is a workaround, the real solution is to have more physical RAM.