Presentation is loading. Please wait.

Presentation is loading. Please wait.

9.4 Page Replacement What if there is no free frame?

Similar presentations


Presentation on theme: "9.4 Page Replacement What if there is no free frame?"— Presentation transcript:

1 9.4 Page Replacement What if there is no free frame?
Page replacement –find some page in memory, but not really in use, swap it out In this case, same page may be brought into memory several times

2 Basic Page Replacement

3 Page Replacement

4 Page Replacement Algorithms
Goal: Want lowest page-fault rate Evaluate algorithm by running it on a particular string of memory references (reference string) and computing the number of page faults on that string In all our examples, the reference string is 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

5 FIFO When a page must be replaced, the oldest page is chosen
In all our examples, the reference string is 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 3 frame (9 page faults) 4 frame (10 page faults) Notice that the number of faults for 4 frames is greater than the umber of faults for 3 frames!! This unexpected result is known as Belady’s anomaly

6 FIFO Illustrating Belady’s Anomaly

7 FIFO Algorithm

8 Optimal Page-Replacement Algorithm
Replace page that will not be used for longest period of time This is a design to guarantee the lowest page-fault rate for a fixed number of frames

9 Optimal Page-Replacement Algorithm

10 Optimal Page-Replacement Algorithm

11 Optimal Page-Replacement Algorithm
Unfortunately, the optimal page-replacement is difficult to implement, because it requires future knowledge of the reference string

12 Least-recently-used (LRU) algorithm
LRU replacement associates with each page the time of that page’s last use When a page must be replaced, LRU chooses the page that has not been used for the longest period of time

13 Least-recently-used (LRU) algorithm

14 Least-recently-used (LRU) algorithm

15 Least-recently-used (LRU) algorithm
The major problem is how to implement LRU replacement: Counter: whenever a reference to a page is made, the content of the clock register are copied to the time-of-use filed in the page table entry for the page. We replace the page with the smallest time value Stack: Whenever a page is referenced, it is removed from the stack and put on the top. In this way, the most recently used page is always at the top of the stack

16 Stack implementation

17 Stack implementation Note that both implementation of LRU requires hardware support If we were to use an interrupt for every reference to allow software to update such data, it would slow every memory reference

18 LRU Approximation Page Replacement
The system without hardware support provide some help for LRU, in a form of a reference bit Initially the bits are cleared (to 0) by the OS. As a user process executes, the bit associated with each page reference is set (to 1) by the hardware After a while, the clear step is activated In this method, although we can not get the order of page reference, we can know that whether the page is referenced or not

19 Second-Chance Algorithm
Basically, it’s a FIFO algorithm When a page has been selected, we inspect its reference bit. If the value is 0, we proceed to replace this page, otherwise, we give the page a second chance and move on to select the next FIFO page When a page get a second chance, it’s reference bit is cleared, and its arrival time is reset to the current time

20 Second-Chance Algorithm
When a page get a second chance, it’s reference bit is cleared, and its arrival time is reset to the current time If a page is used often enough to keep its reference bit set, it will never be replaced

21 Second-Chance Algorithm
One way to implement the second-chance algorithm is as a circular queue In the worst case, when all bits are set, the pointer cycles through the whole queue, giving each page a second chance Enhanced second-chance algorithm

22 Second-Chance Algorithm

23 Additional-Reference-Bits Algorithm
We can gain additional ordering information by recording the reference bits at regular intervals. We can keep 8-bit byte for each page in a table in memory The OS shifts the reference bit for each page into the high-order bit of its 8-bit byte, shifting the other bit right by 1 bit and discard the low-order bit

24 Additional-Reference-Bits Algorithm
For example: means the page has not been used for eight-time interval means a page that is used at least once in each period has used more recently with both value of and

25 Counting Based Page Replacement
Least Frequently used (LFU) page-replacement algorithm Most frequently used (MFU) page-replacement algorithm

26 Page Buffering Algorithm
We can keep some amount of frames (for example 3 frames) always free When a page fault occurs, the system does not have to wait the execution of replace algorithm. The system can load the page into free space and swapped out frames

27 Allocation of Frames When we have more than one processor, we need to allocate frames to each processor Two major algorithms: 1. equal allocation 2. proportional allocation

28 Allocation of Frames


Download ppt "9.4 Page Replacement What if there is no free frame?"

Similar presentations


Ads by Google