Sub topic 9
Page Faults and Effective Access Time
This chapter assumes you know how paging translates a virtual address into a frame and offset, how a TLB speeds up translation, and how to compute effective access time (EAT) with a TLB. It also assumes you know the basic idea of demand paging, where pages are loaded only when they are first used. Here you will trace what happens on a page fault, compute EAT when faults occur, and avoid the usual GATE mistakes.
What a page fault is
In a demand-paged system, each page-table entry has a valid-invalid bit. If the bit is "valid", the page is in memory and the entry holds a frame number. If the bit is "invalid", one of two things is true:
- The page is not in the process's logical address space. This is an illegal reference, and the OS terminates the process (a segmentation fault on Unix-like systems).
- The page is legal but currently on disk. This is a page fault: a trap raised by the MMU when a process references a legal page that is not in main memory.
A page fault is not an error. It is the normal way pages get loaded under demand paging. With pure demand paging, a process starts with no pages in memory and faults on its first instruction.
Steps of fault handling
In words:
- The hardware traps to the OS.
- The OS saves the registers and process state.
- It checks in an internal table (usually kept with the PCB) whether the reference was legal and where the page lives on disk.
- It finds a free frame. If none exists, a page-replacement algorithm picks a victim.
- It schedules a disk read into that frame. The process blocks, and the CPU can run another process.
- When the disk interrupt arrives, the OS updates the page table and marks the entry valid.
- The process becomes ready again. When it is scheduled, the faulting instruction restarts from the beginning.
Step 7 requires that instructions be restartable. Instructions that modify memory in several steps, such as a block move with overlapping source and destination, or auto-increment addressing modes, are the hard cases. Hardware solves them by touching all pages involved before any change, or by keeping enough state to undo partial changes.
The dirty bit
If the victim page was modified while in memory, it must be written back to disk before the frame is reused. That makes the fault cost two disk operations instead of one. Each page-table entry therefore carries a dirty (modify) bit, set by hardware on a write. If the victim is clean, the OS skips the write-back and simply overwrites the frame.
Effective access time with page faults
Let p be the page-fault rate, the probability that a given memory reference causes a fault, with 0 ≤ p ≤ 1. Let t_mem be the memory access time and T_fault the total time for a reference that faults. Then:
EAT = (1 − p) × tmem + p × Tfault
T_fault is dominated by disk I/O, which takes milliseconds, while t_mem takes nanoseconds. A ratio of about 40,000 to 1 means even a tiny p matters.
Worked example
Memory access takes 200 ns and an average fault takes 8 ms. Convert 8 ms to 8,000,000 ns before using the formula.
- EAT = (1 − p) × 200 + p × 8,000,000 = 200 + 7,999,800 × p
Suppose we want the slowdown to be at most 10%, so EAT ≤ 220 ns.
- 7,999,800 × p ≤ 20
- p ≤ 20 / 7,999,800 ≈ 2.5 × 10⁻⁶
That is fewer than one fault per 400,000 references. Demand paging only works because programs have locality of reference: they reuse a small set of pages for long stretches.
Faults with a clean or dirty victim
When the fault time depends on the victim, take a weighted average first. Suppose a fault takes 8 ms if the victim is clean and 20 ms if it is dirty (write-back plus read), and 30% of victims are dirty.
- Average
T_fault= 0.7 × 8 + 0.3 × 20 = 11.6 ms = 11,600,000 ns
The following code computes the EAT for this case and the maximum tolerable fault rate for a given slowdown.
def eat_faults(p, t_mem, t_fault):
"""Effective access time; all times in the same unit (ns here)."""
return (1 - p) * t_mem + p * t_fault
def max_fault_rate(t_mem, t_fault, slowdown):
"""Largest p such that EAT <= (1 + slowdown) * t_mem."""
return slowdown * t_mem / (t_fault - t_mem)
t_fault = 0.7 * 8_000_000 + 0.3 * 20_000_000 # 11,600,000 ns
print(round(eat_faults(1e-6, 200, t_fault), 2)) # 211.6
print(f"{max_fault_rate(200, 8_000_000, 0.10):.3e}") # 2.500e-06Combining the TLB and page faults
Often a question gives a TLB hit ratio and a fault rate. Treat the two layers separately:
- Compute the EAT of a reference that does not fault, using the TLB formula. For a single-level page table, this is
h × (t_tlb + t_mem) + (1 − h) × (t_tlb + 2 × t_mem). - Use that value as
t_memin the page-fault formula.
Example: TLB 10 ns, memory 100 ns, TLB hit ratio 0.9, so the no-fault time is 120 ns, the value computed in the earlier TLB chapter. The fault rate is p = 10⁻⁴ and a fault takes 5 ms = 5,000,000 ns.
- EAT = 0.9999 × 120 + 0.0001 × 5,000,000 = 119.988 + 500 = 619.988 ns
The fault term (500 ns) dwarfs the translation overhead. Improving the TLB hit ratio would barely change this answer.
Variants of the question you will meet
| Given in the question | What to compute |
|---|---|
| Fault rate `p`, `t_mem`, service time | Direct use of the formula |
| Target EAT or slowdown | Solve the linear equation for `p` |
| Fraction of dirty victims | Weighted average service time first |
| Service time split into parts (trap, disk, restart) | Add the parts; the disk part usually dominates |
| One fault per `k` instructions | `p = 1/k` per instruction. Check how many memory references each instruction makes |
| TLB and fault rate both given | Compute the TLB-based EAT, then use it as `t_mem` |
Common errors
- Mixed units. Memory is in ns and disk is in ms. Convert before substituting. This is the most common source of wrong answers.
- Using
pas a percentage. A fault rate of 0.1% isp = 0.001, not 0.1. - Forgetting the dirty write-back. A dirty victim doubles the disk work. When the question states a dirty fraction, use it.
- Confusing fault rate with miss ratio. A TLB miss only costs an extra memory access. A page fault costs a disk read. They are not the same event, and a TLB miss does not imply a fault.
- Per-instruction versus per-reference rates. An instruction can make several memory references (fetch, operands). Check what
prefers to. - Thinking the CPU waits idle. During the disk read, the OS can run another process. EAT measures the delay seen by the faulting process, not wasted CPU time. Waiting-time questions assume the formula above anyway.
Why locality matters
The slowdown equation shows that a system performs well only if almost every reference hits memory. With a fault costing around 8 ms, the program must run hundreds of thousands of references per fault. Locality is why this holds in practice, and the next chapters build on it. Page-replacement algorithms try to keep the pages with locality in memory. If a process lacks enough frames to hold its working set, p rises sharply, which leads to thrashing.
Exercise
Memory access takes 100 ns and an average page fault takes 10 ms. What is the largest page-fault rate that keeps EAT within 10 ns of the memory access time (EAT ≤ 110 ns)?
Show answer
Convert 10 ms to 10,000,000 ns. EAT = 100 + p × (10,000,000 − 100) ≤ 110, so p ≤ 10 / 9,999,900 ≈ 1.0 × 10⁻⁶. That is about one fault per million references.
Exercise
A system has a TLB lookup time of 20 ns, memory access time of 100 ns and a single-level page table. The TLB hit ratio is 0.8. The page-fault rate is 10⁻⁵ per reference, and a fault takes 2 ms in total. What is the EAT?
Show answer
First compute the no-fault time: 0.8 × (20 + 100) + 0.2 × (20 + 200) = 96 + 44 = 140 ns. Then EAT = (1 − 10⁻⁵) × 140 + 10⁻⁵ × 2,000,000 = 139.9986 + 20 = 159.9986 ≈ 160 ns.
Exercise
Page faults take 8 ms when the victim is clean and 20 ms when it is dirty. Memory access time is 200 ns, 40% of victims are dirty, and p = 2 × 10⁻⁷. Find the EAT.
Show answer
Average service time = 0.6 × 8 + 0.4 × 20 = 12.8 ms = 12,800,000 ns. EAT = (1 − 2 × 10⁻⁷) × 200 + 2 × 10⁻⁷ × 12,800,000 = 199.99996 + 2.56 ≈ 202.56 ns.