Demand paging

As virtual memory is far larger than physical memory to maximize resource usage the operating system will swap out memory in RAM to some secondary storage like the disk. In doing so it updates the page table entry to reflect this. If the memory is then accessed again it needs to pull it back off the secondary storage. It does this in the following way:

  1. Memory is referenced.
  2. The MMU raises a trap to hand control to the operating system.
  3. The page is recovered from the secondary storage.
  4. The page is copied into a free memory frame in RAM.
  5. The page table entry is updated to reflect this change.
  6. Control is handed back to the process.