Understanding Page Faults
To understand Page Faults, we must understand the differences between Virtual and Physical memory types.
Virtual memory is used by the operating system, it is used to store data and instructions of a particular program or process on the hard-drive in file called a Page. Each process will have it’s own virtual memory address space. Each page will also contain a fixed number of virtual addresses.
Physical memory is the simply the addresses stored in RAM. We need to also understand that RAM is limited by the address spaced usable by the operating system.
When a process requests access to RAM, then the operating system must map the virtual address provided by the process to the physical address stored within the RAM. This is known process is known as Paging, and handled by the Memory Management Unit within the CPU.
Page Table and Mappings
The Page Table is used by the operating system to store mappings between virtual and physical memory addresses. A mapping is simply the correspondence between a virtual and physical memory address. Each mapping is known as a Page Table Entry (PTE).
So, where do Page Faults come into the equation?
A Page Fault is a type of interrupt, as the name suggests, this is when the CPU stops what process it was running, and then switches to the process which requested the CPU. In terms of a Page Fault, a interrupt occurs when a process requests the MMU to translate data stored in a virtual memory address to be translated into a physical memory address stored in the RAM. The operating system then loads the data for the process.
Invalid Page Fault
Invalid Page Fault occurs when a invalid virtual address is referenced, this is usually due to a corrupt page table or page file corruption.