SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Page Replacement Algorithms
FIFO, NRU, LRU, NFU...
Index
S. No. Topic
1. Paging
2. Page Replacement
3. Algorithms
a. Optimal
b. FIFO
c. NFU
d. NRU
e. LRU
f. Second Chance
g. CLOCK
h. Random
i. Working Set
4. Conclusion
5. References
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?
yesno
HITFAULT
STOPFetch 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 HitHit 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.
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

Weitere ähnliche Inhalte

Was ist angesagt?

Thrashing allocation frames.43
Thrashing allocation frames.43Thrashing allocation frames.43
Thrashing allocation frames.43
myrajendra
 
Cache memory
Cache memoryCache memory
Cache memory
Anuj Modi
 
Free space managment46
Free space managment46Free space managment46
Free space managment46
myrajendra
 

Was ist angesagt? (20)

Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating Systems
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 
CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentation
 
Thrashing allocation frames.43
Thrashing allocation frames.43Thrashing allocation frames.43
Thrashing allocation frames.43
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
Os Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memory
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
 
Paging and Segmentation in Operating System
Paging and Segmentation in Operating SystemPaging and Segmentation in Operating System
Paging and Segmentation in Operating System
 
Demand paging
Demand pagingDemand paging
Demand paging
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
 
Cache memory
Cache memoryCache memory
Cache memory
 
Free space managment46
Free space managment46Free space managment46
Free space managment46
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
SCHEDULING ALGORITHMS
SCHEDULING ALGORITHMSSCHEDULING ALGORITHMS
SCHEDULING ALGORITHMS
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
Cache memory
Cache memoryCache memory
Cache memory
 
Computer architecture page replacement algorithms
Computer architecture page replacement algorithmsComputer architecture page replacement algorithms
Computer architecture page replacement algorithms
 
ADDRESSING MODES
ADDRESSING MODESADDRESSING MODES
ADDRESSING MODES
 

Andere mochten auch

41 page replacement fifo
41 page replacement fifo41 page replacement fifo
41 page replacement fifo
myrajendra
 

Andere mochten auch (9)

Translation lookaside buffer
Translation lookaside bufferTranslation lookaside buffer
Translation lookaside buffer
 
41 page replacement fifo
41 page replacement fifo41 page replacement fifo
41 page replacement fifo
 
Page replacement
Page replacementPage replacement
Page replacement
 
Handling Page Fault
Handling Page FaultHandling Page Fault
Handling Page Fault
 
Faults
FaultsFaults
Faults
 
Microprocessor 8086
Microprocessor 8086Microprocessor 8086
Microprocessor 8086
 
Chapter 9 - Virtual Memory
Chapter 9 - Virtual MemoryChapter 9 - Virtual Memory
Chapter 9 - Virtual Memory
 
Page replacement
Page replacementPage replacement
Page replacement
 
1327 Addressing Modes Of 8086
1327 Addressing Modes Of 80861327 Addressing Modes Of 8086
1327 Addressing Modes Of 8086
 

Ähnlich wie Page replacement algorithms

Percona live-2012-optimizer-tuning
Percona live-2012-optimizer-tuningPercona live-2012-optimizer-tuning
Percona live-2012-optimizer-tuning
Sergey Petrunya
 
15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfz
Joshua Thijssen
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
Command Prompt., Inc
 
Homework Assignment 3 Chapter 3 St. Clair & Visick, Putting you.docx
Homework Assignment 3 Chapter 3 St. Clair & Visick, Putting you.docxHomework Assignment 3 Chapter 3 St. Clair & Visick, Putting you.docx
Homework Assignment 3 Chapter 3 St. Clair & Visick, Putting you.docx
fideladallimore
 
Performance Enhancements In Postgre Sql 8.4
Performance Enhancements In Postgre Sql 8.4Performance Enhancements In Postgre Sql 8.4
Performance Enhancements In Postgre Sql 8.4
HighLoad2009
 

Ähnlich wie Page replacement algorithms (20)

Percona live-2012-optimizer-tuning
Percona live-2012-optimizer-tuningPercona live-2012-optimizer-tuning
Percona live-2012-optimizer-tuning
 
15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfz
 
Using Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query PerformanceUsing Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query Performance
 
Window functions in MariaDB 10.2
Window functions in MariaDB 10.2Window functions in MariaDB 10.2
Window functions in MariaDB 10.2
 
Virtual memory and page replacement algorithm
Virtual memory and page replacement algorithmVirtual memory and page replacement algorithm
Virtual memory and page replacement algorithm
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Perf Tuning Short
Perf Tuning ShortPerf Tuning Short
Perf Tuning Short
 
Replacement.ppt operating system in BCA cu
Replacement.ppt operating system in BCA cuReplacement.ppt operating system in BCA cu
Replacement.ppt operating system in BCA cu
 
Highload++2014: 1Hippeus - zerocopy messaging in the spirit of Sparta!
Highload++2014: 1Hippeus - zerocopy messaging in the spirit of Sparta!Highload++2014: 1Hippeus - zerocopy messaging in the spirit of Sparta!
Highload++2014: 1Hippeus - zerocopy messaging in the spirit of Sparta!
 
4. Data Manipulation.ppt
4. Data Manipulation.ppt4. Data Manipulation.ppt
4. Data Manipulation.ppt
 
Need for Speed: MySQL Indexing
Need for Speed: MySQL IndexingNeed for Speed: MySQL Indexing
Need for Speed: MySQL Indexing
 
#Cashtag
#Cashtag#Cashtag
#Cashtag
 
Hashtag cashtagfinal_1
Hashtag cashtagfinal_1Hashtag cashtagfinal_1
Hashtag cashtagfinal_1
 
MeetBSD2014 Performance Analysis
MeetBSD2014 Performance AnalysisMeetBSD2014 Performance Analysis
MeetBSD2014 Performance Analysis
 
1Hippeus - zerocopy messaging по законам Спарты, Леонид Юрьев (ПЕТЕР-СЕРВИС)
1Hippeus -  zerocopy messaging по законам Спарты, Леонид Юрьев (ПЕТЕР-СЕРВИС)1Hippeus -  zerocopy messaging по законам Спарты, Леонид Юрьев (ПЕТЕР-СЕРВИС)
1Hippeus - zerocopy messaging по законам Спарты, Леонид Юрьев (ПЕТЕР-СЕРВИС)
 
Homework Assignment 3 Chapter 3 St. Clair & Visick, Putting you.docx
Homework Assignment 3 Chapter 3 St. Clair & Visick, Putting you.docxHomework Assignment 3 Chapter 3 St. Clair & Visick, Putting you.docx
Homework Assignment 3 Chapter 3 St. Clair & Visick, Putting you.docx
 
Linux Systems Performance 2016
Linux Systems Performance 2016Linux Systems Performance 2016
Linux Systems Performance 2016
 
Performance Enhancements In Postgre Sql 8.4
Performance Enhancements In Postgre Sql 8.4Performance Enhancements In Postgre Sql 8.4
Performance Enhancements In Postgre Sql 8.4
 
忙しい人のためのSphinx 入門 demo
忙しい人のためのSphinx 入門 demo忙しい人のためのSphinx 入門 demo
忙しい人のためのSphinx 入門 demo
 

Mehr von Piyush Rochwani (20)

Unit 2
Unit 2Unit 2
Unit 2
 
Unit 3
Unit 3Unit 3
Unit 3
 
Biometrics based key generation
Biometrics based key generationBiometrics based key generation
Biometrics based key generation
 
Serial transmission
Serial transmissionSerial transmission
Serial transmission
 
Sequential and combinational alu
Sequential and combinational alu Sequential and combinational alu
Sequential and combinational alu
 
Memory virtualization
Memory virtualizationMemory virtualization
Memory virtualization
 
Risc
RiscRisc
Risc
 
Raid
Raid Raid
Raid
 
Pipelining and co processor.
Pipelining and co processor.Pipelining and co processor.
Pipelining and co processor.
 
8086 Microprocessor
8086 Microprocessor8086 Microprocessor
8086 Microprocessor
 
Dma
DmaDma
Dma
 
Control unit
Control unitControl unit
Control unit
 
Memory types
Memory typesMemory types
Memory types
 
Solid state solid state drives
Solid state solid state drivesSolid state solid state drives
Solid state solid state drives
 
Coa INTERUPT
Coa INTERUPTCoa INTERUPT
Coa INTERUPT
 
Cisc(a022& a023)
Cisc(a022& a023)Cisc(a022& a023)
Cisc(a022& a023)
 
Booth’s algorithm.(a014& a015)
Booth’s algorithm.(a014& a015)Booth’s algorithm.(a014& a015)
Booth’s algorithm.(a014& a015)
 
06 floating point
06 floating point06 floating point
06 floating point
 
05 multiply divide
05 multiply divide05 multiply divide
05 multiply divide
 
Air pollution in mumbai
Air pollution in mumbaiAir pollution in mumbai
Air pollution in mumbai
 

Kürzlich hochgeladen

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Kürzlich hochgeladen (20)

Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 

Page replacement algorithms

  • 2. Index S. No. Topic 1. Paging 2. Page Replacement 3. Algorithms a. Optimal b. FIFO c. NFU d. NRU e. LRU f. Second Chance g. CLOCK h. Random i. Working Set 4. Conclusion 5. References
  • 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 HitHit 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.
  • 31.
  • 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

Hinweis der Redaktion

  1. may exceed the amount of main memory-> virtual memory active part in main memory and the rest in secondary memory Data read in pages
  2.  a local page replacement algorithm selects for replacement some page that belongs to that same process (or a group of processes sharing a memory partition). A global replacement algorithm is free to select any page in memory.
  3. Belady’s anamoly-page fault inc with no. of frames
  4. Disadvantage->page that is referenced frequently also gets replaced->doesn’t take care of that belady’s anamoly
  5. Covers up the disadvantage of FIFO Unreferenced for the longest time->replace that page Os will keep track->pattern should be consistent
  6. Free of belady’s anamoly
  7. Covers up the disadvantage of FIFO Instead of
  8. Free from belady’s anamoly
  9. LRU keeps track of page usage over a short period of time, while NRU just looks at the usage in the last clock interval.
  10. Free from belady’s anamoly