Session 27
Monday, November 3

Virtual Memory

What it is Intended to Do

Virtual memory is intended to provide a process (and by extension a user) with the illusion that it can access as much memory as could possibly be accessed by the number of bits in an address (e.g., 32 bits) regardless of whether that much RAM is available or not and whether there are other processes active in RAM or not.

Why it is Cool

How it Works

When a process is started in by the OS, two parts are created:

  1. An execution image of the process that includes its code, its static variables, a stack, and a heap.  This execution image is kept by the OS on the hard drive in an area referred to as the "swap space," as sections of the execution image are brought into and out of RAM by the OS.
  2. A process control block that keeps track of the state of the process when it is interrupted so that it can be restarted later.

The OS must:

  1. construct and maintain data structures for each process that keep track of where the execution image of that process is in swap space
  2. bring in sections, called pages, of the execution image of a process from the swap space and put them in to RAM as they are needed
  3. construct and maintain data structures, called page tables, for each process to keep track of which pages of the execution image of that process is in RAM and where they are in RAM
  4. construct and maintain a data structure that keeps track of which frames of RAM (which have the same size as pages in the virtual execution image of the process) are in use, which process's pages are in those frames, and frames are free.
  5. put a value in a special page table register in the processor that is the address of the page table for the currently runing process.

The hardware must:

  1. resolve each virtual address that appears in the PC or as an operand address in an instruction to its real physical address in RAM by following the page tables pointed to by the page table register.