Demand paging can significantly affect the performance of a computer system. Let's compute the effective access time for a demand-paged memory.
For most computer systems, the memory-access time, denoted , ranges from 10 to 200 nanoseconds.
As long as we have no page faults, the effective access time is equal to the memory access time.
If, however a page fault occurs, we must first read the relevant pagefrom disk and then access the desired word.
Let be the probability of a page fault (
). We would expect to be close to zero -that is, we would expect to have only a few page faults.
The effective access time is then
effective access time = (1 - p)*ma + p*page fault time
We are faced with three major components of the page-fault service time:
Service the page-fault interrupt.
Read in the page.
Restart the process.
The first and third tasks can be reduced, with careful coding, to several hundred instructions. These tasks may take from 1 to 100 microseconds each.
The page-switch time, however, will probably be close to 8 milliseconds.
A typical hard disk has an average latency of 3 milliseconds, a seek of 5 milliseconds, and a transfer time of 0.05 milliseconds.
Thus, the total paging time is about 8 milliseconds, including hardware and software time.
If we take an average page-fault service time of 8 milliseconds and a memory-access time of 200 nanoseconds, then the effective access time in nanoseconds is
effective access time = (1 - p)*(200) + p*(8 milliseconds)
= (1 - p)*200 + p*8,000,000
= 200 + 7,999,800 x p.
We see, then, that the effective access time is directly proportional to the page-fault rate.
If one access out of 1,000 causes a page fault, the effective access time is 8.2 microseconds. The computer will be slowed down by a factor of 40 because of demand paging!
It is important to keep the page-fault rate low in a demand-paging system. Otherwise, the effective access time increases, slowing process execution dramatically.
An additional aspect of demand paging is the handling and overall use of swap space.
Disk I/O to swap space is generally faster than that to the file system. It is faster because swap space is allocated in much larger blocks, and file lookups and indirect allocation methods are not used.
The system can therefore gain better paging throughput by copying an entire file image into the swap space at process startup and then performing demand paging from the swap space.
Another option is to demand pages from the file system initially but to write the pages to swap space as they are replaced.