Virtual memory is a technology embedded in most
personal computers that enables many of the
advanced operations that we are so accustomed to.
However, the term is only vaguely familiar to many people. When you paste text from your web browser into your
word processor, multiple applications are running simultaneously with the operating system (OS) to make it all happen. Virtual memory plays a key role in allowing those
applications to coexist with each other and with the OS.
and so that it will not be overwritten? There is also the
concern about system-wide fault tolerance. Even if not
malicious, programs may have bugs that cause them to
crash and write data to random memory locations. In
such an instance, one errant application could bring
down others or even crash the OS if it overwrites program
and data regions that belong to the OS kernel.
Multitasking operating systems execute multiple programs at the same time by assigning each program a
certain percentage of the microprocessor's time and then
periodically changing which instruction sequence is being
executed. This is accomplished by a periodic timer interrupt
that causes the OS kernel to save the state of the microprocessor's registers and then reload the registers with a
preserved state from a different program. Each program
runs for a while, is paused, and then execution resumes
without the program having any knowledge of being
paused. In this respect, the individual programs in a multi-tasking environment appear to have complete control over
the computer, despite sharing the resources with others.
Aside from fair access to microprocessor time, conflicts can arise between applications accidentally modifying portions of each other's memory — either program or
data. How does an application know where to locate its
data so that it will not disturb that of other applications
Virtual memory is a hardware enforced and software
configured mechanism that provides each application
with its own private memory space that it can use arbitrarily. This virtual memory space can be as large as the
microprocessor's addressing capability — a full 4 GB in
the case of a 32-bit microprocessor. Because each application has its own exclusive virtual memory space, it can
use any portion of that space that is not otherwise restricted by the kernel. Virtual memory frees the programmer
from having to worry about where other applications may
locate their instructions or data because applications cannot access the virtual memory spaces of others.
NUTS & VOLTS
Clearly, multiple programs cannot place different
data at the same address or each simultaneously occupy
the microprocessor's entire address space. The OS kernel
configures a hardware memory management unit (MMU)
to map each program's virtual addresses into unique physical addresses that correspond to actual main memory.
Each unique virtual memory space is broken into many
small pages that are often in the range of 2 KB to 16 KB
in size ( 4 KB is a common page size). The OS and MMU
refer to each virtual memory space with a process ID
(PID) field. Virtual memory is handled on a process basis
rather than an application basis because it is possible for
an application to consist of multiple semi-independent
FIGURE 1. 32-bit Virtual Memory Mapping
This material was originally published in Complete Digital Design:
A Comprehensive Guide to Digital Electronics by Mark Balch, ©2003
by The McGraw-Hill Companies. Reproduced with permission.