Page Replacement - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Page Replacement

Description:

Run the algorithm on a string of memory references (called reference string) and ... LRU Approximation Algorithms. Hardware support of reference bit ... – PowerPoint PPT presentation

Number of Views:85
Avg rating:3.0/5.0
Slides: 15
Provided by: marily214
Category:

less

Transcript and Presenter's Notes

Title: Page Replacement


1
Page Replacement
  • With demand paging, we can over-allocate memory
  • Consequence when a process generates a page
    fault, there may be no free frames in memory.
  • Possible solutions
  • Swap out a process, freeing all its frames
  • Page replacement
  • Select a victim frame.
  • Write the victim page to disk change the page
    table.
  • Read the desired page into the newly free frame
    change the page table.

2
Page Replacement
3
Page Replacement
  • Page replacement doubles page-fault service time.
  • Use modify bit (or dirty bit) to reduce overhead
  • Each page is associated with a modify bit.
  • Whenever a page is modified, the hardware set the
    modify bit for the page.
  • When a page is selected for replacement, write
    the page to disk only if its modify bit is set.

4
Page Replacement Algorithms
  • Want select an algorithm with the lowest
    page-fault rate.
  • How to evaluate an algorithm?
  • Run the algorithm on a string of memory
    references (called reference string) and compute
    the number of page faults.
  • Reference strings generated artificially or by
    tracing a given system.
  • Compressing a reference string
  • Consider only the page number
  • Reducing several references to the same page in a
    row to one reference
  • The number of page faults depends on the number
    of available frames
  • In general, the number of page faults drops as
    the number of frames increases

5
First-In-First-Out (FIFO) Algorithm
  • Replace the oldest page
  • Implementation use a FIFO queue to hold all
    pages in memory
  • Example reference string 1, 2, 3, 4, 1, 2, 5,
    1, 2, 3, 4, 5
  • 3 frames 9 page faults
  • 4 frames 10 page faults
  • Beladys anomaly page-fault rate may increase
    when the number of allocated frames increases

6
FIFO Illustrating Beladys Anamoly
7
Optimal Algorithm
  • Replace the page that will not be used for the
    longest period of time.
  • Minimize page fault rate
  • Never suffer from Beladys anomaly
  • Example reference string 1, 2, 3, 4, 1, 2, 5,
    1, 2, 3, 4, 5
  • 4 frames 6 page faults
  • The algorithm cant be implemented!
  • Used mainly for measuring how well an algorithm
    performs.

8
Least-Recently-Used (LRU) Algorithm
  • Replace the page that has not been used for the
    longest period of time
  • Never suffer from Beladys anomaly
  • Example reference string 1, 2, 3, 4, 1, 2, 5,
    1, 2, 3, 4, 5
  • 4 frames 8 faults

9
LRU Implementation
  • Counter implementation
  • Use a counter, incremented for every memory
    reference
  • Each page-table entry is associated with a
    time-of-use field every time a page is
    referenced, copy counter into time-of-use field
    of the page.
  • Replace page with the smallest time-of-use
  • Stack implementation
  • keep a stack of page numbers
  • Whenever a page is referenced, move it to the top
  • Replace page at the bottom of the stack
  • Best implemented by a doubly linked list

10
Stack Implementation
11
LRU Approximation Algorithms
  • Hardware support of reference bit
  • A reference bit (initialized to 0) is associated
    with each page-table entry
  • When a page is referenced, its reference bit is
    set to 1 by hardware

12
LRU Approximation Algorithms
  • Additional-Reference-Bits Algorithm
  • Each page has a ref bit and a 1-byte history
    field
  • A timer interrupts at regular intervals (say,
    every 100ms)
  • When the timer goes off
  • shift history bits right, discarding the
    lowest-order bit.
  • copy ref bit to highest-order bit of the history
    bits
  • clear ref bit
  • Replace the page with the smallest history value
  • Use FIFO to break ties when multiple pages have
    the same history value

13
LRU Approximation Algorithms
  • Second-Chance Algorithm
  • Use only reference bit, no history bits
  • Use FIFO replacement
  • If the selected pages reference bit is 0, then
    replace the page
  • If the selected pages reference bit is 1, then
    give it a second chance
  • reference bit set to 0
  • arrival time set to the current time
  • select the next FIFO page
  • Algorithm implementation use a circular queue
  • Second-chance algorithm degenerates to FIFO
    algorithm if all reference bits are set.

14
Second-Chance Page-Replacement Algorithm
Write a Comment
User Comments (0)
About PowerShow.com