Definition — What is a Page Fault?
In the context of computer science, a Page Fault is an exception initiated by the hardware of a computer to notify the operating system when a program attempts to access a block of memory that is not stored in the physical memory or RAM. Reacting to this fault, the operating system must locate the data in virtual memory, then transfer it from the storage device, such as an HDD or SSD, to the system RAM.
Let’s say a particular program has ten pages out of which five pages are loaded into the main memory into two separate frames. So, when the CPU demands a particular page to be executed, however, the page is not available in the main memory, a page fault occurs. The page actually resides in the secondary memory or virtual memory. This whole mechanism is handled by the memory management unit (MMU) hardware. Though the term "page fault" sounds like an error, page faults are common and are part of the normal way CPU handles virtual memory. Most page faults are handled without any problems. However, an invalid page fault may cause a program to hang or crash. This type of page fault may occur when a program tries to access a memory address that does not exist or is corrupt. Some programs can handle these types of errors by finding a new memory address or relocating the data. However, if the program cannot handle the invalid page fault, it will get passed to the operating system, which may terminate the process. This can cause the program to unexpectedly quit. While page faults are common when working with virtual memory, each page fault requires transferring data from secondary memory to primary memory. This process may only take a few milliseconds, but that can still be several thousand times slower than accessing data directly from memory. Therefore, installing more system memory can increase your computer's performance, since it will need to access virtual memory less often.