HOME

TheInfoList



OR:

In
computer A computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations ( computation) automatically. Modern digital electronic computers can perform generic sets of operations known as programs. These prog ...
operating systems An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. Time-sharing operating systems schedule tasks for efficient use of the system and may also in ...
, demand paging (as opposed to anticipatory paging) is a method of
virtual memory In computing, virtual memory, or virtual storage is a memory management technique that provides an "idealized abstraction of the storage resources that are actually available on a given machine" which "creates the illusion to users of a very ...
management. In a system that uses demand paging, the operating system copies a disk
page Page most commonly refers to: * Page (paper), one side of a leaf of paper, as in a book Page, PAGE, pages, or paging may also refer to: Roles * Page (assistance occupation), a professional occupation * Page (servant), traditionally a young m ...
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 In computing, a page fault (sometimes called PF or hard fault) is an exception that the memory management unit (MMU) raises when a process accesses a memory page without proper preparations. Accessing the page requires a mapping to be added t ...
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 Working set is a concept in computer science which defines the amount of memory that a process requires in a given time interval. Definition Peter Denning (1968) defines "the working set of information W(t, \tau) of a process at time t to be t ...
of pages are 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 Computer data storage is a technology consisting of computer components and recording media that are used to retain digital data. It is a core function and fundamental component of computers. The central processing unit (CPU) of a compute ...
to
main memory Computer data storage is a technology consisting of computer components and recording media that are used to retain digital data. It is a core function and fundamental component of computers. The central processing unit (CPU) of a comput ...
. 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 A page table is the data structure used by a virtual memory system in a computer operating system to store the mapping between virtual addresses and physical addresses. Virtual addresses are used by the program executed by the accessing Process ( ...
implementation is used. The page table maps logical memory to physical memory. The page table uses a
bitwise In computer programming, a bitwise operation operates on a bit string, a bit array or a binary numeral (considered as a bit string) at the level of its individual bits. It is a fast and simple action, basic to the higher-level arithmetic operat ...
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 the
context switch In computing, a context switch is the process of storing the state of a process or thread, so that it can be restored and resume execution at a later point, and then restoring a different, previously saved, state. This allows multiple processe ...
ing 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. * Low-cost, low-power
embedded system An embedded system is a computer system—a combination of a computer processor, computer memory, and input/output peripheral devices—that has a dedicated function within a larger mechanical or electronic system. It is ''embedded ...
s may not have a
memory management unit A memory management unit (MMU), sometimes called paged memory management unit (PMMU), is a computer hardware unit having all memory references passed through itself, primarily performing the translation of virtual memory addresses to physical a ...
that supports page replacement. * Memory management with page replacement algorithms becomes slightly more complex. * Possible security risks, including vulnerability to timing attacks; see (specifically the virtual memory attack in section 2). * Thrashing which may occur due to repeated page faults.


See also

* Page cache *
Memory management Memory management is a form of resource management applied to computer memory. The essential requirement of memory management is to provide ways to dynamically allocate portions of memory to programs at their request, and free it for reuse when ...
*
Virtual memory In computing, virtual memory, or virtual storage is a memory management technique that provides an "idealized abstraction of the storage resources that are actually available on a given machine" which "creates the illusion to users of a very ...
* Lazy evaluation


References

* Tanenbaum, Andrew S. ''Operating Systems: Design and Implementation (Second Edition)''. New Jersey: Prentice-Hall 1997. {{Memory management navbox Virtual memory