CS111 Lecture Note: Virtual Memory

Lecture date: Nov. 20, 2013. Note taken by Wentao Shang.

History of virtual memory

However, there is still a problem of THRASHING.

Another problem to solve: memory modularity

Bad memory access

Lots of unreliable processes with bad memory references. Typical errors include:

Possible solutions:

0. Don't do that! And fire the programmer who does that.

1. Turn every memory access into a system call.

2. Let compiler insert code around every access, checking that pointer is valid.

3. Use per-process base-bounds pair.

4. Use segmented memory.

Implementation of segmented virtual memory on x86

1. Single-level page table

2. Two-level page table

Pseudo C code for two-level memory lookup

unsigned pmap (unsigned va) // va: virtual address
{
  unsigned hi = va >> 22; // high order 10 bits
  unsigned med = (va >> 12) & ((1 << 10) - 1);
  unsigned *l1pt = asm ("%cr3", ...); // get location of l1 page table
  unsigned *l2pt = l1pt[hi] &~ ((1 << 12) - 1);
  if (l2pt == FAULT) return FAULT; // FAULT marks zero mem addr
  return l2pt[med] &~ ((1 << 12) -1);
}

Page faulting

"Free memory is wasted memory." -- by Linus Torvalds

Swap space on disk

malloc() revisited


Last modified: Fri Nov 22 13:33:49 PST 2013