1 September 2010

what is demand paging in operating system?

Virtual memory can be implemented by a technique called demanding paging. It is a technique in which a Page is brought into memory when it is actually needed.
A typical life cycle of a process is as follows:

1. When a process is initiated, the operating system must at least load one page in real memory. It is the page containing the execution part of the process.
2. Execution of the process commences and proceeds through subsequent instructions beyond the starting point.

3. This execution continues as long as memory references generated by this page are also within same page. The virtual address created may reference a page that is not in real memory. This is called a page fault. It generates an interrupt that asks for the referenced page to be loaded. This is called demanding page.

4. The operating system will try to load the referenced page into a free real memory frame. When this is achieved the execution can continue.
5. Finally when the process terminates, the operating system releases all the pages belonging to the process. The pages become available to other processes.
In general, the operating system
accommodates the new page by removing a currently loaded page that is not in use. This is called page replacement. It is important to remove a page that will not be accessed in a short time. It will reduce the number of page faults in the system.



demand paging definition

 A kind of virtual memory where a page of memory will be paged in if an attempt is made to access it and it is not already present in main memory. This normally involves a memory management unit which looks up the virtual address in a page map to see if it is paged in. If it is not then the operating system will page it in, update the page map and restart the failed access. This implies that the processor must be able to recover from and restart a failed memory access or must be suspended while some other mechanism is used to perform the paging.
Paging in a page may first require some other page to be moved from main memory to disk ("paged out") to make room. If this page has not been modified since it was paged in, it can simply be reused without writing it back to disk. This is determined from the "modified" or "dirty" flag bit in the page map. A replacement algorithm or policy is used to select the page to be paged out, often this is the least recently used (LRU) algorithm. Prepaging is generally more efficient than demand paging
-source(Dictionary)