OS Design and Implementation: (Week 5) - Page fault
MIT 6.1810 Fall2025 Course - Week 5: Page fault
Lecture
xv6 Book; Chapter 5 - Page fault: https://pdos.csail.mit.edu/6.1810/2025/xv6/book-riscv-rev5.pdf
Chapter 5 discusses page faults. A page fault is an exception that occurs when a virtual address is used but either:
lacks a mapping in the page table (physical memory is not yet allocated),
has an invalid mapping because PTE_V is not set,
or the requested operation (read, write, execute, user, etc.) is not permitted, meaning the appropriate flags (PTE_R, PTE_W, etc.) are not set.
An interesting aspect of page faults is that, when combined with the page table (which maps virtual addresses to physical addresses), they allow the kernel to fully control memory usage, enabling the application of various techniques. For example:
Copy-on-Write (CoW): When executing a fork system call, the kernel shares memory between the parent and child instead of copying the parent's memory to the child, as was done previously. The parent's memory is marked as read-only in the page table and shared with the child. If a write operation occurs, a page fault exception is triggered because the memory is read-only. This alerts the kernel to allocate new memory and copy the shared data before allowing the write operation. This approach ensures that a copy is made only if a write operation occurs, making the fork process faster.
Demand paging: In this approach, the kernel stores only a portion of the user program's pages in RAM, while the rest remain on disk. The page table entries (PTE) for the pages on disk are marked as invalid. The kernel loads these pages into RAM only when the program requests them, triggering a page fault exception due to their invalid PTEs.
It's as if the kernel intentionally allows this exception and knows how to handle it whenever it occurs.
Labs
There is just one lab: Implement copy-on-write (COW) fork() to delay allocating and copying physical memory pages until they are actually needed, if at all. I didn't finish it.
Next week
Next weeks is about Interrupts and Locks.
By the way, here's my GitHub repo for the lab course: https://github.com/TawalMc/MIT-6.1810Fall2025-xv6


