Memory Replacement Policies - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Memory Replacement Policies

Description:

Reference string: the memory reference sequence generated by a program. ... Eviction throwing something out. Pollution bringing in useless pages/lines ... – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 28
Provided by: csU70
Category:

less

Transcript and Presenter's Notes

Title: Memory Replacement Policies


1
Memory Replacement Policies
  • Stallings 8.1,8.2 (Ch22)
  • Lawrence Angrave

2
Demand Paging Example
VM
fault
ref
Load M
Page table
Free frame
3
Concepts this Lecture
  • Terminology
  • Demand Paging
  • Replacement Issues
  • Replacement Strategies

4
1 Terminology
  • Reference string the memory reference sequence
    generated by a program.
  • Paging moving pages to (from) disk
  • Optimal the best (theoretical) strategy
  • Eviction throwing something out
  • Pollution bringing in useless pages/lines

5
2 Demand Paging - Paging Policies
  • Fetch Strategies
  • When should a page be brought into primary (main)
    memory from secondary (disk) storage?
  • Placement Strategies
  • When a page is brought into primary storage,
    where is it to be put?
  • Replacement Strategies
  • Which page now in primary storage is to be
    removed from primary storage when some other page
    or segment is to be brought in and there is not
    enough room?

6
3 Replacement Issues
7
Page Replacement Algorithm (review)
  • find a free page frame
  • if free page frame use it
  • otherwise, select a page frame using the page
    replacement algorithm
  • write the selected page to the disk and update
    any necessary tables
  • find location of page on disk
  • read the requested page from the disk.
  • restart the user process.

8
Page Replacement Issues 1/2
  • if no frames are free, a disk read and write of
    page is required
  • if the page to be replaced has not been changed
    since it was read in, it can be discarded and
    does not need to be copied out to secondary
    storage.
  • read-only pages are never written but may be
    shared!

9
Page Replacement Issues 2/2
  • a dirty bit is set in the page table by hardware
    to indicate that the page has been modified.
  • need to minimize page faults.
  • reference string is the memory references
    generated by a program.

10
Replacement Strategies 4
11
Page Replacement Strategies 1/2
  • optimal
  • replace the page that will not be used again the
    farthest time in the future.
  • random
  • choose a page randomly
  • FIFO - first in first out
  • replace the page that has been in primary memory
    the longest

12
Page Replacement Strategies 2/2
  • LRU - least recently used
  • replace the page not used for the longest time
  • LFU - least frequently used
  • replace the page that is used least often
  • NUR - not used recently
  • an approximation to LRU
  • working set
  • keep in memory those pages that the process is
    actively using.

13
Principal of Optimality
  • provides a basis for comparison with other
    schemes.
  • is difficult to implement because of trying to
    predict the reference string for a program.
  • but sometimes compiler technology can help by
    providing hints.

14
Principal of Optimality
  • if the reference string can be predicted
    accurately, then don't use demand paging but
    should use pre-paging instead.
  • because this would allow paging activity of
    pages needed in the future to be overlapped with
    computation.

15
Optimal Example
12 references, 7 faults
16
FIFO
12 references, 9 faults
17
Paging Behavior with IncreasingNumber of Page
Frames
18
Belady's Anomaly (for FIFO)
As the number of page frames increase, so does
the fault rate.
12 references, 10 faults
19
LRU
12 references, 10 faults
20
Least Recently Used Issues
  • does not suffer from Belady's anomaly
  • use time
  • record time of reference with page table entry
  • use counter as clock
  • search for smallest time.
  • use stack
  • remove reference of page from stack (linked list)
  • push it on top of stack
  • both approaches require large processing
    overhead, more space, and hardware support.

21
LRU and Anomalies
Anomalies cannot occur, why?
12 references, 8 faults
22
NUR A LRU Approximation
  • additional reference bits
  • a register is kept per page
  • a one bit is set in the register if the page is
    referenced
  • the register is shifted by one after some time
    interval
  • 00110011 would be accessed more recently than
    00010111
  • the page with register holding the lowest number
    is the least recently used.
  • the value may not be unique. use fifo to resolve
    conflicts.

23
Second Chance
  • second chance algorithm uses a register size one
    a reference bit.
  • the page table entry has a reference bit
  • initially, the reference bit for a page is set to
    0
  • when a page is referenced, the page is set to 1
  • pages are kept in FIFO order using a circular
    list.
  • select head of FIFO

24
Second Chance
  • if page has reference bit set, reset bit and
    select next page in FIFO list.
  • keep processing until reach page with zero
    reference bit and page that one out.
  • system v, r4 uses a variant of second chance.

25
Second Chance Example
12 references, 9 faults
26
Page Classes
  • 1.(0,0) neither referenced nor dirtied
  • 2.(0,1) not referenced (recently) but dirtied
  • 3.(1,0) referenced but clean
  • 4.(1,1) referenced and dirtied
  • select a page from lowest class
  • if conflict, use random or FIFO.

27
Summary
  • Fetch, placement, page replacement.
  • Demand paging algorithm.
  • Simple page replacement policies.
  • Optimal
  • FIFO
  • LRU
  • NUR
  • Second chance, page classes
Write a Comment
User Comments (0)
About PowerShow.com