When the CPU executes an instruction that is not available
in the memory, a Page Fault occurs. This means a
page is being referenced, but the same is not present in the memory. The Operating
System is now responsible for bringing the appropriate page into memory from
the disk. The total turnaround time of a process is divided into CPU time and
IO time. Disk I/O takes a longer time than CPU and the process must wait until
the page has been fetched from the disk. A module of the Operating System
called the Page Fault Handler is given the control. It gets the Page Table
address and the page number of the faulting page along with the information
needed to bring the required page into the main memory from the backing store. The
information also includes the disk address of the page in the backing store. A
longer IO is detrimental to the performance of the system as a whole because
the CPU would remain idle for a considerable amount of time which is not
feasible for a good Operating System design. So, the CPU would schedule
another process that could execute at the same point of time when the Disk IO
is being performed so that the CPU idle time can be avoided.
The Operating System searches for the page in the File Map
Table that contains the page number and the corresponding disk address of the
page. After acquiring the disk address, the OS schedules a disk read operation
to get the page from the disk/physical storage. The Memory Map Table is then
searched to locate the first free frame for that page to be loaded. After
getting the free frame number, the OS updates the Page Map Table with the frame
number and the reference bit. Now the presence bit is set to indicate the
presence of the page in memory. The CPU is now instructed to restart the
execution. If the probability of the page fault is "p" and the
memory access time is "ma," then the total time required is
(1 - p) x ma + p x page fault time.
Besides Demand Paging, there is another concept related to paging
operation in the name of Anticipatory Paging. This
implies that the Operating System guesses the pages that can be referenced and
fetches them from the backing store to put onto the main memory even before
they need to be referenced.