Sub topic 9
Page Faults and Effective Access Time
Prerequisites and the Core Idea
This chapter assumes that you understand virtual addresses, page tables, TLBs, and basic process execution. A page fault occurs when a process references a virtual page that is not currently in a physical memory frame. The operating system must bring the page from secondary storage, such as an SSD, before the instruction can continue.
A page fault is not necessarily a programming error. It is a normal part of demand paging, where pages are loaded only when they are first used. However, storage access is much slower than memory access, so even a small page-fault rate can greatly increase the average access time.
Page-Fault Handling
When the CPU generates a virtual address, the memory-management unit checks the page-table entry. A valid bit indicates whether the page is currently in memory.
The operating system normally follows these steps:
- It detects the invalid page-table entry and traps into the kernel.
- It checks whether the reference is legal. An illegal reference causes a protection or segmentation error instead of a page load.
- It obtains a free frame. If no frame is free, it selects a victim page using a replacement algorithm.
- If the victim is dirty, the system writes it back to storage.
- It reads the required page into the selected frame.
- It updates the page table and possibly the TLB.
- It restarts the instruction that caused the fault.
Effective Access Time with Page Faults
Effective access time (EAT) is the average time per memory reference. Let:
- \(p\) be the probability of a page fault.
- \(N\) be the time for a normal reference when no page fault occurs.
- \(F\) be the complete page-fault service time, including trap handling, storage transfer, page-table updates, and the restarted reference.
Then:
\[ \text{EAT} = (1-p)N + pF \]
Use consistent units before calculating. Storage time is often given in milliseconds, while memory time is given in nanoseconds.
Suppose a normal reference takes 100 ns, the page-fault service time is 8 ms, and the page-fault probability is \(10^{-6}\). Convert 8 ms to 8,000,000 ns:
\[ \begin{aligned} \text{EAT} &= (1-10^{-6})(100) + (10^{-6})(8{,}000{,}000)\\ &\approx 108\text{ ns} \end{aligned} \]
Although only one reference in a million faults, the average access time rises by about 8 percent.
def effective_access_time(fault_probability, normal_ns, fault_ns):
return ((1 - fault_probability) * normal_ns
+ fault_probability * fault_ns)
print(effective_access_time(1e-6, 100, 8_000_000)) # 107.9999If the stated fault time excludes the final restarted memory access, add that access time to the fault path before applying the formula. If TLB lookup and page-table access are part of the problem, include them in \(N\), and include any required retry costs in \(F\).
Common Errors
- Mixing milliseconds and nanoseconds.
- Using \(pN + (1-p)F\), which reverses the probabilities.
- Treating a TLB miss as a page fault.
- Forgetting that a dirty victim may require an additional storage write.
- Assuming every invalid page reference is legal.
Exercise
A normal reference takes 200 ns. A page fault takes 5 ms in total, and the page-fault probability is 2 × 10^-6. What is the EAT?
Show answer
Convert 5 ms to 5,000,000 ns. EAT = (1 - 2 × 10^-6)(200) + (2 × 10^-6)(5,000,000) = 209.9996 ns, approximately 210 ns.