SlideShare a Scribd company logo
pAge
RePlacEmeNt
ALgoRITHms
Current Mechanism..
❖ The operating system uses the method of paging for memory
management.
❖ Memory Frames.
❖ Processes are loaded as frames.
❖ Page Table.
page replacement.pptx
PROBLEM STATEMENT
❖ The demand occurs when the
operating system needs a page for
processing, and it is not present in
the main memory.
❖ Such situation is called Page
Fault.
Types of Page Replacement Algorithms
❖ First in First Out (FIFO) algorithm
❖ Optimal Page Replacement algorithm
❖ Least Recently Used (LRU) page replacement
algorithm
First in First Out
algorithm
First in First Out
❖ This is the simplest page replacement method in which the operating
system maintains all the pages in a queue.
❖ On a page fault, these pages from the front are removed first, and the
pages in demand are added.
HOW it
Works
Ex: Page Sequence: 1, 2, 3, 4, 5, 1, 3, 1, 6, 3, 2, 3
Total Page Fault = 9
ref 6 0 1 2 0 3 0 4 0 2 3 0 3 2
f 6 0 1 2 2 3 3 4 0 0 0 0 0 0
f 6 0 1 1 2 2 3 4 4 4 4 4 4
f 6 0 0 1 1 2 3 3 3 3 3 3
f 6 6 0 0 1 2 2 2 2 2 2
hit ✗ ✗ ✗ ✗ ✓ ✗ ✓ ✗ ✗ ✓ ✓ ✓ ✓ ✓
Ex: Page Sequence: 6,0,1,2,0,3,0,4,0,2,3,0,3,2
Advantages and Disadvantages
❖ Simple and easy to implement.
❖ Low overhead.
❏ Poor performance.
❏ Doesn’t consider the frequency of use or
last used time, simply replaces the oldest
page.
❏ Suffers from Belady’s Anomaly.
LRU Page
Replacement
algorithm
Least Recently Used Algorithm
❖ In this algorithm , pages are replaced which are not used for the
longest period of time.
❖ This algorithm can be seen as optimal page-replacement algorithm
looking backward in time, rather than forward.
❖ Counters and Stack are two primary ways in which this algorithm can
be implemented.
Least Recently Used Algorithm
❏ Counters
❖ Add the "time stamps" field to the page table entries.
❖ Add counter register to CPU. Counter is incremented every time a page
is referenced.
❖ When a page is referenced, the counter is copied to the "time stamps”
field.
❖ The victim page has the smallest "time stamps" value.
Least Recently Used Algorithm
❏ Counters
Least Recently Used Algorithm
❏ Counters
Total Page fault : 10
Least Recently Used Algorithm
❏ Stack
❖ The LRU replacement algorithm can also be accomplished by keeping
a stack of page numbers.
❖ When a page is referenced, it is removed from the stack and placed at
the top.
❖ Therefore, the most recently used page is always at the top of the stack
and the least recently used page is always at the bottom.
Least Recently Used Algorithm
❏ Stack
Algorithm
1.Start traversing the page
i) If set holds less page than capacity.
A. Insert page into the set one by one until the size
of set reaches capacity or all page requests are
processed.
B. Simultaneously maintain the recent occurred index
of each page in a map called indexes.
C. Increment page fault.
Algorithm
ii) Else
If Current page is present in set, do nothing else.
Else
A. Find the page in the set that was least recently used. We find
it using index array. We basically need to replace the page
with minimum index.
B. Replace the found page with current page.
C. Increment page faults.
D. Update index of current page.
2) Return page faults.
LRU Advantage
❏ Almost as good as OPT.
❏ No Belady’s Anomaly.
❏ Widely used for caches as well
LRU Disadvantage
❏ More complicated and expensive to implement than FIFO
algorithms:
❏ Determining an ordering based upon “time of last use”
❏ May require substantial hardware assistance
Optimal page
Replacement
algorithm
Optimal page replacement
❖ In this algorithm , pages are replaced which are not used for the
longest duration of time in the future.
❖ This algorithms replaces the page which will not be referred for so
long in future.
❖ This algorithm will never suffer from Belady’s anomaly.
Algorithm
1. Push the first page in the stack as per the memory demand.
2. Push the second page as per the memory demand
3. Push the third page until the memory if full.
4. As the stack is full,the page which is least recently used is popped.
5. Repeat step 4, until the page demand continues and until the
processing is over.
6. Terminate the program.
OPT in
Action
Q: 4 Frames. Page reference string: 1,2,3,4,5,1,3,1,6,3,2,3.
Soln:
Total page faults: 6
Q: 3 Frames. Page reference string: 7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1
Soln:
Total page faults: 9
Implementation
❖ Since future cannot be predicted in general,the algorithm
cannot really be implemented
❖ Sometimes,if a program is used repeatedly, its behaviour may
be known
❖ OPT can be approximated
❖ OPT is set a benchmark.
Advantages
❖ It is less complex and easy to understand.
❖ A page is replaced with minimum fuss.
❖ Simple data structure are used for this purpose
Disadvantages
❖ Not all operating system can implement this
algorithm
❖ Error detection is harder
CONCLUSION
Conclusion
In the above methods or algorithms .we have found that optimal page replacement algorithm results
in the best algorithm because the average page faults in all three cases with page frame size 2,3 and
4 is less as compared to FIFO and LRU.
Considering above example: Page faults for respective algorithms were
➢ FIFO: 9 page faults.
➢ LRU: 8 page faults.
➢ OPTIMAL: 6 page faults.
Though optimal page replacement algorithm is best and efficient as compared to other two but it
cannot be implemented because we can't predict the future. So it is best for theory but LRU page
replacement algorithm is used in most of the cases.

More Related Content

PPTX
File access method
GayathriS578276
 
PPTX
Pipelining and vector processing
Kamal Acharya
 
PPTX
Semaphore
Arafat Hossan
 
PPTX
Paging and Segmentation in Operating System
Raj Mohan
 
PPTX
Critical section problem in operating system.
MOHIT DADU
 
PPT
Introduction to Compiler Construction
Sarmad Ali
 
PPTX
Page replacement algorithms
Piyush Rochwani
 
PPTX
Intermediate code generator
sanchi29
 
File access method
GayathriS578276
 
Pipelining and vector processing
Kamal Acharya
 
Semaphore
Arafat Hossan
 
Paging and Segmentation in Operating System
Raj Mohan
 
Critical section problem in operating system.
MOHIT DADU
 
Introduction to Compiler Construction
Sarmad Ali
 
Page replacement algorithms
Piyush Rochwani
 
Intermediate code generator
sanchi29
 

What's hot (20)

PPTX
Page replacement algorithms
sangrampatil81
 
PPTX
OS disk structure (1).pptx
SharanyaEmmadisetty
 
PPT
Contiguous Memory Allocation.ppt
infomerlin
 
PDF
Semaphores
Mohd Arif
 
PPTX
Multi processor scheduling
Shashank Kapoor
 
PDF
Operating system Memory management
Shashank Asthana
 
PPTX
Operating system critical section
Harshana Madusanka Jayamaha
 
PPTX
Code generation
Aparna Nayak
 
PDF
Cs8493 unit 2
Kathirvel Ayyaswamy
 
PPTX
Principal source of optimization in compiler design
Rajkumar R
 
PPT
Interprocess communication (IPC) IN O.S
Hussain Ala'a Alkabi
 
PPTX
Loop optimization
Vivek Gandhi
 
PPTX
sl slides-unit-1.pptx
SRAVANTHISALLARAM1
 
PPT
Intermediate code generation (Compiler Design)
Tasif Tanzim
 
PPTX
Disk Scheduling Algorithm in Operating System
Meghaj Mallick
 
PDF
Monitors
Mohd Arif
 
PPTX
Structure of the compiler
Sudhaa Ravi
 
PPTX
Chomsky classification of Language
Dipankar Boruah
 
PPTX
Computer architecture page replacement algorithms
Mazin Alwaaly
 
Page replacement algorithms
sangrampatil81
 
OS disk structure (1).pptx
SharanyaEmmadisetty
 
Contiguous Memory Allocation.ppt
infomerlin
 
Semaphores
Mohd Arif
 
Multi processor scheduling
Shashank Kapoor
 
Operating system Memory management
Shashank Asthana
 
Operating system critical section
Harshana Madusanka Jayamaha
 
Code generation
Aparna Nayak
 
Cs8493 unit 2
Kathirvel Ayyaswamy
 
Principal source of optimization in compiler design
Rajkumar R
 
Interprocess communication (IPC) IN O.S
Hussain Ala'a Alkabi
 
Loop optimization
Vivek Gandhi
 
sl slides-unit-1.pptx
SRAVANTHISALLARAM1
 
Intermediate code generation (Compiler Design)
Tasif Tanzim
 
Disk Scheduling Algorithm in Operating System
Meghaj Mallick
 
Monitors
Mohd Arif
 
Structure of the compiler
Sudhaa Ravi
 
Chomsky classification of Language
Dipankar Boruah
 
Computer architecture page replacement algorithms
Mazin Alwaaly
 
Ad

Similar to page replacement.pptx (20)

PPTX
virtual memory Operating system
Shaheen kousar
 
PPT
page replacement algorithm powerpoint presentation
SREERAG36
 
PDF
Adobe Scan 06-Jan-2023.pdf demand paging document
AllyKhan2
 
PDF
final_unit_6_spos_notes_2023/24 pattern.pdf
silentkillerin2023
 
PPTX
operating system notes about virtual memory 4.pptx
panditestmail
 
PPT
Unit 2chapter 2 memory mgmt complete
Kalai Selvi
 
PPTX
Page replacement
Davin Abraham
 
PPT
Memory management
Rasi123
 
PPTX
Virtual memory management in Operating System
Rashmi Bhat
 
PPT
Operating System
Subhasis Dash
 
PPTX
Demand paging
Trinity Dwarka
 
DOCX
Virtual memory
lodhran-hayat
 
PPTX
Operating system 38 page replacement
Vaibhav Khanna
 
PPTX
3_page_replacement_algorithms computer system and architecture
bebew44927
 
PPTX
Page replacement_Architecture ppt (213015018+213015017).pptx
MD SAZID ZAMIL
 
PPTX
operating system virtual memory and logical memory
salihan090918
 
PDF
Virtual Memory.pdf
SujanTimalsina5
 
PPTX
Operating system 37 demand paging
Vaibhav Khanna
 
PPT
VM Page Replacement
sathish sak
 
virtual memory Operating system
Shaheen kousar
 
page replacement algorithm powerpoint presentation
SREERAG36
 
Adobe Scan 06-Jan-2023.pdf demand paging document
AllyKhan2
 
final_unit_6_spos_notes_2023/24 pattern.pdf
silentkillerin2023
 
operating system notes about virtual memory 4.pptx
panditestmail
 
Unit 2chapter 2 memory mgmt complete
Kalai Selvi
 
Page replacement
Davin Abraham
 
Memory management
Rasi123
 
Virtual memory management in Operating System
Rashmi Bhat
 
Operating System
Subhasis Dash
 
Demand paging
Trinity Dwarka
 
Virtual memory
lodhran-hayat
 
Operating system 38 page replacement
Vaibhav Khanna
 
3_page_replacement_algorithms computer system and architecture
bebew44927
 
Page replacement_Architecture ppt (213015018+213015017).pptx
MD SAZID ZAMIL
 
operating system virtual memory and logical memory
salihan090918
 
Virtual Memory.pdf
SujanTimalsina5
 
Operating system 37 demand paging
Vaibhav Khanna
 
VM Page Replacement
sathish sak
 
Ad

Recently uploaded (20)

PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Software Development Methodologies in 2025
KodekX
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Doc9.....................................
SofiaCollazos
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 

page replacement.pptx

  • 2. Current Mechanism.. ❖ The operating system uses the method of paging for memory management. ❖ Memory Frames. ❖ Processes are loaded as frames. ❖ Page Table.
  • 4. PROBLEM STATEMENT ❖ The demand occurs when the operating system needs a page for processing, and it is not present in the main memory. ❖ Such situation is called Page Fault.
  • 5. Types of Page Replacement Algorithms ❖ First in First Out (FIFO) algorithm ❖ Optimal Page Replacement algorithm ❖ Least Recently Used (LRU) page replacement algorithm
  • 6. First in First Out algorithm
  • 7. First in First Out ❖ This is the simplest page replacement method in which the operating system maintains all the pages in a queue. ❖ On a page fault, these pages from the front are removed first, and the pages in demand are added.
  • 9. Ex: Page Sequence: 1, 2, 3, 4, 5, 1, 3, 1, 6, 3, 2, 3 Total Page Fault = 9
  • 10. ref 6 0 1 2 0 3 0 4 0 2 3 0 3 2 f 6 0 1 2 2 3 3 4 0 0 0 0 0 0 f 6 0 1 1 2 2 3 4 4 4 4 4 4 f 6 0 0 1 1 2 3 3 3 3 3 3 f 6 6 0 0 1 2 2 2 2 2 2 hit ✗ ✗ ✗ ✗ ✓ ✗ ✓ ✗ ✗ ✓ ✓ ✓ ✓ ✓ Ex: Page Sequence: 6,0,1,2,0,3,0,4,0,2,3,0,3,2
  • 11. Advantages and Disadvantages ❖ Simple and easy to implement. ❖ Low overhead. ❏ Poor performance. ❏ Doesn’t consider the frequency of use or last used time, simply replaces the oldest page. ❏ Suffers from Belady’s Anomaly.
  • 13. Least Recently Used Algorithm ❖ In this algorithm , pages are replaced which are not used for the longest period of time. ❖ This algorithm can be seen as optimal page-replacement algorithm looking backward in time, rather than forward. ❖ Counters and Stack are two primary ways in which this algorithm can be implemented.
  • 14. Least Recently Used Algorithm ❏ Counters ❖ Add the "time stamps" field to the page table entries. ❖ Add counter register to CPU. Counter is incremented every time a page is referenced. ❖ When a page is referenced, the counter is copied to the "time stamps” field. ❖ The victim page has the smallest "time stamps" value.
  • 15. Least Recently Used Algorithm ❏ Counters
  • 16. Least Recently Used Algorithm ❏ Counters Total Page fault : 10
  • 17. Least Recently Used Algorithm ❏ Stack ❖ The LRU replacement algorithm can also be accomplished by keeping a stack of page numbers. ❖ When a page is referenced, it is removed from the stack and placed at the top. ❖ Therefore, the most recently used page is always at the top of the stack and the least recently used page is always at the bottom.
  • 18. Least Recently Used Algorithm ❏ Stack
  • 19. Algorithm 1.Start traversing the page i) If set holds less page than capacity. A. Insert page into the set one by one until the size of set reaches capacity or all page requests are processed. B. Simultaneously maintain the recent occurred index of each page in a map called indexes. C. Increment page fault.
  • 20. Algorithm ii) Else If Current page is present in set, do nothing else. Else A. Find the page in the set that was least recently used. We find it using index array. We basically need to replace the page with minimum index. B. Replace the found page with current page. C. Increment page faults. D. Update index of current page. 2) Return page faults.
  • 21. LRU Advantage ❏ Almost as good as OPT. ❏ No Belady’s Anomaly. ❏ Widely used for caches as well LRU Disadvantage ❏ More complicated and expensive to implement than FIFO algorithms: ❏ Determining an ordering based upon “time of last use” ❏ May require substantial hardware assistance
  • 23. Optimal page replacement ❖ In this algorithm , pages are replaced which are not used for the longest duration of time in the future. ❖ This algorithms replaces the page which will not be referred for so long in future. ❖ This algorithm will never suffer from Belady’s anomaly.
  • 24. Algorithm 1. Push the first page in the stack as per the memory demand. 2. Push the second page as per the memory demand 3. Push the third page until the memory if full. 4. As the stack is full,the page which is least recently used is popped. 5. Repeat step 4, until the page demand continues and until the processing is over. 6. Terminate the program.
  • 26. Q: 4 Frames. Page reference string: 1,2,3,4,5,1,3,1,6,3,2,3. Soln: Total page faults: 6
  • 27. Q: 3 Frames. Page reference string: 7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1 Soln: Total page faults: 9
  • 28. Implementation ❖ Since future cannot be predicted in general,the algorithm cannot really be implemented ❖ Sometimes,if a program is used repeatedly, its behaviour may be known ❖ OPT can be approximated ❖ OPT is set a benchmark.
  • 29. Advantages ❖ It is less complex and easy to understand. ❖ A page is replaced with minimum fuss. ❖ Simple data structure are used for this purpose
  • 30. Disadvantages ❖ Not all operating system can implement this algorithm ❖ Error detection is harder
  • 32. Conclusion In the above methods or algorithms .we have found that optimal page replacement algorithm results in the best algorithm because the average page faults in all three cases with page frame size 2,3 and 4 is less as compared to FIFO and LRU. Considering above example: Page faults for respective algorithms were ➢ FIFO: 9 page faults. ➢ LRU: 8 page faults. ➢ OPTIMAL: 6 page faults. Though optimal page replacement algorithm is best and efficient as compared to other two but it cannot be implemented because we can't predict the future. So it is best for theory but LRU page replacement algorithm is used in most of the cases.

Editor's Notes

  • #19: 7 0 1 2 0 3 0 4 2 3 0 3 2 3