Many of the online introduction of 3 page replacement algorithm example and process is not correct, this article according to "operating system concept" in the seventh edition of three algorithms are introduced, and give the correct example to verify the algorithm.
FIFO first-out page replacement algorithm, create a FIFO queue to manage all the pages in memory. It is best to write out the queue for each page schedule when calculating the paging rate, so it is not easy to make mistakes.
The following examples illustrate:
Suppose the page frame is 3 and the reference string is: 7,0,1,2,0,3,0,4,2
Page direction: 7,0,1,2,0,3,0,4,2,
-----------------------------------------------
Physical pages: 7,7,7,2,2,2,2,4,4,
0,0,0,0,3,3,3,2,
1,1,1,1,0,0,0,
FIFO queue: 7, 7,7,0,0,1,2,3,0,
0,0,1,1,2,3,0,4,
1,2,2,3,0,4,2,
First 7,0,1 page into the page frame, the queue becomes 7,0,1, the next reference 2 to dial in, then the queue head of the 7 out of line, the queue becomes 0,1,2, the physical page will be 7 to 2, the next reference 0, already exists in the page frame, the queue is unchanged, the next 3, queue header 0 out of the queue, 3 into the tail The queue changes to 0, and the page frame changes to 3. Follow the same sequence.
Second, LRU is least recently used least recently used algorithm (to be updated)
Third, opt is the best page replacement algorithm (pending update)
Here are some examples and answers, according to the above algorithm to verify the correctness of the scheduling algorithm.
1, in a request paging system, if a job of the page direction: 1,2,3,6,4,7,3,2,1,4,7,5,6,5,2,1. When the number of physical blocks assigned to the job is 4 o'clock, the optimal permutation algorithm, LRU and FIFO page substitution algorithms are used to calculate the number of pages and the rate of missing pages in the access process.
A: The best permutation algorithm is the following table
Page trend |
1 |
2 |
3 |
6 |
4 |
7 |
3 |
2 |
1 |
4 |
7 |
5 |
6 |
5 |
2 |
1 |
Physical page 0 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
Physical Page 1 |
|
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
Physical Page 2 |
|
|
3 |
3 |
3 |
3 |
3 |
3 |
3 |
4 |
4 |
5 |
5 |
5 |
5 |
5 |
Physical Page 3 |
|
|
|
6 |
4 |
7 |
7 |
7 |
7 |
7 |
7 |
7 |
6 |
6 |
6 |
6 |
Pages No |
Y |
Y |
Y |
Y |
Y |
Y |
N |
N |
N |
Y |
N |
Y |
Y |
N |
N |
N |
The number of pages is 9, the fault rate is 9/16
The LRU algorithm is shown in the following table:
Page trend |
1 |
2 |
3 |
6 |
4 |
7 |
3 |
2 |
1 |
4 |
7 |
5 |
6 |
5 |
2 |
1 |
Physical page 0 |
1 |
1 |
1 |
1 |
4 |
4 |
4 |
4 |
1 |
1 |
1 |
1 |
6 |
6 |
6 |
6 |
Physical Page 1 |
|
2 |
2 |
2 |
2 |
7 |
7 |
7 |
7 |
4 |
4 |
4 |
4 |
4 |
2 |
2 |
Physical Page 2 |
|
|
3 |
3 |
3 |
3 |
3 |
3 |
3 |
3 |
7 |
7 |
7 |
7 |
7 |
1 |
Physical Page 3 |
|
|
|
6 |
6 |
6 |
6 |
2 |
2 |
2 |
2 |
5 |
5 |
5 |
5 |
5 |
Pages No |
Y |
Y |
Y |
Y |
Y |
Y |
N |
Y |
Y |
Y |
Y |
Y |
Y |
N |
Y |
Y |
The number of pages is 14, the fault rate is 14/16
The FIFO algorithm is shown in the following table:
Page orientation |
1 |
2 |
3 |
6 |
4 |
7 |
3 |
2 |
1 |
4 |
7 |
5 |
6 |
5 |
2 |
1 |
Physical page 0 |
1 |
1 |
1 |
1 |
4 |
P>4 |
4 |
4 |
4 |
4 |
4 |
5 |
5 |
5 |
5 |
5 |
Physical page 1 |
< |