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

An overview of page replacement algorithms, specifically fifo (first in, first out) and lru (least recently used), in the context of operating systems. The advantages and disadvantages of each algorithm, as well as the concept of thrashing and swapping. Real-life examples are given to illustrate the concepts.

Typology: Study notes

Pre 2010

Uploaded on 02/13/2009

koofers-user-90q-2
koofers-user-90q-2 🇺🇸

9 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
CMSC 412 – S02 (lect 13)
Announcements
zLecture provided by Bobby Bhattacharjee
pf3
pf4
pf5
pf8

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