Outline for 2/6/98

  • Last time: virtual memory issues

  • Questions from last time?

  • Administrative:

  • course evaluation today

  • pictures on class web page - if you like yours and want a bigger version, let me know.

  • Objective: Replacement algorithms

    Example Reference String

    0 { 1 2 { 2 3 4 5 15 5 20 5 6}m 2 6

    { 2 3 4 5 16 5 21 5 6}m 2 6

    { 2 3 4 5 17 5 22 5 6}m 2 6

    { 2 3 4 5 19 5 24 5 6}m 2 6 7 }n

    FIFO

  • No extra hardware assistance needed,
    No per-reference overhead (we have no information about actual access pattern)

  • At fault time: maintain a first-in first-out queue of pages resident in physical memory

  • Replace oldest resident page

  • Why it might make sense - straight-line code, sequential scans of data

  • Belady's anomaly - fault rate can increase with more memory

    LRU

  • At fault time: replace the resident page that was last used the longest time ago

  • Idea is to track the program's temporal locality

  • To implement exactly: we need to order the pages by time of most recent reference
    (per-reference information needed -> HW, too $$)

  • timestamp pages at each ref, stack operations at each ref

  • Stack algorithm - doesn't suffer from Belady's anomaly -- if i > j then set of pages with j frames is a subset of set of pages with i frames.

    Approximations to LRU

  • Implementable at reasonable cost

  • HW: usage bit for every PTE set on each reference.

  • We now know whether or not a page has been used since the last time the bits were cleared.

  • Algorithms differ on when & how that's done.

  • Unless it's every reference, there will be "ties"

    Approximating a Timestamp

  • Maintain a supplemental data structure
    (a counter) for each page

  • Periodically (on a regular timer interrupt) gather info from the usage bits and zero them.

    for each page i {if (usedi) counteri = 0; else counteri++;
    used
    i = 0;}

  • At fault time, replace page with largest counter value (time intervals since last use)

    Clock Algorithm

  • Also called Second Chance

  • Maintain a circular queue with a pointer to the next candidate (clock hand).

  • At fault time: scan around the clock, looking for page with usage bit of zero (that's your victim),
    clearing usage bits
    as they are passed.

    Practical Considerations

  • Dirty bit - modified pages require a writeback to secondary storage before frame is free to use again.

  • Variation on Clock tries to maintain a healthy pool of clean, free frames

  • on timer interrupt, scan for unused pages, move to free pool, initiate writeback on dirty pages

  • at fault time, if page is still in frame in pool, reclaim; else take free, clean frame.

    Working Set Model

  • Working set at time t is the set of pages referenced in the interval of time (t-w, t) where w is the working set window.

  • Implies per-reference information captured.

  • How to choose w?

  • Identifies the "active" pages. Any page that is resident in memory but not in any process's working set is a candidate for replacement.

  • Size of the working set can vary with locality changes

    WSClock

  • The implementable approximation

  • At fault time: scan usage bits of resident pages. For each page i

    {if (usedi) {time_of_refi = vtowner[i] /*virtual time of

    owning process*/; usedi = 0;}

    else if ( | vtowner[i] - time_of_refi | >= w ) replaceable; //else still in "working set"}

  • When scheduler preempts process: record the process`s virtual time in its PCB. Virtual time is the time that the process has actually been running, not including waiting times.