See how an executable program can be loaded from disk into memory. An alternative is to load the entire program in physical memory at the time of program execution. An issue with this method, as it may be, is that we do not need the entire program in memory. Suppose a program starts with a set of accessible options from which the program user has to choose. Loading the entire program into memory brings about loading executable code for all options, whether it is at the last option selected by the program user or not. Other alternative technique is to load pages only when necessary. This process is known as request paging and is commonly used in virtual memory frameworks. With requests for virtual memory, pages are likely loaded when requested during program execution; Pages that have never been formed along these lines are never in physical memory.
As indicated by the concept of virtual memory, so in order to execute some process, just one piece of the process must be available in primary memory, meaning that some required pages of process can be available in memory. Regardless of which pages should be kept in primary memory and which should be kept in secondary memory, there will be difficult in light of the fact that we cannot predict that a process requires a specific page at what specific time. In this way, to overcome the issue, the idea of demand paging is introduced. It proposes to keep all pages of frames in secondary memory until they are required. In other words, it says not to load any page in main memory unless it is required. Whenever any page is referred for the first time in the main memory, then that page will be found in the secondary memory.After that, it may or may not be present in the main memory depending upon the page replacement algorithm.
The root cause of the operating system is to reduce the load on the system and be progressively effective. The demand paging system gives utility that is similar to the paging system with swapping introduced in the figure 1, where processes reside in secondary memory (usually a disk). At this point when we need to execute a process, we swap it in memory. Instead of swapping the entire process in memory, we use a lazy swapper. Lazy swaggers never swap a page into memory, except that page will be needed. Since we are currently viewing a process as a sequence of pages, as opposed to a huge contiguous address space, the use of the term swapper is technically incorrect. For example, a 128MB size application may require 16MB pages to be swapped, so there is no compelling reason to swap at the same time. A swagger controls entire processes, although a pager is concerned about individual pages of a process. Along these lines we use a pager instead of a swapper about demand paging.
The fundamental parts associated with the process of demand paging are;
- Control Processing Unit (CPU)
- Main Memory
- Secondary Memory
- Logical Address space
- Physical Address space
- Page Table
- Operating System
Working paradigm of Demand Paging
Following steps includes as working of Demand paging;
- The CPU may be requested for a page that may not be accessible in main/primary memory in a active state. Along these lines, it needs to be generating an interrupt.
- This is the point at which the operating system move advances the process in a blocked state because an interrupt has occurred.
- At this point, the operating system appears from the given page in the logical location space.
- Finally with the help of page replacement algorithms, replacements are made in the physical address space. Simultaneously, page tables are updated.
- The CPU is informed about the update and asked to go ahead with the execution and process gets back into the ready state.
Also check: Paging In Operating System
If the referred page is not present in the main memory then there will be a miss and the concept is called Page miss or page fault.
The CPU has to access the missed page from the secondary memory. If the number of page fault is very high then the effective access time of the system will become very high.
Page Fault Service Time
Whenever a page fault occurs, the CPU takes considerable amount of time to perform the demand paging working steps. This time taken by the CPU is called as page fault service time.
If the access time for main memory is , service time for page fault is , page fault rate is , Then the effective memory access time
If the number of page faults is equal to the number of referred pages or the number of page faults are so high so that the CPU remains busy in just reading the pages from the secondary memory then the effective access time will be the time taken by the CPU to read one word from the secondary memory and it will be so high. The concept is called thrashing.
Also check: Memory Fragmentation In Operating System