When Does Page Fault Occur?

Learn via video courses
Topics Covered

A page fault is a trap that occurs when the requested page is not loaded into the memory, in other words, when a program tries to access a chunk of memory that does not exist in physical memory (main memory) causes a page fault.

What is a Page Fault in the OS?

In operating systems, a page fault is an exception/error that is raised by the memory management unit if a process accesses a memory page without it being loaded into the memory. A mapping is required to be added to the virtual address space of the process to access the page. The page contents are loaded from a backing store (secondary storage), such as a disk. The page fault is detected by the memory management unit, but the operating system's kernel handles the exception by making the required page accessible in the physical memory or denying illegal memory access.

page fault in the OS

Describe the Actions Taken by the Operating System When a Page Fault Occurs.

When a page fault occurs, the following sequence of events happens:

  1. At first, an internal table is created to process whether the reference was valid or invalid memory access.
  2. The system gets terminated if the reference becomes invalid, if not, the page will be paged in.
  3. After checking for validity, the free-frame list searches the system for a free frame.
  4. The disk operation will be scheduled to get the required page from the disk.
  5. The page table of the process will be updated with a new frame number, and the invalid bit will be changed after the completion of the I/O operation. Now it is a valid page reference.
  6. Restart these steps upon finding any more page faults.

Learn About Page Replacement Algorithms

A page replacement algorithm is needed to decide which page needs to be replaced when a new page comes in. These are used in operating systems that use paging for memory management.

To learn more about page replacement algorithms, follow the below link

Conclusion

  • Page faults occur when a requested page is not loaded into the memory.
  • Page faults are detected by the Memory Management Unit (MMU).
  • Page replacement algorithms are used to minimize the number of page faults.