0% found this document useful (0 votes)
9 views26 pages

NEW-OS-W6-L2-Page Replacement Algorithms

Uploaded by

kaiwenphuah171
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views26 pages

NEW-OS-W6-L2-Page Replacement Algorithms

Uploaded by

kaiwenphuah171
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 26

Operating Systems

AICT004-4-2 and Version VC1

Page Replacement Algorithm


Topic & Structure of the lesson

• Page replacement algorithms

• First In First Out

• Least Recently Used

• Optimal

AICT004-4-2-OS Operating Systems Page Replacement Algorithms


Slide 2 of 26
Learning Outcomes

• At the end of this lecture YOU should be able to:

- explain how page replacement algorithms work

- define the term thrashing

- explain circumstances that cause thrashing

AICT004-4-2-OS Operating Systems Page Replacement Algorithms


Slide 3 of 26
Key Terms you must be able to use

If you have mastered this topic, you should be able to use


the following terms correctly in your assignments and
exams:

• first in first out


• least recently used
• optimal
• belady’s anomaly
• thrashing

AICT004-4-2-OS Operating Systems Page Replacement Algorithms


Slide 4 of 26
First In First Out
• the simplest page replacement algorithm

• easily implemented

• algorithm uses the age of the page as the criteria to


perform page replacement

• the age of the page is the amount of time the page has
spent in memory

• oldest page is the victim

• all other pages are lined up in the order of highest time


spent in memory to be sacrificed
AICT004-4-2-OS Operating Systems Page Replacement Algorithms
Slide 5 of 26
First In First Out

• first three reference strings (7,0,1) causes page faults


and are brought into the empty frames

• next reference (2) replaces page (7) because (7) was


brought in first

• (0) is the next reference, it is already in memory, so


there is no page fault

• next reference (3) results in a page (0) being replaced

• next reference (0), results in a page fault, page (1)


replaces page (0)
AICT004-4-2-OS Operating Systems Page Replacement Algorithms
Slide 6 of 26
First In First Out

reference string

7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1

7 7 7 2 2 2 4 4 4 0 0 0 7 7 7
0 0 0 3 3 3 2 2 2 1 1 1 0 0
1 1 1 0 0 0 3 3 3 2 2 2 1

Number of Page Faults :15

Perform an analysis using First-In-First-Out (FIFO) Algorithm for


the following string of memory reference addresses. Assume that
there are three frames available within the memory for holding
AICT004-4-2-OS Operating Systems
pages.
Page Replacement Algorithms
Slide 7 of 26
Belady’s Anomaly

• FIFO suffers from Belady’s anomaly:

• BELADY was one of the pioneers of modern operating


systems who did extensive studies on page
replacement schemes

• on the basis of logical thinking, as the number of


memory frames are increased, the number of page faults
decreases

• but after conducting extensive experiments for certain


memory reference strings, as the number of memory
frames increased, the number of page faults increased
AICT004-4-2-OS Operating Systems Page Replacement Algorithms
Slide 8 of 26
Belady’s Anomaly

• BELADY’S observations contradicted the commonly


accepted dogma, his results are classified as BELADY’S
anomaly

AICT004-4-2-OS Operating Systems Page Replacement Algorithms


Slide 9 of 26
Belady’s Anomaly

16
14
12
number of page

10
faults

8
6
4
2

0 1 2 3 4 5 6 7
number of frames
page-fault curve for FIFO replacement on a reference string
AICT004-4-2-OS Operating Systems Page Replacement Algorithms
Slide 10 of 26
Optimal

• results from Belady’s anomaly resulted in a search for a


new algorithm

• Optimal

- has the lowest page fault for a fixed number of frames

- does not suffer from Belady’s anomaly

- replaces the page that will not be used for the longest
period of time

- is difficult to implement, requires future knowledge of the


reference string
AICT004-4-2-OS Operating Systems Page Replacement Algorithms
Slide 11 of 26
Optimal

• first 3 references would cause a page fault to fill in the


frames

• reference (2), page (2) replaces page (7) because

• page (7) will not be used until reference(18) page (0) will
be used at (5) and page (1) at (14)

• reference (3) replaces page (1)

• page (1) will be referenced at the last (3) references

AICT004-4-2-OS Operating Systems Page Replacement Algorithms


Slide 12 of 26
Optimal algorithm

reference string

7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1

7 7 7 2 2 2 2 2 7
0 0 0 0 4 0 0 0
1 1 3 3 3 1 1

Replace the page that will not be used for


Number of Page Faults: 9 the longest period of time

Perform an analysis using Optimal Algorithm for the following


string of memory reference addresses. Assume that there are
three frames available within the memory for holding pages.
AICT004-4-2-OS Operating Systems Page Replacement Algorithms
Slide 13 of 26
Least Recently Used

• associates each page with the time of when the page


was last used

• when a page needs to be replaced, the page that has


not been used the for the longest period will be chosen

• technique of looking backwards

AICT004-4-2-OS Operating Systems Page Replacement Algorithms


Slide 14 of 26
Least Recently Used
• reference to page (4), page (2) was used least recently

• recently used pages are (0) and before that (3)

• replaces page (2), not knowing that page (2) is about to


be used

• when a page fault occurs in page 2 least recently used


replaces page (3) since page (3) was least recently used

• hardware assistance to order the frames defined by the


time of last used

AICT004-4-2-OS Operating Systems Page Replacement Algorithms


Slide 15 of 26
Least Recently Used
reference string

7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1

7 7 7 2 2 4 4 4 0 1 1 1
0 0 0 0 0 0 3 3 3 0 0
1 1 3 3 2 2 2 2 2 7

Number of Page Faults: 12

Perform an analysis using least recently used algorithm for the


following string of memory reference addresses. Assume that
there are three frames available within the memory for holding
AICT004-4-2-OS Operating Systems
pages.
Page Replacement Algorithms
Slide 16 of 26
Random

• choose any page to replace at random

• assumes that the next page to be referenced is chosen


randomly

AICT004-4-2-OS Operating Systems Page Replacement Algorithms


Slide 17 of 26
Second Chance

• second chance is actually a FIFO replacement algorithm


with a small modification that causes it to be similar to
least recently used

• when a page is selected accordingly in a FIFO order, we


check the reference bit.

• if the reference bit is set, than we do not select that page


and look for another page to be selected

• also known as the clock algorithm, requires hardware


support to keep track of the reference bit

AICT004-4-2-OS Operating Systems Page Replacement Algorithms


Slide 18 of 26
Second Chance

• in the worst case, when all bits are set the pointer cycles
through all of the pages, giving each page a second
chance and clears all the bits

AICT004-4-2-OS Operating Systems Page Replacement Algorithms


Slide 19 of 26
Thrashing

• thrashing occurs:

- when high page replacement activity takes place

- when processes spend more time page replacing than


processing

• thrashing causes CPU utilization to drop

• as page fault increases, system throughput is reduced

AICT004-4-2-OS Operating Systems Page Replacement Algorithms


Slide 20 of 26
Thrashing

• a process is thrashing if it is spending more time paging


than executing
Utilization
CPU

AICT004-4-2-OS Operating Systems


Degree of multiprogramming
Page Replacement Algorithms
Slide 21 of 26
Quick Review Questions

• First in first out is associated with an anomaly, name


that anomaly?

• Name three page replacement algorithms

AICT004-4-2-OS Operating Systems Page Replacement Algorithms


Slide 22 of 26
Follow Up Assignment

• Explain Belady’s anomaly

• As a result of thrashing, what happens to CPU


utilization and system performance

AICT004-4-2-OS Operating Systems Page Replacement Algorithms


Slide 23 of 26
Summary of Main Teaching Points

• Page replacement algorithms are first in first out, optimal


and least recently used.

• First in first out replaces the oldest page.

• Optimal replaces the page that is least likely to be used.

• Least recently used replaces the page that has not


been used recently.

• Thrashing takes place when page replacement activities


occur more than process execution.

AICT004-4-2-OS Operating Systems Page Replacement Algorithms


Slide 24 of 26
Question and Answer Session

Q&A

AICT004-4-2-OS Operating Systems Page Replacement Algorithms


Slide 25 of 26
Next Session

Secondary Storage Disk Scheduling

AICT004-4-2-OS Operating Systems Page Replacement Algorithms


Slide 26 of 26

You might also like