Docsity

Page Replacement Algorithms in Operating Systems: FIFO, LRU, and Thrashing - Prof. Jeffrey, Study notes of Operating Systems

Partial preview of the text

Download Page Replacement Algorithms in Operating Systems: FIFO, LRU, and Thrashing - Prof. Jeffrey and more Study notes Operating Systems in PDF only on Docsity!

Announcements

z

Lecture provided by Bobby Bhattacharjee

Page Replacement Algorithms

z

FIFO

Replace the page that was brought in longest ago

However

-^

old pages may be great pages (frequently used)

-^

number of page faults may increase when one increases number ofpage frames (discouraging!)

  • called belady’s anomaly– 1,2,3,4,1,2,5,1,2,3,4,5 (consider 3 vs. 4 frames)

z

Optimal

Replace the page that will be used furthest in the future

Good algorithm(!) but requires knowledge of the future

With good compiler assistance, knowledge of the future issometimes possible

FIFO Example (3 frames)

  • Reference string: 1,2,3,4,1,2,5,1,2,3,4,

•^

access 1 - (1) fault

-^

access 2 - (1,2) fault

-^

access 3- (1,2,3) fault

-^

access 4 - (2,3,4) fault, replacement

-^

access 1 - (3,4,1) fault, replacement

-^

access 2 - (4,1,2) fault, replacement

-^

access 5 - (1,2,5) fault, replacement

-^

access 1- (1,2,5)

-^

access 2 - (1,2,5)

-^

access 3 - (2,5,3) fault, replacement

-^

access 4 - (5,3,4) fault, replacement

-^

access 5 - (5,3,4)

  • 9 page faults

LRU Example (3 frames)

  • Reference string: 1,2,3,4,1,2,5,1,2,3,4,

•^

access 1 - (1) fault

-^

access 2 - (1,2) fault

-^

access 3- (1,2,3) fault

-^

access 4 - (2,3,4) fault, replacement

-^

access 1 - (3,4,1) fault, replacement

-^

access 2 - (4,1,2) fault, replacement

-^

access 5 - (1,2,5) fault, replacement

-^

access 1- (2,5,1)

-^

access 2 - (5,1,2)

-^

access 3 - (1,2,3) fault, replacement

-^

access 4 - (2,3,4) fault, replacement

-^

access 5 - (3,4,5) fault, replacement

  • 10 page faults

FIFO Example (4 frames)

  • Reference string: 1,2,3,4,1,2,5,1,2,3,4,

•^

access 1 - (1)

fault

•^

access 2 - (1,2) fault

-^

access 3- (1,2,3) fault

-^

access 4 - (1,2,3,4) fault, replacement

-^

access 1 - (1,2,3,4)

-^

access 2 - (1,2,3,4)

-^

access 5 - (2,3,4,5) fault, replacement

-^

access 1- (3,4,5,1) fault, replacement

-^

access 2 - (4,5,1,2) fault, replacement

-^

access 3 - (5,1,2,3) fault, replacement

-^

access 4 - (1,2,3,4) fault, replacement

-^

access 5 - (2,3,4,5) fault, replacement

  • 10 Page faults

Thrashing

z

Virtual memory is not “free”

  • can allocate so much virtual memory that the system spends

all its time getting pages

  • the situation is called thrashing– need to select one or more processes to swap out

z

Swapping

  • write all of the memory of a process out to disk– don’t run the process for a period of time– part of medium term scheduling

z

How do we know when we are thrashing?

  • check CPU utilization?– check paging rate?– Answer: need to look at both
    • low CPU utilization plus high paging rate --> thrashing