Virtual Memory
An OS handles a page fault trap as follows:
- The memory address requested is first checked, to make sure it was a valid memory request (that is, that this address doesn't belong to another program.)
- If the reference was invalid, the program is terminated. Otherwise, the page must be paged in (= brought from disk to memory.)
- A free frame is located, possibly from a free-frame list.
- A disk operation is scheduled to bring in the necessary page from disk, during which the program's execution is paused.
- When the copy from disk finishes, the program's page table is updated with the new frame number, and the invalid bit is changed to indicate that this is now a valid page reference.
- The instruction that caused the page fault must now be restarted from the beginning, and this program will continue executing on the CPU.