Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Page replacement


Published on

Operating System - Page replacement

Published in: Education

Page replacement

  1. 1. Page Replacement Sashikanta Taorem MTech – CSE 1 st Semester Presented by:
  2. 2. Overview <ul><li>Why we need page replacement? </li></ul><ul><li>Basic page replacement technique. </li></ul><ul><li>Different type of page replacement algorithm and their examples. </li></ul>
  3. 3. Why???? <ul><li>Limited physical memory --> limited number of frame --> limited number of frame allocated to a process. </li></ul>
  4. 4. Basic Page Replacement <ul><li>Find the location of the desired page on the disk. </li></ul><ul><li>Find a free frame </li></ul><ul><ul><ul><li>If there is a free frame use it. </li></ul></ul></ul><ul><ul><ul><li>No free frame – use page replacement algorithm to select a victim frame. </li></ul></ul></ul><ul><ul><ul><li>Write the victim frame to disk, change the frame and page tables accordingly. </li></ul></ul></ul>
  5. 5. Basic Page Replacement (Contd) <ul><li>3. Read the desired page into the newly freed frame, change the page and frame tables. </li></ul><ul><li>4. Restart the user process. </li></ul>
  6. 6. Page Replacement
  7. 7. Overhead <ul><li>If no free frames - 2 page transfers. </li></ul><ul><li>Solution : Modify bit or Dirty bit. </li></ul>
  8. 8. Replacement Policy <ul><li>Which page to be replaced? </li></ul><ul><li>Page removed should be the page least likely to be referenced in the near future. </li></ul><ul><li>Most policies predict the future behavior on the basis of past behavior. </li></ul>
  9. 9. Page faults versus number of frames <ul><li>Number of frames </li></ul>Number of page faults
  10. 10. Replacement Algorithm <ul><li>FIFO page replacement </li></ul><ul><li>Optimal page replacement </li></ul><ul><li>LRU page replacement </li></ul><ul><li>LRU-Approximation page replacement </li></ul><ul><li>Counting-Based page replacement </li></ul>
  11. 11. FIFO Page Replacement <ul><li>Easy to understand and program. </li></ul><ul><li>Performance is not always good. </li></ul><ul><li>Belady’s Anomaly </li></ul>
  12. 12. Drawbacks - FIFO <ul><li>A page which is being accessed quite often may also get replaced because it arrived earlier than those present </li></ul><ul><li>Ignores locality of reference. A page which was referenced last may also get replaced, although there is high probability that the same page may be needed again. </li></ul>
  13. 13. FIFO – An Example
  14. 14. Optimal Page Replacement <ul><li>Lowest page fault rate of all algorithms </li></ul><ul><li>Free from Belady’s anomaly </li></ul>
  15. 15. Optimal Page Replacement (contd) <ul><li>“Replace the page that will not be used for the longest period of time.” </li></ul><ul><li>Requires future knowledge of the reference string. </li></ul><ul><li>Used for comparison studies. </li></ul>
  16. 16. OPR – An Example
  17. 17. LRU Page Replacement <ul><li>Free from Belady’s Anomaly. </li></ul><ul><li>Problem: How to order the frame defined by the time of last use. </li></ul><ul><li>Solution: </li></ul><ul><ul><ul><li>Counters </li></ul></ul></ul><ul><ul><ul><li>Queue </li></ul></ul></ul>
  18. 18. LRU – An Example
  19. 19. LRU – Approximation Page Replacement <ul><li>Additional-Reference-Bits Algorithm </li></ul><ul><li>Second-Chance Algorithm </li></ul><ul><li>Enhanced Second-Chance Algorithm </li></ul>
  20. 20. Additional-Reference-Bits Algorithm <ul><li>Uses reference bit, initially at 0 ,after reference h/w updates it to 1. </li></ul><ul><li>We can use 8-bit byte as reference bits history. </li></ul><ul><li>At regular interval </li></ul><ul><ul><li>Shift the reference bit into the high-order bit of 8-bit byte, shifting the other bits right by 1 bit and discarding the low-order bit. </li></ul></ul>
  21. 21. Additional-Reference-Bits Algorithm <ul><li>Example: </li></ul><ul><ul><li>00000000 – page has not been use for eight time period. </li></ul></ul><ul><ul><li>11111111 – use at least once in each time period. </li></ul></ul><ul><ul><li>11000100 is use more recently than 01110111 </li></ul></ul>
  22. 22. Second-Chance Algorithm <ul><li>Uses FIFO and a reference bit. </li></ul><ul><li>Implement using a circular queue. </li></ul><ul><li>Refer as CLOCK algorithm. </li></ul>
  23. 24. Enhanced Second-Chance Algorithm <ul><li>Considers the Reference bit and the modify bit as an ordered pair, (Reference bit, Modify bit). </li></ul><ul><li>Four possible cases: </li></ul><ul><ul><ul><li>(0,0) – neither recently used nor modified. </li></ul></ul></ul><ul><ul><ul><li>(0,1) </li></ul></ul></ul><ul><ul><ul><li>(1,0) </li></ul></ul></ul><ul><ul><ul><li>(1,1) </li></ul></ul></ul>
  24. 25. Counting-Based Page Replacement <ul><li>Uses COUNTERS to count the number of references that have been made to each page. </li></ul><ul><li>Least Frequently used </li></ul><ul><li>Most frequently Used </li></ul>
  25. 26. Page-Buffering algorithm <ul><li>Uses POOL of frames </li></ul><ul><li>When a page fault occurs, a victim is chosen but the page is read into a free frame from the pool before the victim is written out. </li></ul><ul><li>When a page fault occurs, we first check whether the desire page is in the free-frame pool. If it is not, we must select a free frame and read into it. </li></ul>
  26. 27. Objective Questions!!!
  27. 28. Ans: C <ul><li>Dirty bit is used to show the </li></ul><ul><li>a. page with corrupted data </li></ul><ul><li>b. the wrong page in the memory </li></ul><ul><li>c. page that is modified after being loaded into cache memory </li></ul><ul><li>d. page that is less frequently accessed. </li></ul>
  28. 29. Ans: C <ul><li>2. What replacement policy is used by Windows NT </li></ul><ul><li>a. LRU </li></ul><ul><li>b. NFU </li></ul><ul><li>c. FIFO </li></ul><ul><li>d. Clock Replacement </li></ul><ul><li>e. None of the above </li></ul>
  29. 30. CLOCK algorithm <ul><li>3. Second-Chance page replacement algorithm is also known as ……………… </li></ul>
  30. 31. Reference String <ul><li>4. The string of memory references is called </li></ul><ul><li>___________. </li></ul>
  31. 32. Belady’s Anomaly <ul><li>5. FIFO page replacement suffers from </li></ul><ul><li>________________anomaly. </li></ul>
  32. 33. Page fault increases with increase in number of frames. <ul><li>6. What is Belady’s anomaly?? </li></ul>
  33. 34. TRUE <ul><li>7. Optimal Page Replacement algorithm has the lowest page fault rate. </li></ul><ul><li>TRUE/FALSE </li></ul>
  34. 35. The reference bit and the modify bit <ul><li>8. Enhanced Second-Chance algorithm uses </li></ul><ul><li>_____________and ___________ as an ordered pair. </li></ul>