SlideShare a Scribd company logo
Page Replacement Algorithms
FIFO, NRU, LRU, NFU...
Index
1. Paging
2. Page Replacement
3. Algorithms
4. Conclusion
5. References
Topic
S. No.
a. Optimal
b. FIFO
c. NFU
d. NRU
e. LRU
f. Second Chance
g. CLOCK
h. Random
i. Working Set
i
Plan of Action
• What is paging?
• What is page replacement?
• What are the types of page replacement?
• Why we need a page replacement algorithm?
• What are the algorithms?
What is Paging?
• The OS divides virtual memory and the main
memory into units, called pages.
• Each used page can be either in secondary
memory or in a page frame in main memory.
• A frame does not have to comprise a single
physically contiguous region in secondary
storage.
What is page replacement?
• When memory located in secondary memory is
needed, it can be retrieved back to main memory.
• Process of storing data from main memory to
secondary memory ->swapping out
• Retrieving data back to main memory ->swapping
in
Fig: Page Replacement
What are Page Replacement
Algorithms?
• Deals with which pages need to be swapped out
and which are the ones that need to be swapped
in
• The efficiency lies in the least time that is wasted
for a page to be paged in
Types
• Local Page Replacement Strategy
• Global Page Replacement Strategy
Why we need a page replacement
algorithm?
• The main goal of page replacement algorithms is
to provide lowest page fault rate.
START
Send Page
request
Page found?
yes
no
HIT
FAULT
STOP
Fetch page
No. of Page Faults Vs No. of Frames
Algorithms
• First In First Out
• Optimal Replacement
• Not Recently Used
• Second Chance
• CLOCK
• Not Frequently Used
• Least Recently Used
• Random Replacement
• Working Set Replacement
First-In First-Out (FIFO)
• Pages in main memory are kept in a list
• Newest page is in head and the oldest in tail
• It does not take advantage of page access
patterns or frequency
Fig: FIFO
FIFO Example
Oldest
Hit Hit Hit
Newest
Fig: FIFO example
Optimal Replacement (OPT)
• When the memory is full, evict a page that will
be unreferenced for the longest time
• The OS keeps track of all pages referenced by the
program
• Only if the program's memory reference pattern
is relatively consistent
OPTIMAL Example
Referenced last
Hit Hit Hit
Hit Hit Hit
Fig: OPTIMAL example
Not Recently Used (NRU)
• It favours keeping pages in memory that have
been recently used.
• The OS divides the pages into four classes based
on usage during the last clock tick:
 3. Referenced, modified
 2. Referenced, not modified
 1. Not referenced, modified
 0. Not referenced, not modified
NRU
• Pick a random page from the lowest category for
removal
• i.e. the not referenced, not modified page
NRU Example
Fig: NRU example
Recently
referenced
Hit
Hit Hit Hit Hit Hit
Second Chance
• Modified version of FIFO
• Instead of swapping out the last page, the
referenced bit is checked
• Gives every page a "second-chance"
Fig: Second Chance
Clock
• Modified version of FIFO
• The set of frame candidates for replacement is
considered as a circular buffer.
Fig: CLOCK
Least Recently Used (LRU)
• It swaps the pages that have been used the least
over a period of time.
• It is free from Belady’s anomaly.
LRU Example
Recently
referenced
Hit
Hit Hit Hit Hit Hit
Fig: LRU example
Not frequently used (NFU)
• This page replacement algorithm requires a
counter
• The counters keep track of how frequently a
page has been used
• The page with the lowest counter can be
swapped out
reference sequence : 3 2 3 0 8 4 2 5 0 9 8 3 2
P U 3 P U 2 P U 3 P U 0 P U 8 P U 4
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| | 0 |* | 3 | 1 | | 3 | 1 | | 3 | 1 | | 3 | 1 | | 3 | 1 |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| | 0 | | | 0 |* | 2 | 1 | | 2 | 1 | | 2 | 1 | | 2 | 1 |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| | 0 | | | 0 | | | 0 |* | | 0 |* | 0 | 1 | | 0 | 1 |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| | 0 | | | 0 | | | 0 | | | 0 | | | 0 |* | 8 | 1 |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| | 0 | | | 0 | | | 0 | | | 0 | | | 0 | | | 0 |*
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+----
P U 2 P U 5 P U 0 P U 9 P U 8 P U 3
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| 3 | 1 |* | 3 | 1 |* | 5 | 1 | | 5 | 1 | | 5 | 1 | | 5 | 1 |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| 2 | 1 | | 2 | 1 | | 2 | 0 |* | 2 | 0 |* | 9 | 1 | | 9 | 1 |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| 0 | 1 | | 0 | 1 | | 0 | 0 | | 0 | 1 | | 0 | 1 |* | 0 | 1 |*
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| 8 | 1 | | 8 | 1 | | 8 | 0 | | 8 | 0 | | 8 | 0 | | 8 | 1 |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+
| 4 | 1 | | 4 | 1 | | 4 | 0 | | 4 | 0 | | 4 | 0 | | 4 | 0 |
+---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+----
P U 2 P U
+---+---+ +---+---+ * = indicates the pointer which identifies the next location
| 5 | 1 |* | 5 | 0 | to scan P = page# stored in that frame U = used flag
| 9 | 1 | | 9 | 0 | 0 = not used recently 1 = referenced recently
+---+---+ +---+---+
| 0 | 0 | | 2 | 1 |
+---+---+ +---+---+
| 8 | 0 | | 8 | 0 |*
+---+---+ +---+---+
| 3 | 1 | | 3 | 1 |
+---+---+ +---+---+
Fig: NFU example
Random
• This algorithm replaces a random page in
memory.
• It fares better than FIFO.
Working set page replacement
• The set of pages that a process is currently using
is called the working set.
• The working set algorithm is based on
determining a working set and evicting any page
that is not in the current working set upon a
page fault.
pagereplacementalgorithmsa010a011-140520095310-phpapp01.pdf
Conclusion
Algorithm Comment
• FIFO
• OPTIMAL
• LRU
• NRU
• NFU
• Second Chance
• CLOCK
• Might throw out important
pages
• Not implementable
• Excellent but difficult to
implement
• Crude approximation of LRU
• Crude approximation of LRU
• Big improvement over FIFO
• Realistic
References
• Web Links
 www.wikipedia.com
 www.youtube.com
 www.vbForum.com
• Papers
 Operating System Page Replacement Algorithms by
A. Frank C. Wersberg
• Books
 Computer Organization & Architecture by William
Stallings
Thank You

More Related Content

PDF
Percona live-2012-optimizer-tuning
Sergey Petrunya
 
PPT
15 protips for mysql users pfz
Joshua Thijssen
 
PDF
Using Optimizer Hints to Improve MySQL Query Performance
oysteing
 
PDF
Window functions in MariaDB 10.2
Sergey Petrunya
 
PDF
pg_proctab: Accessing System Stats in PostgreSQL
Command Prompt., Inc
 
PDF
pg_proctab: Accessing System Stats in PostgreSQL
Mark Wong
 
PPTX
Computer architecture page replacement algorithms
Mazin Alwaaly
 
PPTX
Virtual memory and page replacement algorithm
Muhammad Mansoor Ul Haq
 
Percona live-2012-optimizer-tuning
Sergey Petrunya
 
15 protips for mysql users pfz
Joshua Thijssen
 
Using Optimizer Hints to Improve MySQL Query Performance
oysteing
 
Window functions in MariaDB 10.2
Sergey Petrunya
 
pg_proctab: Accessing System Stats in PostgreSQL
Command Prompt., Inc
 
pg_proctab: Accessing System Stats in PostgreSQL
Mark Wong
 
Computer architecture page replacement algorithms
Mazin Alwaaly
 
Virtual memory and page replacement algorithm
Muhammad Mansoor Ul Haq
 

Similar to pagereplacementalgorithmsa010a011-140520095310-phpapp01.pdf (20)

KEY
Perf Tuning Short
Ligaya Turmelle
 
PDF
Highload++2014: 1Hippeus - zerocopy messaging in the spirit of Sparta!
Leonid Yuriev
 
PPT
Explain about replacement algorithms from these slides
ssusera979f41
 
PPT
Replacement.ppt operating system in BCA cu
PankajKumar790026
 
PDF
Need for Speed: MySQL Indexing
MYXPLAIN
 
PDF
#Cashtag
Shafi Bashar
 
PDF
Hashtag cashtagfinal_1
Shafi Bashar
 
PPT
4. Data Manipulation.ppt
KISHOYIANKISH
 
PDF
MeetBSD2014 Performance Analysis
Brendan Gregg
 
PDF
1Hippeus - zerocopy messaging по законам Спарты, Леонид Юрьев (ПЕТЕР-СЕРВИС)
Ontico
 
PDF
Linux Systems Performance 2016
Brendan Gregg
 
DOCX
Homework Assignment 3 Chapter 3 St. Clair & Visick, Putting you.docx
fideladallimore
 
PDF
Performance Enhancements In Postgre Sql 8.4
HighLoad2009
 
PDF
忙しい人のためのSphinx 入門 demo
Fumihito Yokoyama
 
PDF
Routing in Fat Trees (RIFT) Open Source Update at IETF-108
Bruno Rijsman
 
PDF
ANALYZE for executable statements - a new way to do optimizer troubleshooting...
Sergey Petrunya
 
PDF
How to use histograms to get better performance
MariaDB plc
 
PDF
Using histograms to get better performance
Sergey Petrunya
 
DOCX
Subquery factoring for FTS
Heribertus Bramundito
 
PDF
Workshop 20140522 BigQuery Implementation
Simon Su
 
Perf Tuning Short
Ligaya Turmelle
 
Highload++2014: 1Hippeus - zerocopy messaging in the spirit of Sparta!
Leonid Yuriev
 
Explain about replacement algorithms from these slides
ssusera979f41
 
Replacement.ppt operating system in BCA cu
PankajKumar790026
 
Need for Speed: MySQL Indexing
MYXPLAIN
 
#Cashtag
Shafi Bashar
 
Hashtag cashtagfinal_1
Shafi Bashar
 
4. Data Manipulation.ppt
KISHOYIANKISH
 
MeetBSD2014 Performance Analysis
Brendan Gregg
 
1Hippeus - zerocopy messaging по законам Спарты, Леонид Юрьев (ПЕТЕР-СЕРВИС)
Ontico
 
Linux Systems Performance 2016
Brendan Gregg
 
Homework Assignment 3 Chapter 3 St. Clair & Visick, Putting you.docx
fideladallimore
 
Performance Enhancements In Postgre Sql 8.4
HighLoad2009
 
忙しい人のためのSphinx 入門 demo
Fumihito Yokoyama
 
Routing in Fat Trees (RIFT) Open Source Update at IETF-108
Bruno Rijsman
 
ANALYZE for executable statements - a new way to do optimizer troubleshooting...
Sergey Petrunya
 
How to use histograms to get better performance
MariaDB plc
 
Using histograms to get better performance
Sergey Petrunya
 
Subquery factoring for FTS
Heribertus Bramundito
 
Workshop 20140522 BigQuery Implementation
Simon Su
 

Recently uploaded (20)

PPTX
Top 10 Social Media Strategies to Boost Your Digital Marketing in 2024
hrithiksrivastava683
 
PDF
A Digital Marketing Dream Team: Web, SEO & Design in PH
Jomer Gregorio
 
PDF
Owning the Outcome When You Don’t Own the Click: A New Look at Zero-Click Mar...
DigiMarCon - Digital Marketing, Media and Advertising Conferences & Exhibitions
 
PDF
Master Marketing Fundamentals: Principles, Psychology & Strategy (Day 1) | Th...
Dipendra Poudel | The Digital Dipendra
 
PDF
Unfiltered. Real. Relatable. Rich Vibes Publication on Medium
Rich Vibes Publication
 
PDF
AI, Algorithms & Authority: Building Magnetic Brands in 2025's Digital Battle...
DigiMarCon - Digital Marketing, Media and Advertising Conferences & Exhibitions
 
PDF
AI in Marketing - From Imagination to Execution - Aarshiya Khandelwal
aarshiyakhandelwal1
 
PDF
GBS Company Profile || Trending Branding
Pratibha Singh
 
PPTX
Empowering Startups with Digital at Ashesi
Eli Daniel-Wilson
 
PDF
Multi-Platform Search is the Future of SEO: How to Capture Demand Beyond Goog...
DigiMarCon - Digital Marketing, Media and Advertising Conferences & Exhibitions
 
PDF
How Healthcare Advertising Agencies in Mumbai Use Digital To.pdf
matrix bricks infotech
 
PDF
How AI is Reshaping SEO: Trends, Predictions, and Opportunities for Marketers
Fractl - Content Marketing Agency
 
PDF
Hit Play, Then Pause: Reframing Entertainment for Resilience SXSW 2026 Propos...
morgan212401
 
PDF
Intent Based vs Demand Gen - Duda Webinar.pdf
Anton Shulke
 
PPTX
What Branding looks like, by: Cayancela Sánchez Jairo
Jairo Cayancela Sánchez
 
PDF
Becoming a Better You: How to Discover a Better Version of Yourself - Jamie T...
DigiMarCon - Digital Marketing, Media and Advertising Conferences & Exhibitions
 
PPTX
The Ultimate Social Media Guide for Marketers and Business Owners
hrithiksrivastava683
 
PPTX
How Digital Marketing Transformed Local Businesses in India
GTB Infotech
 
PDF
AI & Automation: The Future of Marketing or the End of Creativity - Brian Fle...
DigiMarCon - Digital Marketing, Media and Advertising Conferences & Exhibitions
 
PDF
Emotional Intelligence in AI: The New Marketing Superpower - Jennifer Jones-M...
DigiMarCon - Digital Marketing, Media and Advertising Conferences & Exhibitions
 
Top 10 Social Media Strategies to Boost Your Digital Marketing in 2024
hrithiksrivastava683
 
A Digital Marketing Dream Team: Web, SEO & Design in PH
Jomer Gregorio
 
Owning the Outcome When You Don’t Own the Click: A New Look at Zero-Click Mar...
DigiMarCon - Digital Marketing, Media and Advertising Conferences & Exhibitions
 
Master Marketing Fundamentals: Principles, Psychology & Strategy (Day 1) | Th...
Dipendra Poudel | The Digital Dipendra
 
Unfiltered. Real. Relatable. Rich Vibes Publication on Medium
Rich Vibes Publication
 
AI, Algorithms & Authority: Building Magnetic Brands in 2025's Digital Battle...
DigiMarCon - Digital Marketing, Media and Advertising Conferences & Exhibitions
 
AI in Marketing - From Imagination to Execution - Aarshiya Khandelwal
aarshiyakhandelwal1
 
GBS Company Profile || Trending Branding
Pratibha Singh
 
Empowering Startups with Digital at Ashesi
Eli Daniel-Wilson
 
Multi-Platform Search is the Future of SEO: How to Capture Demand Beyond Goog...
DigiMarCon - Digital Marketing, Media and Advertising Conferences & Exhibitions
 
How Healthcare Advertising Agencies in Mumbai Use Digital To.pdf
matrix bricks infotech
 
How AI is Reshaping SEO: Trends, Predictions, and Opportunities for Marketers
Fractl - Content Marketing Agency
 
Hit Play, Then Pause: Reframing Entertainment for Resilience SXSW 2026 Propos...
morgan212401
 
Intent Based vs Demand Gen - Duda Webinar.pdf
Anton Shulke
 
What Branding looks like, by: Cayancela Sánchez Jairo
Jairo Cayancela Sánchez
 
Becoming a Better You: How to Discover a Better Version of Yourself - Jamie T...
DigiMarCon - Digital Marketing, Media and Advertising Conferences & Exhibitions
 
The Ultimate Social Media Guide for Marketers and Business Owners
hrithiksrivastava683
 
How Digital Marketing Transformed Local Businesses in India
GTB Infotech
 
AI & Automation: The Future of Marketing or the End of Creativity - Brian Fle...
DigiMarCon - Digital Marketing, Media and Advertising Conferences & Exhibitions
 
Emotional Intelligence in AI: The New Marketing Superpower - Jennifer Jones-M...
DigiMarCon - Digital Marketing, Media and Advertising Conferences & Exhibitions
 

pagereplacementalgorithmsa010a011-140520095310-phpapp01.pdf

  • 2. Index 1. Paging 2. Page Replacement 3. Algorithms 4. Conclusion 5. References Topic S. No. a. Optimal b. FIFO c. NFU d. NRU e. LRU f. Second Chance g. CLOCK h. Random i. Working Set i
  • 3. Plan of Action • What is paging? • What is page replacement? • What are the types of page replacement? • Why we need a page replacement algorithm? • What are the algorithms?
  • 4. What is Paging? • The OS divides virtual memory and the main memory into units, called pages. • Each used page can be either in secondary memory or in a page frame in main memory. • A frame does not have to comprise a single physically contiguous region in secondary storage.
  • 5. What is page replacement? • When memory located in secondary memory is needed, it can be retrieved back to main memory. • Process of storing data from main memory to secondary memory ->swapping out • Retrieving data back to main memory ->swapping in
  • 7. What are Page Replacement Algorithms? • Deals with which pages need to be swapped out and which are the ones that need to be swapped in • The efficiency lies in the least time that is wasted for a page to be paged in
  • 8. Types • Local Page Replacement Strategy • Global Page Replacement Strategy
  • 9. Why we need a page replacement algorithm? • The main goal of page replacement algorithms is to provide lowest page fault rate.
  • 11. No. of Page Faults Vs No. of Frames
  • 12. Algorithms • First In First Out • Optimal Replacement • Not Recently Used • Second Chance • CLOCK • Not Frequently Used • Least Recently Used • Random Replacement • Working Set Replacement
  • 13. First-In First-Out (FIFO) • Pages in main memory are kept in a list • Newest page is in head and the oldest in tail • It does not take advantage of page access patterns or frequency
  • 15. FIFO Example Oldest Hit Hit Hit Newest Fig: FIFO example
  • 16. Optimal Replacement (OPT) • When the memory is full, evict a page that will be unreferenced for the longest time • The OS keeps track of all pages referenced by the program • Only if the program's memory reference pattern is relatively consistent
  • 17. OPTIMAL Example Referenced last Hit Hit Hit Hit Hit Hit Fig: OPTIMAL example
  • 18. Not Recently Used (NRU) • It favours keeping pages in memory that have been recently used. • The OS divides the pages into four classes based on usage during the last clock tick:  3. Referenced, modified  2. Referenced, not modified  1. Not referenced, modified  0. Not referenced, not modified
  • 19. NRU • Pick a random page from the lowest category for removal • i.e. the not referenced, not modified page
  • 20. NRU Example Fig: NRU example Recently referenced Hit Hit Hit Hit Hit Hit
  • 21. Second Chance • Modified version of FIFO • Instead of swapping out the last page, the referenced bit is checked • Gives every page a "second-chance"
  • 23. Clock • Modified version of FIFO • The set of frame candidates for replacement is considered as a circular buffer.
  • 25. Least Recently Used (LRU) • It swaps the pages that have been used the least over a period of time. • It is free from Belady’s anomaly.
  • 26. LRU Example Recently referenced Hit Hit Hit Hit Hit Hit Fig: LRU example
  • 27. Not frequently used (NFU) • This page replacement algorithm requires a counter • The counters keep track of how frequently a page has been used • The page with the lowest counter can be swapped out
  • 28. reference sequence : 3 2 3 0 8 4 2 5 0 9 8 3 2 P U 3 P U 2 P U 3 P U 0 P U 8 P U 4 +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ | | 0 |* | 3 | 1 | | 3 | 1 | | 3 | 1 | | 3 | 1 | | 3 | 1 | +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ | | 0 | | | 0 |* | 2 | 1 | | 2 | 1 | | 2 | 1 | | 2 | 1 | +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ | | 0 | | | 0 | | | 0 |* | | 0 |* | 0 | 1 | | 0 | 1 | +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ | | 0 | | | 0 | | | 0 | | | 0 | | | 0 |* | 8 | 1 | +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ | | 0 | | | 0 | | | 0 | | | 0 | | | 0 | | | 0 |* +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---- P U 2 P U 5 P U 0 P U 9 P U 8 P U 3 +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ | 3 | 1 |* | 3 | 1 |* | 5 | 1 | | 5 | 1 | | 5 | 1 | | 5 | 1 | +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ | 2 | 1 | | 2 | 1 | | 2 | 0 |* | 2 | 0 |* | 9 | 1 | | 9 | 1 | +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ | 0 | 1 | | 0 | 1 | | 0 | 0 | | 0 | 1 | | 0 | 1 |* | 0 | 1 |* +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ | 8 | 1 | | 8 | 1 | | 8 | 0 | | 8 | 0 | | 8 | 0 | | 8 | 1 | +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ | 4 | 1 | | 4 | 1 | | 4 | 0 | | 4 | 0 | | 4 | 0 | | 4 | 0 | +---+---+ +---+---+ +---+---+ +---+---+ +---+---+ +---+---- P U 2 P U +---+---+ +---+---+ * = indicates the pointer which identifies the next location | 5 | 1 |* | 5 | 0 | to scan P = page# stored in that frame U = used flag | 9 | 1 | | 9 | 0 | 0 = not used recently 1 = referenced recently +---+---+ +---+---+ | 0 | 0 | | 2 | 1 | +---+---+ +---+---+ | 8 | 0 | | 8 | 0 |* +---+---+ +---+---+ | 3 | 1 | | 3 | 1 | +---+---+ +---+---+ Fig: NFU example
  • 29. Random • This algorithm replaces a random page in memory. • It fares better than FIFO.
  • 30. Working set page replacement • The set of pages that a process is currently using is called the working set. • The working set algorithm is based on determining a working set and evicting any page that is not in the current working set upon a page fault.
  • 32. Conclusion Algorithm Comment • FIFO • OPTIMAL • LRU • NRU • NFU • Second Chance • CLOCK • Might throw out important pages • Not implementable • Excellent but difficult to implement • Crude approximation of LRU • Crude approximation of LRU • Big improvement over FIFO • Realistic
  • 33. References • Web Links  www.wikipedia.com  www.youtube.com  www.vbForum.com • Papers  Operating System Page Replacement Algorithms by A. Frank C. Wersberg • Books  Computer Organization & Architecture by William Stallings