What is Virtual Memory?

As the name suggests, virtual memory (VM) creates the illusion of an unlimited amount of memory. It allows multiple processes with memory needs larger than the physical memory itself to run simultaneously on a processor. With virtual memory, a 16MB program can run on a 4MB system for example.

It's not uncommon to want to run multiple processes with sizes that are much larger than the memory available on that processor. But at any given time, only a portion of those programs are active, so main memory need not contain the entire collection of processes at all times. Processes that do not fit in physical memory are stored in a disk. Main memory can act as a "cache" containing the active portion of one program, leaving the others to reside on disk.

Figure 1. Memory hierarchy and corresponding access times.
Software developers are well aware of the memory hierarchy that consists of multiple levels of memory. The memory level closest to the CPU is the smallest and fastest. As the levels move away from the CPU they get bigger and slower (Figure 1).

The cost of each memory level varies significantly from one to the other as well. The cost per bit is a lot higher with the level closest to the CPU, and the cost decreases as you move away. One of the goals of VM is to provide the end-user with as much memory as possible at very little cost while still providing high access times. In reality, this is not always possible. Memory constraints continue to be a problem and software developers have always had to work around such issues.