in computer operating systems, demand paging (as opposed to anticipatory paging) is a method of virtual memory management. 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 and that page is not already in memory (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 a lazy loading technique. ==basic concept== demand paging follows that pages should only be brought into memory if the executing process demands them. this is often referred to as lazy evaluation as only those pages demanded by the process are swapped from secondary storage to main memory. contrast this to pure swapping, where all memory for a process is swapped from secondary storage to main memory during the process startup. commonly, to achieve this process a page table implementation is used. the page table maps logical memory to physical memory. the page table uses a bitwise operator to mark if a page is valid or invalid. a valid page is one that currently resides in main memory. an invalid page is one that currently resides in secondary memory. when a process tries to access a page, the following steps are generally followed: * attempt to access page. * if page is valid (in memory) then continue processing instruction as normal. * if page is invalid then a page-fault trap occurs. * check if the memory reference is a valid reference to a location on secondary memory. if not, the process is terminated (illegal memory access). otherwise, we have to page in the required page. * schedule disk operation to read the desired page into main memory. * restart the instruction that was interrupted by the operating system trap. ==advantages== demand paging, as opposed to loading all pages immediately: * only loads pages that are demanded by the executing process. * as there is more space in main memory, more processes can be loaded reducing context switching time which utilizes large amounts of resources. * less loading latency occurs at program startup, as less information is accessed from secondary storage and less information is brought into main memory. * as main memory is expensive compared to secondary memory, this technique helps significantly reduce the bill of material (bom) cost in smart phones for example. symbian os had this feature. ==disadvantages== * individual programs face extra latency when they access a page for the first time. * 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 slig
Virtual_memory