Demand paging is an application of virtual memory. In a system that uses demand paging, the operating system copies a disk page into physical memory only if an attempt is made to access it (i.e., if a page fault occurs). It follows that a process begins execution with none of its pages in physical memory, and many page faults will occur until most of a process's working set of pages is located in physical memory. This is an example of lazy loading techniques

Advantages

Demand paging, as opposed to loading all pages immediately:

  • Does not load the pages that are never accessed, so saves the memory for other programs and increases the degree of multiprogramming.
  • Less loading latency at the program startup.
  • Less of initial disk overhead because of fewer page reads.
  • Does not need extra hardware support than what paging needs, since protection fault can be used to get page fault.

Disadvantages

  • Individual programs face extra latency when they access a page for the first time. So prepaging, a method of remembering which pages a process used when it last executed and preloading a few of them, is used to improve performance.
  • Programs running on low-cost, low-power embedded systems may not have a memory management unit that supports page replacement.
  • Memory management with page replacement algorithms becomes slightly more complex.
  • Possible security risks, including vulnerability to timing attacks; see Percival 2005 Cache Missing for Fun and Profit (specifically the virtual memory attack in the first section).