SlideShare a Scribd company logo
1 of 23
Page Replacement
CS 537 - Introduction to Operating Systems
Paging Revisitted
• If a page is not in physical memory
– find the page on disk
– find a free frame
– bring the page into memory
• What if there is no free frame in memory?
Page Replacement
• Basic idea
– if there is a free page in memory, use it
– if not, select a victim frame
– write the victim out to disk
– read the desired page into the now free frame
– update page tables
– restart the process
Page Replacement
• Main objective of a good replacement
algorithm is to achieve a low page fault rate
– insure that heavily used pages stay in memory
– the replaced page should not be needed for
some time
• Secondary objective is to reduce latency of
a page fault
– efficient code
– replace pages that do not need to be written out
Reference String
• Reference string is the sequence of pages
being referenced
• If user has the following sequence of
addresses
– 123, 215, 600, 1234, 76, 96
• If the page size is 100, then the reference
string is
– 1, 2, 6, 12, 0, 0
First-In, First-Out (FIFO)
• The oldest page in physical memory is the
one selected for replacement
• Very simple to implement
– keep a list
• victims are chosen from the tail
• new pages in are placed at the head
FIFO
0
2
1
6
4
2
1
6
4
0
1
6
4
0
3
6
4
0
3
1
2
0
3
1
4 0 3 1 2
•Fault Rate = 9 / 12 = 0.75
•Consider the following reference string: 0, 2, 1, 6, 4, 0, 1, 0, 3, 1, 2, 1
x x x x x x x x x
Compulsory Misses
FIFO Issues
• Poor replacement policy
• Evicts the oldest page in the system
– usually a heavily used variable should be
around for a long time
– FIFO replaces the oldest page - perhaps the one
with the heavily used variable
• FIFO does not consider page usage
Optimal Page Replacement
• Often called Balady’s Min
• Basic idea
– replace the page that will not be referenced for
the longest time
• This gives the lowest possible fault rate
• Impossible to implement
• Does provide a good measure for other
techniques
Optimal Page Replacement
•Consider the following reference string: 0, 2, 1, 6, 4, 0, 1, 0, 3, 1, 2, 1
x x x x x x
Compulsory Misses
0
2
1
6
0
2
1
4
3
2
1
4
4 3
•Fault Rate = 6 / 12 = 0.50
•With the above reference string, this is the best we can hope to do
Least Recently Used (LRU)
• Basic idea
– replace the page in memory that has not been
accessed for the longest time
• Optimal policy looking back in time
– as opposed to forward in time
– fortunately, programs tend to follow similar
behavior
LRU
•Consider the following reference string: 0, 2, 1, 6, 4, 0, 1, 0, 3, 1, 2, 1
x x x x x x x x
Compulsory Misses
0
2
1
6
4
2
1
6
4
0
1
6
4 0
•Fault Rate = 8 / 12 = 0.67
4
0
1
3
3
2
0
1
3
2
LRU Issues
• How to keep track of last page access?
– requires special hardware support
• 2 major solutions
– counters
• hardware clock “ticks” on every memory reference
• the page referenced is marked with this “time”
• the page with the smallest “time” value is replaced
– stack
• keep a stack of references
• on every reference to a page, move it to top of stack
• page at bottom of stack is next one to be replaced
LRU Issues
• Both techniques just listed require
additional hardware
– remember, memory reference are very common
– impractical to invoke software on every
memory reference
• LRU is not used very often
• Instead, we will try to approximate LRU
Replacement Hardware Support
• Most system will simply provide a reference
bit in PT for each page
• On a reference to a page, this bit is set to 1
• This bit can be cleared by the OS
• This simple hardware has lead to a variety
of algorithms to approximate LRU
Sampled LRU
• Keep a reference byte for each page
• At set time intervals, take an interrupt and
get the OS involved
– OS reads the reference bit for each page
– reference bit is stuffed into the beginning byte
for page
– all the reference bits are then cleared
• On page fault, replace the page with the
smallest reference byte
Sampled LRU
R
0
1
2
3
4
1
1
1
0
0
01100110
10001001
10000000
01010101
00001101
Interrupt
R
0
1
2
3
4
0
0
0
0
0
10110011
01000100
01000000
10101010
10000110
Page Table Reference Bytes
page to replace
on next page fault
Clock Algorithm (Second Chance)
• On page fault, search through pages
• If a page’s reference bit is set to 1
– set its reference bit to zero and skip it (give it a
second chance)
• If a page’s reference bit is set to 0
– select this page for replacement
• Always start the search from where the last
search left off
Clock Algorithm
R
1
P6
R
1
P1
R
1
P7
R
0
P3
R
1
P9
R
0
P0
Pointer to first
page to check
•user refs P4 - not currently paged
•start at P6
•check P6, P1, P7 and set their
reference bits to zero (give
them a second chance)
•check P3 and notice its ref bit
is 0
•Select P3 for replacement
•Set pointer to P9 for next search
0
0
0
R
1
P4
Dirty Pages
• If a page has been written to, it is dirty
• Before a dirty page can be replaced it must
be written to disk
• A clean page does not need to be written to
disk
– the copy on disk is already up-to-date
• We would rather replace an old, clean page
than and old, dirty page
Modified Clock Algorithm
• Very similar to Clock Algorithm
• Instead of 2 states (ref’d and not ref’d) we
will have 4 states
– (0, 0) - not referenced clean
– (0, 1) - not referenced dirty
– (1, 0) - referenced but clean
– (1, 1) - referenced and dirty
• Order of preference for replacement goes in
the order listed above
Modified Clock Algorithm
• Add a second bit to PT - dirty bit
• Hardware sets this bit on write to a page
• OS can clear this bit
• Now just do clock algorithm and look for
best page to replace
• This method may require multiple passes
through the list
Page Buffering
• It is expensive to wait for a dirty page to be
written out
• To get process started quickly, always keep a pool
of free frames (buffers)
• On a page fault
– select a page to replace
– write new page into a frame in the free pool
– mark page table
– restart the process
– now write the dirty page out to disk
– place frame holding replaced page in the free pool

More Related Content

Similar to Replacement.ppt operating system in BCA cu

Computer architecture page replacement algorithms
Computer architecture page replacement algorithmsComputer architecture page replacement algorithms
Computer architecture page replacement algorithmsMazin Alwaaly
 
Comparision of page replacement algorithms.pptx
Comparision of page replacement algorithms.pptxComparision of page replacement algorithms.pptx
Comparision of page replacement algorithms.pptxSureshD94
 
Virtual memory and page replacement algorithm
Virtual memory and page replacement algorithmVirtual memory and page replacement algorithm
Virtual memory and page replacement algorithmMuhammad Mansoor Ul Haq
 
Virtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdfVirtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdfHarika Pudugosula
 
16. PagingImplementIssused.pptx
16. PagingImplementIssused.pptx16. PagingImplementIssused.pptx
16. PagingImplementIssused.pptxMyName1sJeff
 
virtual memory Operating system
virtual memory Operating system virtual memory Operating system
virtual memory Operating system Shaheen kousar
 
Virtual Memory Management Part - I.pdf
Virtual Memory Management Part - I.pdfVirtual Memory Management Part - I.pdf
Virtual Memory Management Part - I.pdfHarika Pudugosula
 
Operating system 38 page replacement
Operating system 38 page replacementOperating system 38 page replacement
Operating system 38 page replacementVaibhav Khanna
 
Understanding memory management
Understanding memory managementUnderstanding memory management
Understanding memory managementGokul Vasan
 
Page replacement
Page replacementPage replacement
Page replacementsashi799
 
Memory management
Memory managementMemory management
Memory managementRasi123
 
chap.4.memory.manag.ppt
chap.4.memory.manag.pptchap.4.memory.manag.ppt
chap.4.memory.manag.pptamadayshwan
 
Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvk
Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvkVirtual Memory sjkdhikejv vsdkjnksnv vkjhfvk
Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvkHKShab
 

Similar to Replacement.ppt operating system in BCA cu (20)

Computer architecture page replacement algorithms
Computer architecture page replacement algorithmsComputer architecture page replacement algorithms
Computer architecture page replacement algorithms
 
Comparision of page replacement algorithms.pptx
Comparision of page replacement algorithms.pptxComparision of page replacement algorithms.pptx
Comparision of page replacement algorithms.pptx
 
Virtual memory and page replacement algorithm
Virtual memory and page replacement algorithmVirtual memory and page replacement algorithm
Virtual memory and page replacement algorithm
 
Virtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdfVirtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdf
 
16. PagingImplementIssused.pptx
16. PagingImplementIssused.pptx16. PagingImplementIssused.pptx
16. PagingImplementIssused.pptx
 
virtual_memory (3).pptx
virtual_memory (3).pptxvirtual_memory (3).pptx
virtual_memory (3).pptx
 
virtual memory Operating system
virtual memory Operating system virtual memory Operating system
virtual memory Operating system
 
Virtual memory
Virtual memory Virtual memory
Virtual memory
 
Virtual Memory Management Part - I.pdf
Virtual Memory Management Part - I.pdfVirtual Memory Management Part - I.pdf
Virtual Memory Management Part - I.pdf
 
O ssvv82014
O ssvv82014O ssvv82014
O ssvv82014
 
Operating system 38 page replacement
Operating system 38 page replacementOperating system 38 page replacement
Operating system 38 page replacement
 
Understanding memory management
Understanding memory managementUnderstanding memory management
Understanding memory management
 
Page replacement
Page replacementPage replacement
Page replacement
 
Page replacement alg
Page replacement algPage replacement alg
Page replacement alg
 
Memory management
Memory managementMemory management
Memory management
 
4 (1)
4 (1)4 (1)
4 (1)
 
chap.4.memory.manag.ppt
chap.4.memory.manag.pptchap.4.memory.manag.ppt
chap.4.memory.manag.ppt
 
Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvk
Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvkVirtual Memory sjkdhikejv vsdkjnksnv vkjhfvk
Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvk
 
Os4
Os4Os4
Os4
 
Os4
Os4Os4
Os4
 

Recently uploaded

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
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 17Celine George
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
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 ModeThiyagu K
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
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 Delhikauryashika82
 
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 ConsultingTechSoup
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 

Recently uploaded (20)

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
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
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
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
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
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
 
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
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 

Replacement.ppt operating system in BCA cu

  • 1. Page Replacement CS 537 - Introduction to Operating Systems
  • 2. Paging Revisitted • If a page is not in physical memory – find the page on disk – find a free frame – bring the page into memory • What if there is no free frame in memory?
  • 3. Page Replacement • Basic idea – if there is a free page in memory, use it – if not, select a victim frame – write the victim out to disk – read the desired page into the now free frame – update page tables – restart the process
  • 4. Page Replacement • Main objective of a good replacement algorithm is to achieve a low page fault rate – insure that heavily used pages stay in memory – the replaced page should not be needed for some time • Secondary objective is to reduce latency of a page fault – efficient code – replace pages that do not need to be written out
  • 5. Reference String • Reference string is the sequence of pages being referenced • If user has the following sequence of addresses – 123, 215, 600, 1234, 76, 96 • If the page size is 100, then the reference string is – 1, 2, 6, 12, 0, 0
  • 6. First-In, First-Out (FIFO) • The oldest page in physical memory is the one selected for replacement • Very simple to implement – keep a list • victims are chosen from the tail • new pages in are placed at the head
  • 7. FIFO 0 2 1 6 4 2 1 6 4 0 1 6 4 0 3 6 4 0 3 1 2 0 3 1 4 0 3 1 2 •Fault Rate = 9 / 12 = 0.75 •Consider the following reference string: 0, 2, 1, 6, 4, 0, 1, 0, 3, 1, 2, 1 x x x x x x x x x Compulsory Misses
  • 8. FIFO Issues • Poor replacement policy • Evicts the oldest page in the system – usually a heavily used variable should be around for a long time – FIFO replaces the oldest page - perhaps the one with the heavily used variable • FIFO does not consider page usage
  • 9. Optimal Page Replacement • Often called Balady’s Min • Basic idea – replace the page that will not be referenced for the longest time • This gives the lowest possible fault rate • Impossible to implement • Does provide a good measure for other techniques
  • 10. Optimal Page Replacement •Consider the following reference string: 0, 2, 1, 6, 4, 0, 1, 0, 3, 1, 2, 1 x x x x x x Compulsory Misses 0 2 1 6 0 2 1 4 3 2 1 4 4 3 •Fault Rate = 6 / 12 = 0.50 •With the above reference string, this is the best we can hope to do
  • 11. Least Recently Used (LRU) • Basic idea – replace the page in memory that has not been accessed for the longest time • Optimal policy looking back in time – as opposed to forward in time – fortunately, programs tend to follow similar behavior
  • 12. LRU •Consider the following reference string: 0, 2, 1, 6, 4, 0, 1, 0, 3, 1, 2, 1 x x x x x x x x Compulsory Misses 0 2 1 6 4 2 1 6 4 0 1 6 4 0 •Fault Rate = 8 / 12 = 0.67 4 0 1 3 3 2 0 1 3 2
  • 13. LRU Issues • How to keep track of last page access? – requires special hardware support • 2 major solutions – counters • hardware clock “ticks” on every memory reference • the page referenced is marked with this “time” • the page with the smallest “time” value is replaced – stack • keep a stack of references • on every reference to a page, move it to top of stack • page at bottom of stack is next one to be replaced
  • 14. LRU Issues • Both techniques just listed require additional hardware – remember, memory reference are very common – impractical to invoke software on every memory reference • LRU is not used very often • Instead, we will try to approximate LRU
  • 15. Replacement Hardware Support • Most system will simply provide a reference bit in PT for each page • On a reference to a page, this bit is set to 1 • This bit can be cleared by the OS • This simple hardware has lead to a variety of algorithms to approximate LRU
  • 16. Sampled LRU • Keep a reference byte for each page • At set time intervals, take an interrupt and get the OS involved – OS reads the reference bit for each page – reference bit is stuffed into the beginning byte for page – all the reference bits are then cleared • On page fault, replace the page with the smallest reference byte
  • 18. Clock Algorithm (Second Chance) • On page fault, search through pages • If a page’s reference bit is set to 1 – set its reference bit to zero and skip it (give it a second chance) • If a page’s reference bit is set to 0 – select this page for replacement • Always start the search from where the last search left off
  • 19. Clock Algorithm R 1 P6 R 1 P1 R 1 P7 R 0 P3 R 1 P9 R 0 P0 Pointer to first page to check •user refs P4 - not currently paged •start at P6 •check P6, P1, P7 and set their reference bits to zero (give them a second chance) •check P3 and notice its ref bit is 0 •Select P3 for replacement •Set pointer to P9 for next search 0 0 0 R 1 P4
  • 20. Dirty Pages • If a page has been written to, it is dirty • Before a dirty page can be replaced it must be written to disk • A clean page does not need to be written to disk – the copy on disk is already up-to-date • We would rather replace an old, clean page than and old, dirty page
  • 21. Modified Clock Algorithm • Very similar to Clock Algorithm • Instead of 2 states (ref’d and not ref’d) we will have 4 states – (0, 0) - not referenced clean – (0, 1) - not referenced dirty – (1, 0) - referenced but clean – (1, 1) - referenced and dirty • Order of preference for replacement goes in the order listed above
  • 22. Modified Clock Algorithm • Add a second bit to PT - dirty bit • Hardware sets this bit on write to a page • OS can clear this bit • Now just do clock algorithm and look for best page to replace • This method may require multiple passes through the list
  • 23. Page Buffering • It is expensive to wait for a dirty page to be written out • To get process started quickly, always keep a pool of free frames (buffers) • On a page fault – select a page to replace – write new page into a frame in the free pool – mark page table – restart the process – now write the dirty page out to disk – place frame holding replaced page in the free pool