Demand Paging in Operating Systems | OS Tutorials YASH PAL, June 25, 2026June 25, 2026 In an operating system, demand paging is similar to a paging system with swapping. In demand paging, a page is loaded/swapped into memory when needed, i.e., when a logical address generated by a process points to a page that is not present in memory. This is done by a lazy swapper.Table of Contents Demand PagingHardwareHandling Page FaultPerformance of Demand Paging (By calculating Effective Access Time)Demand PagingTo facilitate demand paging, the entire logical address space of a process is maintained on a secondary storage device like a fast disk. We call this disk the paging device. Figure 1 illustrates the demand paging scheme.Figure 1: Transfer Page to Paging DeviceWhile initiating execution of a process, an area is allocated on the paging device for this logical address space, and its code and data are copied into this space. This space is called the swap space of the process.A page is loaded from this area into the memory when needed. When the virtual memory handler decides to remove a page from memory, the page is copied back into the swap space if it was modified since the last time it was loaded into memory.Hence, this way, the swap space contains an up-to-date copy of every page that is not present in memory.Demand paging involves interaction between hardware and software components of the virtual memory, i.e., between the MMU and the virtual memory handler.Three concepts are involved in understanding the operation of demand paging. These are:Page faults (also called missing page interrupts).Page-in and page-out operations.Page replacement.HardwareWith this scheme, we need some form of hardware support to distinguish between those pages that are in memory and those that are on the disk.The valid-invalid bit scheme can be used for this purpose; when this bit is set to valid, this value indicates that the associated page is both legal and in memory.If the bit is set to invalid, this value indicates that the page is not valid, or is valid but is currently on the disk.Figure 2 depicts the concept.Figure 2: Depicts the conceptFigure 3 illustrates the concept of demand paging.Figure 2: Example of Demand PagingPage fault trap: While performing address translation for a logical address, the MMU checks the valid bit of the page table entry. If the process is not present in memory, the MMU raises an interrupt called Page fault trap or Missing Page Interrupt.Handling Page FaultThe procedure of handling a page fault is carried out in six steps as given below: (also shown in Figure 3).Figure 3: Steps involved in page fault handlingStep 1: Firstly, check the internal table for this process to determine whether the reference was a valid or invalid memory access.Step 2: If the reference was invalid, we terminate the process. If it were valid, but we have not yet brought in that page. We now page in the latter.Step 3: We find a free frame.Step 4: Then, we schedule a disk operation to read the desired page into the newly allocated frame.Step 5: When the disk read is complete, we modify the internal table kept with the process and the page table to indicate that the page is now in memory.Step 6: Restart the instruction that was interrupted by the illegal address trap.Performance of Demand Paging (By calculating Effective Access Time)Demand paging can have a significant effect on the performance of a computer system. To compute the effective access time for a demand-paged memory system. Let ma be the memory access time, generally from 10 to 200 nanoseconds.If page fault = 0, then effective access time = Memory access timeIf a page fault occurs, then read the relevant page from the disk and access the desired word. Let P be the probability of a page fault (0 <= P <= 1). Make P close to 0 (which means the page fault rate is low). ThenEffective access time = (1 - P) x ma + P x Page fault timeTo compute the effective access time, we must know how much time is needed to service a page fault. engineering subjects Operating System Operating System