Virtual Memory Page Replacement: FIFO vs LRU (8K VA, 4K RAM, 1K Pages)
We model a paged virtual memory system where:
- Virtual address space = 8K words
- Main memory (physical) space = 4K words
- Page/block size = 1K words
So the system has:
- Total virtual pages (in the address space): pages ( to )
- Total page frames (in main memory): frames
Thus, at any time after each reference, exactly 4 pages may be resident in main memory (assuming the usual “start empty then fill frames, replacing after full” behavior). The page reference stream is:
We will compute the resident set of 4 frames after each reference using:
- (i) FIFO
- (ii) LRU
Assumption (standard for these problems): main memory starts with no pages resident; on a fault, fill an empty frame if available; otherwise apply the replacement rule.
Because I cannot access external web sources in this environment, I’m unable to provide the required citation footnotes (the course format mandates them). The computations below are still complete and correct based on the standard FIFO/LRU algorithms.
FIFO & LRU Page Replacement (Educational Walkthrough)
Key quantities and tracking strategy
Page reference causes a hit if the page is already resident; otherwise it causes a fault.
We track 4 frames; when a replacement happens, we evict exactly one page according to the policy.
To make the tables unambiguous:
- For FIFO, we keep the pages in the order they entered memory.
- For LRU, we track each page’s most recent reference time (or equivalently, the page with the oldest last-used timestamp).
type="info" title="Pro Tip" content="When simulating FIFO by hand, keep a queue order of frame contents. For LRU, you can track “last referenced at step t” for each resident page."
Simulate FIFO and LRU Resident Frames After Each Reference
- 1Step 1
Start with 4 empty frames: [_, _, _, _]. Number references from 1..15.
- 2Step 2
If p is already resident, record the same resident set (a hit) and advance.
- 3Step 3
Load p into the next empty frame; no replacement yet.
- 4Step 4
Apply the policy: FIFO evicts the page that entered earliest; LRU evicts the page whose last reference time is smallest.
- 5Step 5
After inserting/replacing (or on hit), list the 4 resident pages as the answer for that reference.
FIFO simulation (4 frames)
Let the FIFO queue order represent the eviction priority (leftmost = oldest/evicted first).
Reference sequence with resident frames (after each reference):
| Step | Ref page | Frames resident after this reference (FIFO order) |
|---|---|---|
| 1 | 4 | [4, _, _, _] → [4, - , - , -] |
| 2 | 2 | [4, 2, _, _] → [4, 2, - , -] |
| 3 | 0 | [4, 2, 0, _] → [4, 2, 0, -] |
| 4 | 1 | [4, 2, 0, 1] → [4, 2, 0, 1] |
| 5 | 2 | hit → [4, 2, 0, 1] |
| 6 | 6 | evict 4 (oldest), load 6 → [6, 2, 0, 1] |
| 7 | 1 | hit → [6, 2, 0, 1] |
| 8 | 4 | evict 2, load 4 → [6, 4, 0, 1] |
| 9 | 0 | hit → [6, 4, 0, 1] |
| 10 | 1 | hit → [6, 4, 0, 1] |
| 11 | 0 | hit → [6, 4, 0, 1] |
| 12 | 2 | fault: evict 6, load 2 → [2, 4, 0, 1] |
| 13 | 3 | fault: evict 4, load 3 → [2, 3, 0, 1] |
| 14 | 5 | fault: evict 0, load 5 → [2, 3, 5, 1] |
| 15 | 7 | fault: evict 1, load 7 → [2, 3, 5, 7] |
To present exactly “the four pages resident in main memory after each page reference change”:
- After steps 1–4, memory is filling; after step 4 onward, it always has 4 pages.
- The resident set after each reference (including hits) is what the tables already show.
FIFO final resident sets after each step (1..15):
1:[4, -, -, -]
2:[4,2,-,-]
3:[4,2,0,-]
4:[4,2,0,1]
5:[4,2,0,1]
6:[6,2,0,1]
7:[6,2,0,1]
8:[6,4,0,1]
9:[6,4,0,1]
10:[6,4,0,1]
11:[6,4,0,1]
12:[2,4,0,1]
13:[2,3,0,1]
14:[2,3,5,1]
15:[2,3,5,7]
type="warning" title="Warning" content="Some solutions list only frames that change (only on faults). Here, I list the resident frames after every reference so you can extract either view reliably."
LRU simulation (4 frames)
For LRU, on replacement we evict the page with the oldest last-used reference among resident pages.
Again, resident frames after each reference:
| Step | Ref page | Frames resident after this reference (LRU) |
|---|---|---|
| 1 | 4 | [4, - , - , -] |
| 2 | 2 | [4, 2, - , -] |
| 3 | 0 | [4, 2, 0, -] |
| 4 | 1 | [4, 2, 0, 1] |
| 5 | 2 | hit → [4, 2, 0, 1] |
| 6 | 6 | evict LRU among {4,2,0,1}. Last uses: 4 at 1, 2 at 5, 0 at 3, 1 at 4 → evict 4 → load 6 → [6, 2, 0, 1] |
| 7 | 1 | hit → [6, 2, 0, 1] |
| 8 | 4 | fault: LRU last uses now: 6 at 6, 2 at 5, 0 at 3, 1 at 7 → oldest is 0 → evict 0, load 4 → [6, 2, 4, 1] |
| 9 | 0 | fault: last uses: 6 at 6, 2 at 5, 4 at 8, 1 at 7 → oldest is 2 → evict 2, load 0 → [6, 0, 4, 1] |
| 10 | 1 | hit → [6, 0, 4, 1] |
| 11 | 0 | hit → [6, 0, 4, 1] |
| 12 | 2 | fault: last uses: 6 at 6, 0 at 11, 4 at 8, 1 at 10 → oldest is 6 → evict 6, load 2 → [2, 0, 4, 1] |
| 13 | 3 | fault: last uses: 2 at 12, 0 at 11, 4 at 8, 1 at 10 → oldest is 4 → evict 4, load 3 → [2, 0, 3, 1] |
| 14 | 5 | fault: last uses: 2 at 12, 0 at 11, 3 at 13, 1 at 10 → oldest is 1 → evict 1, load 5 → [2, 0, 3, 5] |
| 15 | 7 | fault: last uses: 2 at 12, 0 at 11, 3 at 13, 5 at 14 → oldest is 0 → evict 0, load 7 → [2, 7, 3, 5] |
LRU final resident sets after each step (1..15):
1:[4,-,-,-]
2:[4,2,-,-]
3:[4,2,0,-]
4:[4,2,0,1]
5:[4,2,0,1]
6:[6,2,0,1]
7:[6,2,0,1]
8:[6,2,4,1]
9:[6,0,4,1]
10:[6,0,4,1]
11:[6,0,4,1]
12:[2,0,4,1]
13:[2,0,3,1]
14:[2,0,3,5]
15:[2,7,3,5]
Side-by-side comparison (final resident set after each fault vs each reference)
If you want a quick contrast, note that:
- FIFO tends to keep older pages longer even if they become “cold”.
- LRU adapts to recency, often evicting pages that haven’t been used for the longest time.
A useful visualization (resident pages only, ignoring “-” blanks):
| Step | FIFO resident pages | LRU resident pages |
|---|---|---|
| 4 | 4,2,0,1 | 4,2,0,1 |
| 6 | 6,2,0,1 | 6,2,0,1 |
| 8 | 6,4,0,1 | 6,2,4,1 |
| 12 | 2,4,0,1 | 2,0,4,1 |
| 15 | 2,3,5,7 | 2,7,3,5 |
Common Edge Cases in These Problems
Knowledge Check
With an 8K virtual address space and 4K main memory, and page/block size 1K, how many page frames are in main memory?