Tutorial 9
-
Upload
samuel-rivers -
Category
Documents
-
view
14 -
download
2
description
Transcript of Tutorial 9
Tutorial 9
Page Replacement Algorithms
In the following examples
• A frame with a value of 0 is empty. A frame shown with an “=” sign holds the same value as it held in the previous time period
First in first out (FIFO)• The reference string of pages is 123472512645• When a page must be replaced, the oldest page is chosen
– page faults: 11
1 2 3 4 7 2 5 1 2 6 4 5
1 = = = 7 = = = = 6 = =
0 2 = = = = 5 = = = 4 =
0 = 3 = = = = 1 = = = 5
0 = = 4 = = = = 2 = = =
Optimal• The reference string of pages is 123472512645• Replace the page that will not be used for the longest period of time
– page faults: 7
1 2 3 4 7 2 5 1 2 6 4 5
1 = = = = = = = = 6 = =
0 2 = = = = = = = = = =
0 = 3 = 7 = 5 = = = = =
0 = = 4 = = = = = = = =
Least recently used (LRU)• The reference string of pages is 123472512645• When a page must be replaced , LRU choses the page that has not been used for
the largest period of time
• page faults: 10
1 2 3 4 7 2 5 1 2 6 4 5
1 = = = 7 = = = = 6 = =
0 2 = = = = = = = = = =
0 = 3 = = = 5 = = = 4 =
0 = = 4 = = = 1 = = = 5
Second chance
When a page is used its use bit is set to 1. We also use a pointer to the next victim which is initialized to the first page/frame. When a page is loaded, it is set to point to the next frame. The list of pages is considered as a circular queue. When a page is considered for replacement, its use bit is examined. If it is zero [that page is replaced] otherwise [the use bit is set to zero, the next victim pointer is advanced, and the process repeated until a page is found with a zero use bit].
Second chance
– 9 page faults.
1 Bit 2 Bit 3 Bit 4 Bit 7 Bit 2 Bit 5 Bit 1 Bit 2 Bit 6 Bit 4 Bit 5 Bit1 1 1 1 1 1 1 1 7 1 7 1 7 1 7 1 7 1 6 1 6 1 6 1
2 1 2 1 2 1 2 0 2 1 2 0 2 0 2 1 2 0 4 1 4 13 1 3 1 3 0 3 0 5 1 5 1 5 1 5 0 5 0 5 1
4 1 4 0 4 0 4 0 1 1 1 1 1 0 1 0 1 0