A technique that uses main memory as a “cache” for secondary
storage. Historically, there were two major
motivations for virtual memory: to allow efficient and safe sharing of memory
among multiple programs, and to remove the programming burdens of a small,
limited amount of main memory. Four decades after its invention, it’s the
former reason that reigns today.
Consider a collection of programs running at once
on a computer. The total memory required by all the programs may be much larger
than the amount of main memory available on the computer, but only a fraction
of this memory is actively being used at any point in time. Main memory need
contain only the active portions of the many programs, just as a cache contains
only the active portion of one program. Thus, the principle of locality enables
virtual memory as well as caches, and virtual memory allows us to efficiently
share the processor as well as the main memory. Of course, to allow multiple
programs to share the same memory, we must be able to protect the programs from
each other, ensuring that a program can only read and write the portions of
main memory that have been assigned to it.
We cannot know which programs will share the memory
with other programs when we compile them. In fact, the programs sharing the
memory change dynamically while the programs are running. Because of this
dynamic interaction, we would like to compile each program into its own address
space— separate range of memory locations accessible only to this program.
Virtual memory implements the translation of a program’s address space to physical addresses. This translation process enforces protection of a program’s address
space from other programs.
The second motivation for virtual memory is to
allow a single user program to exceed the size of primary memory. Formerly, if
a program became too large for memory, it was up to the programmer to make it
fit. Programmers divided programs into pieces and then identified the pieces
that were mutually exclusive. These overlays were loaded or unloaded
under user program control during execution, with the programmer ensuring that
the program never tried to access an overlay that was not loaded and that the
overlays loaded never exceeded the total size of the memory. Overlays were
traditionally organized as modules, each containing both code and data. Calls
between procedures in different modules would lead to overlaying of one module
with another. As you can well imagine, this responsibility was a substantial
burden on programmers. Virtual memory, which was invented to relieve
programmers of this difficulty, automatically manages the two levels of the
memory hierarchy represented by main memory (sometimes called physical
memory to distinguish it from virtual memory) and secondary storage.
Although the concepts at work in virtual memory and
in caches are the same, their differing historical roots have led to the use of
different terminology. A virtual memory block is called a page, and a
virtual memory miss is called a page
fault. With virtual memory, the
processor produces a virtual address, which is translated
by a combination of hardware and software to a physical address, which
in turn can be used to access main memory. Figure below shows the virtually
addressed memory with pages mapped to main memory. This process is called address
mapping or address translation.
Today, the two memory hierarchy levels controlled by virtual memory are DRAMs.
Physical address: An address in main memory.
Protection: A set of mechanisms for ensuring that multiple processes
sharing the processor, memory, or I/O devices cannot interfere, intentionally
or unintentionally, with one another by reading or writing each other’s data.
These mechanisms also isolate the operating system from a user process.
Page fault: An event that occurs when an accessed page is not present in main
memory.
Virtual address: An address that corresponds to a location in virtual
space and is translated by address mapping to a physical address when memory is
accessed.
Address translation: Also
called address mapping. The process by which a virtual address is mapped to an
address used to access memory.
In virtual memory, blocks of memory
(called pages) are mapped from one set of addresses (called virtual
addresses) to another set (called physical addresses).