Answer:
- 1. The initial value of the counters is: 0
- Counters are add 1 when each page frame replace a new page.(new page是指之前没有出现过的页面)
- Counters are minus 1 when the replaced page was not appeared.(也就是在之后的页面中都不再出现)
- Every time a new page need to replace page frame, first to determine all the page frames, select the current counter value is the smallest frame as a replacement pages, if there are multiple page frames of the same counter value, then select the page which first enter page frame as the replacement page.
- reference string: 1, 2, 3, 4, 5, 3, 4, 1, 6, 7, 8, 7, 8, 9, 7, 8, 9, 5, 4, 5, 4, 2
c represent counter
M represent Miss, also page fault
H represent Hit
Page frame1 |
1(M, c=1) |
1(c=1) |
1(c=1) |
1(c=1) |
5(M, c=2) |
5(c=2) |
5(c=2) |
5(c=1) |
5(c=1) |
5(c=1) |
Page frame2 |
|
2(M, c=1) |
2(c=1) |
2(c=1) |
2(c=1) |
2(c=1) |
2(c=1) |
2(c=1) |
2(c=1) |
2(c=1) |
Page frame3 |
|
|
3(M, c=1) |
3(c=1) |
3(c=1) |
3(H, c=0) |
3(c=0) |
1(M, c=0) |
6(M, c=0) |
7(M, c=1) |
Page frame4 |
|
|
|
4(M, c=1) |
4(c=1) |
4(c=1) |
4(H, c=1) |
4(c=1) |
4(c=1) |
4(c=1) |
Page frame1 |
5(c=1) |
5(c=1) |
5(c=1) |
5(c=1) |
5(c=1) |
5(c=1) |
5(c=1) |
5(H, c=1) |
5(c=1) |
5(H, c=0) |
Page frame2 |
8(c=2) |
8(c=2) |
8(H, c=2) |
8(c=2) |
8(c=2) |
8(H, c=1) |
8(c=1) |
8(c=1) |
8(c=1) |
8(c=1) |
Page frame3 |
7(M, c=1) |
7(H, c=1) |
7(c=1) |
7(c=1) |
7(H, c=0) |
7(c=0) |
7(c=0) |
7(c=0) |
4(M, c=0) |
4(c=0) |
Page frame4 |
4(c=1) |
4(c=1) |
4(c=1) |
9(M, c=2) |
9(c=2) |
9(c=2) |
9(H, c=1) |
9(c=1) |
9(c=1) |
9(c=1) |
Page frame1 |
5(c=0) |
2(M, c=0) |
|
|
|
|
|
|
|
|
Page frame2 |
8(c=1) |
8(c=1) |
|
|
|
|
|
|
|
|
Page frame3 |
4(H, c=0) |
4(c=0) |
|
|
|
|
|
|
|
|
Page frame4 |
9(c=1) |
9(c=1) |
|
|
|
|
|
|
|
|
So there are 12 page faults
Page frame1 |
1(M) |
1 |
1 |
1 |
1 |
1 |
1 |
1(H) |
6(M) |
6 |
Page frame2 |
|
2(M) |
2 |
2 |
5(M) |
5 |
5 |
5 |
5 |
5 |
Page frame3 |
|
|
3(M) |
3 |
3 |
3(H) |
3 |
3 |
3 |
7(M) |
Page frame4 |
|
|
|
4(M) |
4 |
4 |
4(H) |
4 |
4 |
4 |
Page frame1 |
8(M) |
8 |
8(H) |
8 |
8 |
8(H) |
8 |
8 |
4(M) |
4 |
Page frame2 |
5 |
5 |
5 |
5 |
5 |
5 |
5 |
5(H) |
5 |
5(H) |
Page frame3 |
7 |
7(H) |
7 |
7 |
7(H) |
7 |
7 |
7 |
7 |
7 |
Page frame4 |
4 |
4 |
4 |
9(M) |
9 |
9 |
9(H) |
9 |
9 |
9 |
Page frame1 |
4(H) |
4 |
|
|
|
|
|
|
|
|
Page frame2 |
5 |
2(M) |
|
|
|
|
|
|
|
|
Page frame3 |
7 |
7 |
|
|
|
|
|
|
|
|
Page frame4 |
9 |
9 |
|
|
|
|
|
|
|
|
So there are 11 page faults.