Page Fault

If the CPU requests a particular page and that page is not found in the main memory, then it will be a page fault situation. Then, the OS loads that page from the hard disk to the main memory. When loading that particular page from Secondary memory to the main memory, the CPU sits idle. The operating system is responsible for loading a page from secondary memory to main memory. Due to CPU idleness, System performance decreases.

Page Fault example

Suppose a CPU generates a logical address 0111. The first three bits represent the page number, and the last represents the offset. Remember that 011 denotes the 3rd page, and 1 represents the second byte of that page.

 The page table has no corresponding frame if the requested page is not in the main memory. It is the page fault situation. As shown in the diagram given below.

example of page fault in operating system STEP 1

Now, a trap is generated, which requests the OS to load that page from secondary memory to main memory, as shown in the diagram below.

example of page fault in operating system STEP 2

As the requested page is loaded in the frame of the main memory, the Page table is updated, which assigns the frame number from the main memory. Look at the following diagram,

example of page fault in operating system STEP 3

The physical address is now generated, as shown in the diagram below. It is already discussed in the concept of Paging.

example of page fault in operating system STEP 4

Note: If the number of page faults increases, then the effective access time of the system will also increase.