When physical RAM fills up, the operating system uses an area of secondary storage as if it were extra RAM. This is called virtual memory (also 'swap' on Linux, 'page file' on Windows).
How it works.
- The OS divides RAM and the swap area into fixed-size pages.
- When RAM is full and a new program needs space, the OS chooses an inactive page and writes it out to the swap area.
- The freed-up RAM is given to the new program.
- If the swapped-out page is needed again later, it's read back from disk into RAM (and another page may be evicted in turn).
Why use it. Lets you run more programs / larger programs than physical RAM alone would allow. The OS provides each program with the illusion of a large, continuous memory space — even on machines with very limited RAM.
Trade-off. Secondary storage is HUNDREDS of times slower than RAM. If virtual memory is being used heavily, the system slows dramatically — this is called thrashing. The fix: more physical RAM.
Cambridge tip. Mark scheme rewards the two halves: WHAT it is (using disk as if it were RAM) and WHY (so more programs can run when RAM is full). Don't forget the cost (slower than RAM).