Lecture 20 Virtual Memory - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Lecture 20 Virtual Memory

Description:

Lecture 20 Virtual Memory Page-Replacement Algorithms – PowerPoint PPT presentation

Number of Views:77
Avg rating:3.0/5.0
Slides: 15
Provided by: eam80
Category:

less

Transcript and Presenter's Notes

Title: Lecture 20 Virtual Memory


1
Lecture 20Virtual Memory
  • Page-Replacement Algorithms

2
Optimal Policy
  • Replace page that will not be used for longest
    period of time.
  • How do you know this?
  • Is impossible!, the OS does not know future
    events
  • Why do we present it?
  • Used for measuring how well your algorithm
    performs.

3
Optimal Policy
4
First-in, First Out(FIFO)
  • FIFO policy treats the page frames allocated to a
    process as a circular buffer, and pages are
    removed in round-robin style.
  • A page fetched into memory a long time ago may
    have now fallen out of use
  • It requires a pointer that circles through the
    page frames of the process
  • It is simple but not optimal.

5
First-in, First Out(FIFO)
6
Least Recently Used(LRU)
  • Replaces the page in memory that has not been
    referenced for the longest time.
  • By the principle of locality, this should be the
    page least likely to be referenced in the near
    future.
  • LRU policy does nearly as well as the optimal
    policy
  • Problem Difficulty in implementation

7
Least Recently Used(LRU)
  • Counter implementation
  • Every page entry has a counter every time page
    is referenced through this entry, copy the clock
    into the counter.
  • When a page needs to be changed, look at the
    counters to determine which are to change.
  • Problem Tremendous overhead (even if the
    hardware would support this scheme)

8
Least Recently Used(LRU)
  • Stack implementation keep a stack of page
    numbers in a double link form
  • Page referenced
  • move it to the top
  • requires 6 pointers to be changed (entries must
    be moved even from the middle of the stack)
  • No search for replacement

9
Least Recently Used(LRU)
10
LRU Approximation AlgorithmsOne bit Hardware
support
  • Initially, all bits are cleared (to 0) by the OS
  • As a user process executes, the bit associated
    with each page referenced is set (to 1) by the
    hardware
  • After some time, we can determine which pages
    have been used and which have not been used by
    examining the reference bits

11
LRU Approximation AlgorithmsAdditional-Reference-
bits Hardware support
  • We can gain additional ordering information by
    recording the reference bits at regular intervals
  • We can keep an 8-bit byte for each page in a
    table in memory
  • At regular intervals a timer interrupt transfers
    control to the OS
  • The OS shifts the reference bit for each page
    into the high-order bit of its 8-bit byte,
    shifting the other bits right 1 bit, discarding
    the low-order bit
  • The page with the lowest number is the LRU page
  • Notice that the numbers are not guaranteed to be
    unique

12
LRU Approximation AlgorithmsSecond-Chance
Algorithm
  • Is a FIFO replacement algorithm
  • When a page is first loaded in memory, the use
    bit is set to 0
  • When the page is referenced, the use bit is set
    to 1
  • When a page is selected
  • If its reference bit 0 then we replace this
    page
  • If its reference bit 1 then move to to select
    the next FIFO page
  • Thus, a page that is given a second chance will
    not replaced until all the other pages are
    replaced (or given second chances)

13
Clock Policy
State of buffer just prior to a page replacement
14
Clock Policy
Write a Comment
User Comments (0)
About PowerShow.com