In: Computer Science
A page fault occurs when a program attempts to access a block of memory that is not stored in the physical memory or RAM. The fault notifies the operating system that it must locate the data in virtual memory and then transfer it from the storage device, such as an HDD or SSD, to the system RAM.
When handling a page fault, the operating system tries to make the required page accessible at the location in physical memory or terminates the program in cases of illegal memory access. Steps in page fault handling are:
1. The memory address requested is first checked, to make sure it was a valid memory request. Check the location of the referenced page in the Page Map Table (PMT)
2. If the reference was invalid, the process is terminated. Otherwise, the page must be paged in. If any page fault occurred, call on the operating system to fix it.
3. Using frame replacement algorithm, find the frame location. A free frame is located, possibly from a free-frame list.
4. Read the data from disk to memory. A disk operation is scheduled to bring in the necessary page from the disk. This will usually block the process on an I/O wait, allowing some other process to use the CPU in the meantime.
5. When the input / output operation is complete, the process’s Page Map Table (PMT) is updated with the new frame number, and the invalid bit is changed to indicate that this is now a valid page reference.
6. The instruction that caused the page fault must be restarted when the process resumes execution.