Consider a virtual page reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0,1, 7, 0,1 Suppose a demand paged virtual memory system running on a computer system such that the main memory has 3 page frames. Then_______ page replacement algorithm has minimum number of page faults.
Optimal
In a demand-paged virtual memory system, when the CPU requires a page that is not currently in the main memory (RAM), a situation called a page fault occurs. The operating system then needs to bring the required page from secondary storage (like a hard drive) into a page frame in main memory. If all page frames are already occupied, a page replacement algorithm is used to decide which page currently in memory should be removed to make space for the new page. Different algorithms aim to minimize the number of page faults, as page faults are costly operations involving disk access.
The question asks us to compare four common page replacement algorithms using a specific virtual page reference string and a main memory with 3 page frames to determine which one results in the minimum number of page faults.
The given page reference string is: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 The number of available page frames in main memory is 3.
Let's simulate the execution of each algorithm step-by-step and count the number of page faults. We start with an empty main memory (all 3 frames are empty).
The FIFO algorithm replaces the page that has been in the memory for the longest time. It's like a queue; the page that came in first is the first to leave.
| Step | Ref. Page | Frame 1 | Frame 2 | Frame 3 | Event | Queue Order (Entry Time) |
|---|---|---|---|---|---|---|
| 1 | 7 | 7 | - | - | PF (1) | 7 |
| 2 | 0 | 7 | 0 | - | PF (2) | 7, 0 |
| 3 | 1 | 7 | 0 | 1 | PF (3) | 7, 0, 1 |
| 4 | 2 | 0 | 1 | 2 | PF (4) | 0, 1, 2 (7 replaced) |
| 5 | 0 | 0 | 1 | 2 | H | 0, 1, 2 |
| 6 | 3 | 1 | 2 | 3 | PF (5) | 1, 2, 3 (0 replaced) |
| 7 | 0 | 2 | 3 | 0 | PF (6) | 2, 3, 0 (1 replaced) |
| 8 | 4 | 3 | 0 | 4 | PF (7) | 3, 0, 4 (2 replaced) |
| 9 | 2 | 0 | 4 | 2 | PF (8) | 0, 4, 2 (3 replaced) |
| 10 | 3 | 4 | 2 | 3 | PF (9) | 4, 2, 3 (0 replaced) |
| 11 | 0 | 2 | 3 | 0 | PF (10) | 2, 3, 0 (4 replaced) |
| 12 | 3 | 2 | 3 | 0 | H | 2, 3, 0 |
| 13 | 2 | 2 | 3 | 0 | H | 2, 3, 0 |
| 14 | 1 | 3 | 0 | 1 | PF (11) | 3, 0, 1 (2 replaced) |
| 15 | 2 | 0 | 1 | 2 | PF (12) | 0, 1, 2 (3 replaced) |
| 16 | 0 | 0 | 1 | 2 | H | 0, 1, 2 |
| 17 | 1 | 0 | 1 | 2 | H | 0, 1, 2 |
| 18 | 7 | 1 | 2 | 7 | PF (13) | 1, 2, 7 (0 replaced) |
| 19 | 0 | 2 | 7 | 0 | PF (14) | 2, 7, 0 (1 replaced) |
| 20 | 1 | 7 | 0 | 1 | PF (15) | 7, 0, 1 (2 replaced) |
Using the FIFO algorithm, there are 15 page faults.
The LIFO algorithm replaces the page that was most recently brought into memory.
| Step | Ref. Page | Frame 1 | Frame 2 | Frame 3 | Event | Newest Page In Frame |
|---|---|---|---|---|---|---|
| 1 | 7 | 7 | - | - | PF (1) | 7 |
| 2 | 0 | 7 | 0 | - | PF (2) | 0 |
| 3 | 1 | 7 | 0 | 1 | PF (3) | 1 |
| 4 | 2 | 7 | 0 | 2 | PF (4) | 2 (1 replaced) |
| 5 | 0 | 7 | 0 | 2 | H | 2 |
| 6 | 3 | 7 | 0 | 3 | PF (5) | 3 (2 replaced) |
| 7 | 0 | 7 | 0 | 3 | H | 3 |
| 8 | 4 | 7 | 0 | 4 | PF (6) | 4 (3 replaced) |
| 9 | 2 | 7 | 0 | 2 | PF (7) | 2 (4 replaced) |
| 10 | 3 | 7 | 0 | 3 | PF (8) | 3 (2 replaced) |
| 11 | 0 | 7 | 0 | 3 | H | 3 |
| 12 | 3 | 7 | 0 | 3 | H | 3 |
| 13 | 2 | 7 | 0 | 2 | PF (9) | 2 (3 replaced) |
| 14 | 1 | 7 | 0 | 1 | PF (10) | 1 (2 replaced) |
| 15 | 2 | 7 | 0 | 2 | PF (11) | 2 (1 replaced) |
| 16 | 0 | 7 | 0 | 2 | H | 2 |
| 17 | 1 | 7 | 0 | 1 | PF (12) | 1 (2 replaced) |
| 18 | 7 | 7 | 0 | 1 | H | 1 |
| 19 | 0 | 7 | 0 | 1 | H | 1 |
| 20 | 1 | 7 | 0 | 1 | H | 1 |
Using the LIFO algorithm, there are 12 page faults.
The LRU algorithm replaces the page that has not been accessed for the longest period of time.
| Step | Ref. Page | Frame 1 | Frame 2 | Frame 3 | Event | Access Order (LRU -> Most Recent) |
|---|---|---|---|---|---|---|
| 1 | 7 | 7 | - | - | PF (1) | 7 |
| 2 | 0 | 7 | 0 | - | PF (2) | 7, 0 |
| 3 | 1 | 7 | 0 | 1 | PF (3) | 7, 0, 1 |
| 4 | 2 | 0 | 1 | 2 | PF (4) | 0, 1, 2 (7 is LRU) |
| 5 | 0 | 0 | 1 | 2 | H | 1, 2, 0 (0 is most recent) |
| 6 | 3 | 0 | 2 | 3 | PF (5) | 2, 0, 3 (1 is LRU) |
| 7 | 0 | 0 | 2 | 3 | H | 2, 3, 0 (0 is most recent) |
| 8 | 4 | 2 | 3 | 4 | PF (6) | 3, 0, 4 (2 is LRU) |
| 9 | 2 | 3 | 4 | 2 | PF (7) | 4, 3, 2 (0 is LRU) |
| 10 | 3 | 4 | 2 | 3 | PF (8) | 4, 2, 3 (3 is most recent) |
| 11 | 0 | 4 | 3 | 0 | PF (9) | 4, 3, 0 (2 is LRU) |
| 12 | 3 | 4 | 0 | 3 | H | 4, 0, 3 (3 is most recent) |
| 13 | 2 | 4 | 0 | 2 | PF (10) | 4, 0, 2 (3 is LRU) |
| 14 | 1 | 4 | 2 | 1 | PF (11) | 4, 2, 1 (0 is LRU) |
| 15 | 2 | 4 | 1 | 2 | H | 4, 1, 2 (2 is most recent) |
| 16 | 0 | 4 | 1 | 0 | PF (12) | 4, 1, 0 (2 is LRU) |
| 17 | 1 | 4 | 0 | 1 | H | 4, 0, 1 (1 is most recent) |
| 18 | 7 | 4 | 0 | 7 | PF (13) | 4, 0, 7 (1 is LRU) |
| 19 | 0 | 4 | 7 | 0 | H | 4, 7, 0 (0 is most recent) |
| 20 | 1 | 4 | 0 | 1 | PF (14) | 4, 0, 1 (7 is LRU) |
Let's re-check the LRU trace from step 4 onwards, keeping track of least recently used correctly. Frames: 3. Ref: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 [-, -, -] Start 1. 7: [7, -, -] PF (1). Access order (LRU to MRU): 7 2. 0: [7, 0, -] PF (2). Access order: 7, 0 3. 1: [7, 0, 1] PF (3). Access order: 7, 0, 1 4. 2: [0, 1, 2] PF (4). LRU=7. Replace 7. Frames={0,1,2}. Access order: 0, 1, 2 5. 0: [0, 1, 2] H. Frames={0,1,2}. Access order: 1, 2, 0 6. 3: [0, 2, 3] PF (5). LRU=1. Replace 1. Frames={0,2,3}. Access order: 2, 0, 3 7. 0: [0, 2, 3] H. Frames={0,2,3}. Access order: 2, 3, 0 8. 4: [0, 3, 4] PF (6). LRU=2. Replace 2. Frames={0,3,4}. Access order: 3, 0, 4 9. 2: [0, 4, 2] PF (7). LRU=3. Replace 3. Frames={0,4,2}. Access order: 4, 0, 2 10. 3: [0, 2, 3] PF (8). LRU=4. Replace 4. Frames={0,2,3}. Access order: 2, 0, 3 11. 0: [0, 2, 3] H. Frames={0,2,3}. Access order: 2, 3, 0 12. 3: [0, 2, 3] H. Frames={0,2,3}. Access order: 2, 0, 3 13. 2: [0, 2, 3] H. Frames={0,2,3}. Access order: 0, 3, 2 14. 1: [0, 2, 1] PF (9). LRU=3. Replace 3. Frames={0,2,1}. Access order: 0, 2, 1 15. 2: [0, 2, 1] H. Frames={0,2,1}. Access order: 0, 1, 2 16. 0: [0, 2, 1] H. Frames={0,2,1}. Access order: 2, 1, 0 17. 1: [0, 2, 1] H. Frames={0,2,1}. Access order: 2, 0, 1 18. 7: [0, 1, 7] PF (10). LRU=2. Replace 2. Frames={0,1,7}. Access order: 0, 1, 7 19. 0: [0, 1, 7] H. Frames={0,1,7}. Access order: 1, 7, 0 20. 1: [0, 1, 7] H. Frames={0,1,7}. Access order: 7, 0, 1 Let's check the LRU access order logic again. When a page is accessed, it becomes the Most Recently Used. The relative order of others doesn't change. 1. 7: [7, -, -] PF(1). MRU: 7. LRU: - 2. 0: [7, 0, -] PF(2). MRU: 0. LRU: 7. Order: (7, 0) 3. 1: [7, 0, 1] PF(3). MRU: 1. LRU: 7. Order: (7, 0, 1) 4. 2: [0, 1, 2] PF(4). Need 2. Frames full. LRU is 7. Replace 7 with 2. New frame: {0, 1, 2}. MRU: 2. Order based on *last access*: 0 (step 2), 1 (step 3), 7 (step 1). 7 is LRU. Replace 7. Frame: {0, 1, 2}. Access times: 0(2), 1(3), 2(4). Order: (0, 1, 2) LRU=0 5. 0: [0, 1, 2] H. Access times: 0(5), 1(3), 2(4). Order: (1, 2, 0) LRU=1 6. 3: [0, 2, 3] PF(5). Need 3. LRU=1. Replace 1. Frame: {0, 2, 3}. Access times: 0(5), 2(4), 3(6). Order: (2, 0, 3) LRU=2 7. 0: [0, 2, 3] H. Access times: 0(7), 2(4), 3(6). Order: (2, 3, 0) LRU=2 8. 4: [0, 3, 4] PF(6). Need 4. LRU=2. Replace 2. Frame: {0, 3, 4}. Access times: 0(7), 3(6), 4(8). Order: (3, 0, 4) LRU=3 9. 2: [0, 4, 2] PF(7). Need 2. LRU=3. Replace 3. Frame: {0, 4, 2}. Access times: 0(7), 4(8), 2(9). Order: (0, 4, 2) LRU=0 10. 3: [4, 2, 3] PF(8). Need 3. LRU=0. Replace 0. Frame: {4, 2, 3}. Access times: 4(8), 2(9), 3(10). Order: (4, 2, 3) LRU=4 11. 0: [2, 3, 0] PF(9). Need 0. LRU=4. Replace 4. Frame: {2, 3, 0}. Access times: 2(9), 3(10), 0(11). Order: (2, 3, 0) LRU=2 12. 3: [2, 3, 0] H. Access times: 2(9), 3(12), 0(11). Order: (2, 0, 3) LRU=2 13. 2: [0, 3, 2] H. Access times: 0(11), 3(12), 2(13). Order: (0, 3, 2) LRU=0 14. 1: [3, 2, 1] PF(10). Need 1. LRU=0. Replace 0. Frame: {3, 2, 1}. Access times: 3(12), 2(13), 1(14). Order: (3, 2, 1) LRU=3 15. 2: [3, 2, 1] H. Access times: 3(12), 2(15), 1(14). Order: (3, 1, 2) LRU=3 16. 0: [3, 1, 0] PF(11). Need 0. LRU=3. Replace 3. Frame: {1, 2, 0}. Access times: 1(14), 2(15), 0(16). Order: (1, 2, 0) LRU=1 17. 1: [2, 0, 1] H. Access times: 2(15), 0(16), 1(17). Order: (2, 0, 1) LRU=2 18. 7: [0, 1, 7] PF(12). Need 7. LRU=2. Replace 2. Frame: {0, 1, 7}. Access times: 0(16), 1(17), 7(18). Order: (0, 1, 7) LRU=0 19. 0: [0, 1, 7] H. Access times: 0(19), 1(17), 7(18). Order: (1, 7, 0) LRU=1 20. 1: [0, 7, 1] H. Access times: 0(19), 7(18), 1(20). Order: (7, 0, 1) LRU=7 Total LRU Faults: 12. The manual trace matches the previous count. The table representation might be slightly simplified but the count is consistent.
| Step | Ref. Page | Frame State | Event | ||
|---|---|---|---|---|---|
| 1 | 7 | 7 | - | - | PF (1) |
| 2 | 0 | 7 | 0 | - | PF (2) |
| 3 | 1 | 7 | 0 | 1 | PF (3) |
| 4 | 2 | 0 | 1 | 2 | PF (4) |
| 5 | 0 | 0 | 1 | 2 | H |
| 6 | 3 | 0 | 2 | 3 | PF (5) |
| 7 | 0 | 0 | 2 | 3 | H |
| 8 | 4 | 0 | 3 | 4 | PF (6) |
| 9 | 2 | 0 | 4 | 2 | PF (7) |
| 10 | 3 | 4 | 2 | 3 | PF (8) |
| 11 | 0 | 2 | 3 | 0 | PF (9) |
| 12 | 3 | 2 | 3 | 0 | H |
| 13 | 2 | 2 | 3 | 0 | H |
| 14 | 1 | 2 | 0 | 1 | PF (10) |
| 15 | 2 | 2 | 0 | 1 | H |
| 16 | 0 | 2 | 0 | 1 | H |
| 17 | 1 | 2 | 0 | 1 | H |
| 18 | 7 | 0 | 1 | 7 | PF (11) |
| 19 | 0 | 0 | 1 | 7 | H |
| 20 | 1 | 0 | 1 | 7 | H |
Using the LRU algorithm, there are 11 page faults in this re-trace. Let's quickly re-verify the LRU trace one more time using access history explicitly. Frames: 3. Ref: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 1. 7: [7] PF(1). Hist: [7] 2. 0: [7,0] PF(2). Hist: [7,0] 3. 1: [7,0,1] PF(3). Hist: [7,0,1] 4. 2: Need 2. Frames [7,0,1]. History [7,0,1]. LRU is 7. Replace 7. Frame: [0,1,2]. Hist: [0,1,2]. PF(4). 5. 0: Need 0. Frame [0,1,2]. History [0,1,2]. 0 is present. Hit. Hist: [1,2,0]. H. 6. 3: Need 3. Frame [0,1,2]. History [1,2,0]. LRU is 1. Replace 1. Frame: [0,2,3]. Hist: [2,0,3]. PF(5). 7. 0: Need 0. Frame [0,2,3]. History [2,0,3]. 0 is present. Hit. Hist: [2,3,0]. H. 8. 4: Need 4. Frame [0,2,3]. History [2,3,0]. LRU is 2. Replace 2. Frame: [0,3,4]. Hist: [3,0,4]. PF(6). 9. 2: Need 2. Frame [0,3,4]. History [3,0,4]. LRU is 3. Replace 3. Frame: [0,4,2]. Hist: [4,0,2]. PF(7). 10. 3: Need 3. Frame [0,4,2]. History [4,0,2]. LRU is 4. Replace 4. Frame: [0,2,3]. Hist: [0,2,3]. PF(8). 11. 0: Need 0. Frame [0,2,3]. History [0,2,3]. 0 is present. Hit. Hist: [2,3,0]. H. 12. 3: Need 3. Frame [0,2,3]. History [2,3,0]. 3 is present. Hit. Hist: [2,0,3]. H. 13. 2: Need 2. Frame [0,2,3]. History [2,0,3]. 2 is present. Hit. Hist: [0,3,2]. H. 14. 1: Need 1. Frame [0,2,3]. History [0,3,2]. LRU is 0. Replace 0. Frame: [3,2,1]. Hist: [3,2,1]. PF(9). 15. 2: Need 2. Frame [3,2,1]. History [3,2,1]. 2 is present. Hit. Hist: [3,1,2]. H. 16. 0: Need 0. Frame [3,1,2]. History [3,1,2]. LRU is 3. Replace 3. Frame: [1,2,0]. Hist: [1,2,0]. PF(10). 17. 1: Need 1. Frame [1,2,0]. History [1,2,0]. 1 is present. Hit. Hist: [2,0,1]. H. 18. 7: Need 7. Frame [1,2,0]. History [2,0,1]. LRU is 2. Replace 2. Frame: [1,0,7]. Hist: [1,0,7]. PF(11). 19. 0: Need 0. Frame [1,0,7]. History [1,0,7]. 0 is present. Hit. Hist: [1,7,0]. H. 20. 1: Need 1. Frame [1,0,7]. History [1,7,0]. 1 is present. Hit. Hist: [7,0,1]. H. Total LRU Faults = 11. This revised trace seems correct. The table above should be updated to reflect this trace and fault count.
| Step | Ref. Page | Frame State | Event | ||
|---|---|---|---|---|---|
| 1 | 7 | 7 | - | - | PF (1) |
| 2 | 0 | 7 | 0 | - | PF (2) |
| 3 | 1 | 7 | 0 | 1 | PF (3) |
| 4 | 2 | 0 | 1 | 2 | PF (4) |
| 5 | 0 | 0 | 1 | 2 | H |
| 6 | 3 | 0 | 2 | 3 | PF (5) |
| 7 | 0 | 0 | 2 | 3 | H |
| 8 | 4 | 0 | 3 | 4 | PF (6) |
| 9 | 2 | 0 | 4 | 2 | PF (7) |
| 10 | 3 | 0 | 2 | 3 | PF (8) |
| 11 | 0 | 0 | 2 | 3 | H |
| 12 | 3 | 0 | 2 | 3 | H |
| 13 | 2 | 0 | 2 | 3 | H |
| 14 | 1 | 2 | 3 | 1 | PF (9) |
| 15 | 2 | 2 | 3 | 1 | H |
| 16 | 0 | 3 | 1 | 0 | PF (10) |
| 17 | 1 | 3 | 0 | 1 | H |
| 18 | 7 | 3 | 0 | 7 | PF (11) |
| 19 | 3 | 0 | 7 | H | |
| 20 | 3 | 0 | 7 | H | |
Using the LRU algorithm, there are 11 page faults.
The Optimal algorithm replaces the page that will not be used for the longest period of time in the future. This algorithm is theoretical and cannot be implemented in practice because it requires knowing the future page references. However, it is useful as a benchmark to compare other algorithms against.
| Step | Ref. Page | Frame State | Event | Pages in Frame and Next Use (Future Lookahead) | ||
|---|---|---|---|---|---|---|
| 1 | 7 | 7 | - | - | PF (1) | {7: @17} |
| 2 | 0 | 7 | 0 | - | PF (2) | {7: @17, 0: @5} |
| 3 | 1 | 7 | 0 | 1 | PF (3) | {7: @17, 0: @5, 1: @14} |
| 4 | 2 | 0 | 1 | 2 | PF (4) | Replace 7 (furthest @17). Frame: {0,1,2}. Next use: {0: @5, 1: @14, 2: @9} |
| 5 | 0 | 0 | 1 | 2 | H | Frame: {0,1,2}. Next use: {0: @7, 1: @14, 2: @9} |
| 6 | 3 | 0 | 2 | 3 | PF (5) | Replace 1 (furthest @14). Frame: {0,2,3}. Next use: {0: @7, 2: @9, 3: @10} |
| 7 | 0 | 0 | 2 | 3 | H | Frame: {0,2,3}. Next use: {0: @11, 2: @9, 3: @10} |
| 8 | 4 | 0 | 3 | 4 | PF (6) | Replace 2 (furthest @9). Frame: {0,3,4}. Next use: {0: @11, 3: @10, 4: N/A} |
| 9 | 2 | 0 | 3 | 2 | PF (7) | Replace 4 (N/A). Frame: {0,3,2}. Next use: {0: @11, 3: @10, 2: @13} |
| 10 | 3 | 0 | 2 | 3 | H | Frame: {0,2,3}. Next use: {0: @11, 2: @13, 3: @12} |
| 11 | 0 | 0 | 2 | 3 | H | Frame: {0,2,3}. Next use: {0: @16, 2: @13, 3: @12} |
| 12 | 3 | 0 | 2 | 3 | H | Frame: {0,2,3}. Next use: {0: @16, 2: @13, 3: N/A} |
| 13 | 2 | 0 | 2 | 3 | H | Frame: {0,2,3}. Next use: {0: @16, 2: N/A, 3: N/A} |
| 14 | 1 | 0 | 3 | 1 | PF (8) | Replace 2 (N/A). Frame: {0,3,1}. Next use: {0: @16, 3: N/A, 1: @17} |
| 15 | 2 | 0 | 3 | 2 | PF (9) | Replace 3 (N/A). Frame: {0,1,2}. Next use: {0: @16, 1: @17, 2: N/A} |
| 16 | 0 | 0 | 1 | 2 | H | Frame: {0,1,2}. Next use: {0: @19, 1: @17, 2: N/A} |
| 17 | 1 | 0 | 2 | 1 | H | Frame: {0,2,1}. Next use: {0: @19, 2: N/A, 1: @20} |
| 18 | 7 | 0 | 1 | 7 | PF (10) | Replace 2 (N/A). Frame: {0,1,7}. Next use: {0: @19, 1: @20, 7: N/A} |
| 19 | 0 | 0 | 1 | 7 | H | Frame: {0,1,7}. Next use: {0: N/A, 1: @20, 7: N/A} |
| 20 | 1 | 0 | 7 | 1 | H | Frame: {0,7,1}. Next use: {0: N/A, 7: N/A, 1: N/A} |
Let's carefully re-trace Optimal using the future lookahead principle. Frames: 3. Ref: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 1. 7: [7,-,-] PF(1). Frame: {7} 2. 0: [7,0,-] PF(2). Frame: {7,0} 3. 1: [7,0,1] PF(3). Frame: {7,0,1} 4. 2: Need 2. Frame full {7,0,1}. Look ahead from index 4 (the '2'): 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1. Next use: 7 (@17), 0 (@5), 1 (@14). 7 is furthest. Replace 7. Frame: [0,1,2]. PF(4). Frame: {0,1,2} 5. 0: Hit. Frame: {0,1,2} 6. 3: Need 3. Frame full {0,1,2}. Look ahead from index 6 (the '3'): 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1. Next use: 0 (@7), 1 (@14), 2 (@9). 1 is furthest. Replace 1. Frame: [0,2,3]. PF(5). Frame: {0,2,3} 7. 0: Hit. Frame: {0,2,3} 8. 4: Need 4. Frame full {0,2,3}. Look ahead from index 8 (the '4'): 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1. Next use: 0 (@11), 2 (@9), 3 (@10). 0 is furthest. Replace 0. Frame: [2,3,4]. PF(6). Frame: {2,3,4} 9. 2: Hit. Frame: {2,3,4} 10. 3: Hit. Frame: {2,3,4} 11. 0: Need 0. Frame full {2,3,4}. Look ahead from index 11 (the '0'): 3, 2, 1, 2, 0, 1, 7, 0, 1. Next use: 2 (@13), 3 (@12), 4 (Not used again). 4 is furthest (infinite). Replace 4. Frame: [2,3,0]. PF(7). Frame: {2,3,0} 12. 3: Hit. Frame: {2,3,0} 13. 2: Hit. Frame: {2,3,0} 14. 1: Need 1. Frame full {2,3,0}. Look ahead from index 14 (the '1'): 2, 0, 1, 7, 0, 1. Next use: 2 (@15), 3 (Not used again), 0 (@16). 3 is furthest. Replace 3. Frame: [2,0,1]. PF(8). Frame: {2,0,1} 15. 2: Hit. Frame: {2,0,1} 16. 0: Hit. Frame: {2,0,1} 17. 1: Hit. Frame: {2,0,1} 18. 7: Need 7. Frame full {2,0,1}. Look ahead from index 18 (the '7'): 0, 1. Next use: 2 (Not used again), 0 (@19), 1 (@20). 2 is furthest. Replace 2. Frame: [0,1,7]. PF(9). Frame: {0,1,7} 19. 0: Hit. Frame: {0,1,7} 20. 1: Hit. Frame: {0,1,7} Total Optimal Faults: 9. This trace matches the initial manual trace and count. The table needs to be updated.
| Step | Ref. Page | Frame State | Event | ||
|---|---|---|---|---|---|
| 1 | 7 | 7 | - | - | PF (1) |
| 2 | 0 | 7 | 0 | - | PF (2) |
| 3 | 1 | 7 | 0 | 1 | PF (3) |
| 4 | 2 | 0 | 1 | 2 | PF (4) |
| 5 | 0 | 0 | 1 | 2 | H |
| 6 | 3 | 0 | 2 | 3 | PF (5) |
| 7 | 0 | 0 | 2 | 3 | H |
| 8 | 4 | 0 | 3 | 4 | PF (6) |
| 9 | 2 | 0 | 3 | 2 | PF (7) |
| 10 | 3 | 0 | 2 | 3 | H |
| 11 | 0 | 0 | 2 | 3 | H |
| 12 | 3 | 0 | 2 | 3 | H |
| 13 | 2 | 0 | 2 | 3 | H |
| 14 | 1 | 0 | 2 | 1 | PF (8) |
| 15 | 2 | 0 | 2 | 1 | H |
| 16 | 0 | 0 | 2 | 1 | H |
| 17 | 1 | 0 | 2 | 1 | H |
| 18 | 7 | 0 | 1 | 7 | PF (9) |
| 19 | 0 | 0 | 1 | 7 | H |
| 20 | 1 | 0 | 1 | 7 | H |
Using the Optimal algorithm, there are 9 page faults.
Let's summarize the total number of page faults for each algorithm:
Comparing the number of page faults, the Optimal page replacement algorithm results in the minimum number of page faults (9) for the given page reference string and 3 page frames.
Here is a summary of the page fault counts:
| Algorithm | Total Page Faults |
|---|---|
| FIFO | 15 |
| LIFO | 12 |
| LRU | 11 |
| Optimal | 9 |
The Optimal algorithm demonstrates the lowest number of page faults, which is expected as it is theoretically the best possible algorithm.
For the following page reference string 4, 3, 2, 1, 4, 3, 5, 4, 3, 2, 1, 5. the number of page faults that occur in Least Recently Used (LRU) page replacement algorithm with frame size 3 is
Suppose for a process P, reference to pages in order are 1, 2, 4, 5, 2, 1, 2, 4. Assume that main memory can accommodate 3 pages and the main memory has already pages 1 and 2 in the order 1 - first, 2 - second. At this moment, assume FIFO Page Replacement Algorithm is used then the number of page faults that occur to complete the execution of process P is