Download - Page replacement
![Page 1: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/1.jpg)
Page Replacement
Sashikanta TaoremMTech – CSE1st Semester
Presented by:
![Page 2: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/2.jpg)
Overview
1. Why we need page replacement?
2. Basic page replacement technique.
3. Different type of page replacement algorithm and their examples.
![Page 3: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/3.jpg)
Why????
Limited physical memory --> limited number of frame --> limited number of frame allocated to a process.
![Page 4: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/4.jpg)
Basic Page Replacement
1. Find the location of the desired page on the disk.
2. Find a free frame If there is a free frame use it. No free frame – use page replacement algorithm to
select a victim frame. Write the victim frame to disk, change the frame and
page tables accordingly.
![Page 5: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/5.jpg)
Basic Page Replacement (Contd)
3. Read the desired page into the newly freed frame, change the page and frame tables.
4. Restart the user process.
![Page 6: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/6.jpg)
Page Replacement
Victim
Swap desirepage in
Reset pagetable for new page
Change toinvaid
Page table
FrameValid invalid bit
2
4
3
0F
I V
Swap outvictim page
1
Physical memory
![Page 7: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/7.jpg)
Overhead
If no free frames - 2 page transfers.
Solution : Modify bit or Dirty bit.
![Page 8: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/8.jpg)
Replacement Policy
Which page to be replaced?
Page removed should be the page least likely to be referenced in the near future.
Most policies predict the future behavior on the basis of past behavior.
![Page 9: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/9.jpg)
Page faults versus number of frames
Number of frames
Number of page faults
![Page 10: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/10.jpg)
Replacement Algorithm
1. FIFO page replacement
2. Optimal page replacement
3. LRU page replacement
4. LRU-Approximation page replacement
5. Counting-Based page replacement
![Page 11: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/11.jpg)
FIFO Page Replacement
Easy to understand and program.
Performance is not always good.
Belady’s Anomaly
![Page 12: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/12.jpg)
Drawbacks - FIFO
A page which is being accessed quite often may also get replaced because it arrived earlier than those present
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.
![Page 13: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/13.jpg)
FIFO – An Example
7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
707 7
01
201
231
230
430
420
423
023
013
012
712
702
701
![Page 14: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/14.jpg)
Optimal Page Replacement
Lowest page fault rate of all algorithms
Free from Belady’s anomaly
![Page 15: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/15.jpg)
Optimal Page Replacement (contd)
“Replace the page that will not be used for the longest period of time.”
Requires future knowledge of the reference string.
Used for comparison studies.
![Page 16: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/16.jpg)
OPR – An Example
7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
707 7
01
201
203
243
203
701
201
![Page 17: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/17.jpg)
LRU Page Replacement
Free from Belady’s Anomaly.
Problem: How to order the frame defined by the time of last use.
Solution: Counters Queue
![Page 18: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/18.jpg)
LRU – An Example
7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
707 7
01
201
203
4
3
4
23
2
03
701
04
20
231
201
![Page 19: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/19.jpg)
LRU – Approximation Page Replacement
Additional-Reference-Bits Algorithm
Second-Chance Algorithm
Enhanced Second-Chance Algorithm
![Page 20: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/20.jpg)
Additional-Reference-Bits Algorithm
Uses reference bit, initially at 0 ,after reference h/w updates it to 1.
We can use 8-bit byte as reference bits history.
At regular interval – 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.
![Page 21: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/21.jpg)
Additional-Reference-Bits Algorithm
Example:00000000 – page has not been use for eight time
period.
11111111 – use at least once in each time period.
11000100 is use more recently than 01110111
![Page 22: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/22.jpg)
Second-Chance Algorithm
Uses FIFO and a reference bit.
Implement using a circular queue.
Refer as CLOCK algorithm.
![Page 23: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/23.jpg)
![Page 24: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/24.jpg)
Enhanced Second-Chance Algorithm
Considers the Reference bit and the modify bit as an ordered pair, (Reference bit, Modify bit).
Four possible cases:1. (0,0) – neither recently used nor modified.
2. (0,1)
3. (1,0)
4. (1,1)
![Page 25: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/25.jpg)
Counting-Based Page Replacement
Uses COUNTERS to count the number of references that have been made to each page.
1. Least Frequently used
2. Most frequently Used
![Page 26: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/26.jpg)
Page-Buffering algorithm
Uses POOL of frames
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.
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.
![Page 27: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/27.jpg)
Objective Questions!!!
![Page 28: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/28.jpg)
Ans: C
1. Dirty bit is used to show the
a. page with corrupted data
b. the wrong page in the memory
c. page that is modified after being loaded into cache memory
d. page that is less frequently accessed.
![Page 29: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/29.jpg)
Ans: C
2. What replacement policy is used by Windows NT
a. LRU
b. NFU
c. FIFO
d. Clock Replacement
e. None of the above
![Page 30: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/30.jpg)
CLOCK algorithm
3. Second-Chance page replacement algorithm is also known as ………………
![Page 31: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/31.jpg)
Reference String
4. The string of memory references is called
___________.
![Page 32: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/32.jpg)
Belady’s Anomaly
5. FIFO page replacement suffers from
________________anomaly.
![Page 33: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/33.jpg)
Page fault increases with increase in number of frames.
6. What is Belady’s anomaly??
![Page 34: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/34.jpg)
TRUE
7. Optimal Page Replacement algorithm has the lowest page fault rate.
TRUE/FALSE
![Page 35: Page replacement](https://reader033.vdocument.in/reader033/viewer/2022061410/5562f9acd8b42a62598b4948/html5/thumbnails/35.jpg)
The reference bit and the modify bit
8. Enhanced Second-Chance algorithm uses
_____________and ___________ as an ordered pair.