Virtual Memory

Tom Kelliher, CS 240

Apr. 17, 2000

Administrivia

Announcements

Collect homework.

Assignment

New homework, due 4/26.

From Last Time

VM system support, VM performance, page fault sequence.

Outline

  1. Swap space policies.

  2. Replacement policies.

Coming Up

Placement policies, VM behavior (thrashing).

Virtual Memory

Swap Space Policies

  1. Copy image into swap at process start-up. Demand paging done from swap device. Wastes swap space, extra I/O, but swap device is faster than filesystem.

  2. Demand page from filesystem. Read-only pages are never swapped out, just overwritten and re-read from filesystem. Conserves swap space, uses slower filesystem.

  3. Demand page from filesystem, swap out to swap device. Only demanded pages are read from filesystem, only necessary pages are replaced to swap device.

Replacement Policies

  1. What happens if a page fault occurs and all frames are in use?

  2. Must select a victim frame:
    1. Page-out victim frame.

    2. Update victim process' page table.

    3. Page-in faulted page.

  3. How do we select the victim frame?

  4. Comparison criteria for replacement algorithms.

Reference Strings

  1. What is it?

  2. Where do I get one?

  3. What about redundancy?

FIFO Replacement

  1. In the set of candidate victim pages, select the ``oldest'' page.

  2. Example reference string: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1. Three frames allocated.

  3. Belady's anomaly:
    1. Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5.

    2. Three frames allocated.

    3. Four frames allocated.

  4. Stack property: Set of pages in memory with n frames allocated is a subset of set of pages in memory with n + 1 frames allocated.

Optimal Replacement

  1. Replace the page which won't be used for the longest time.

  2. Example reference string: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1. Three frames allocated.

  3. Implementation?

LRU Replacement

  1. Approximation to optimal: replace page which hasn't been used for the longest time.

  2. ``Reversal'' of optimal.

  3. Example reference string: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1. Three frames allocated.

  4. Implementation:
    1. Counters. Hardware support required

    2. Stack. Expensive.

    3. Reference bits concatenation as approximation to counter.

    4. Second chance (clock) algorithm: FIFO, but skip over page if reference bit set (reset reference bit).

Page Buffering Optimizations

  1. Keep a small pool of empty frames so paging-in can occur without waiting for victim page-out.

  2. When idle, write dirty pages out and clear dirty bit.

  3. Keep track of what's in free frames, so page-ins can possibly use an old, free frame.

LRU Implementation

  1. Maintain frame list as a ``stack.'' Implementation?

  2. Timestamp page table entry on each access. Implementation?

  3. Simulating the time stamp through recording and concatenation of reference bits.
    1. Implementation: system daemon and timer interrupt.

    2. How often to record?

    3. How many bits?

Second Chance FIFO

AKA clock algorithm.

  1. Maintain process' frame list in a circular queue.

  2. The ``victim'' pointer.

  3. Victim page referenced: skip over, resetting reference bit.

  4. All pages referenced: pure FIFO.

  5. Enhancement: examine (reference bit, dirty bit):
    1. Four combinations --- priorities?

    2. Possibly several passes through the queue.



Thomas P. Kelliher
Wed Apr 19 08:10:39 EDT 2000
Tom Kelliher