Consider the following page reference string:
1,2,3,4,5,3,4,1,2,7,8,7,8,9,7,8,9,5,4,5. How many page faults would occur for the following replacement algorithm, assuming four frames:
a) FIFO
b) LRU
a) FIFO (First In First Out) algorithm:
Using the FIFO algorithm with four frames and the given page reference string, the page faults occur as follows:
Page | Frame 0 | Frame 1 | Frame 2 | Frame 3 | Page Fault? |
---|---|---|---|---|---|
1 | 1 | Yes | |||
2 | 1 | 2 | Yes | ||
3 | 1 | 2 | 3 | Yes | |
4 | 1 | 2 | 3 | 4 | Yes |
5 | 5 | 2 | 3 | 4 | Yes |
3 | 5 | 2 | 3 | 4 | No |
4 | 5 | 2 | 3 | 4 | No |
1 | 5 | 2 | 3 | 4 | No |
2 | 5 | 2 | 3 | 4 | No |
7 | 5 | 7 | 3 | 4 | Yes |
8 | 5 | 7 | 8 | 4 | Yes |
7 | 5 | 7 | 8 | 4 | No |
8 | 5 | 7 | 8 | 4 | No |
9 | 5 | 7 | 8 | 9 | Yes |
7 | 5 | 7 | 8 | 9 | No |
8 | 5 | 7 | 8 | 9 | No |
9 | 5 | 7 | 8 | 9 | No |
5 | 5 | 7 | 8 | 9 | No |
4 | 5 | 4 | 8 | 9 | Yes |
5 | 5 | 4 | 8 | 9 | No |
Therefore, the total number of page faults is 9.
b) LRU (Least Recently Used) algorithm:
Using the LRU algorithm with four frames and the given page reference string, the page faults occur as follows:
Page | Frame 0 | Frame 1 | Frame 2 | Frame 3 | Page Fault? |
---|---|---|---|---|---|
1 | 1 | Yes | |||
2 | 1 | 2 | Yes | ||
3 | 1 | 2 | 3 | Yes | |
4 | 1 | 2 | 3 | 4 | Yes |
5 | 5 | 2 | 3 | 4 | Yes |
3 | 5 | 2 | 3 | 4 | No |
4 | 5 | 2 | 3 | 4 | No |
1 | 1 | 2 | 3 | 4 | Yes |
2 | 1 | 2 | 3 | 4 | No |
7 | 1 | 2 | 7 | 4 | Yes |
8 | 1 | 2 | 7 | 8 | Yes |
7 | 1 | 2 | 7 | 8 | No |
8 | 1 | 2 | 7 | 8 | No |
9 | 1 | 2 | 7 | 9 | Yes |
7 | 1 | 2 | 7 | 9 | No |
8 | 1 | 2 | 8 | 9 | Yes |
9 | 1 | 2 | 8 | 9 | No |
5 | 1 | 2 | 5 | 9 | Yes |
4 | 1 | 2 | 5 | 4 | Yes |
5 | 1 | 2 | 5 | 4 | No |
Therefore, the total number of page faults is 10.