Working Process of Demand Paging
So, let us understand this with the help of an example. Suppose we want to run a process P which have four pages P0, P1, P2, and P3. Currently, in the page table, we have pages P1 and P3.
Therefore, the operating system‘s demand paging mechanism follows a few steps in its operation.
- Program Execution: Upon launching a program, the operating system allocates a certain amount of memory to the program and establishes a process for it.
- Creating page tables: To keep track of which program pages are currently in memory and which are on disk, the operating system makes page tables for each process.
- Handling Page Fault: When a program tries to access a page that isn’t in memory at the moment, a page fault happens. In order to determine whether the necessary page is on disk, the operating system pauses the application and consults the page tables.
- Page Fetch: The operating system loads the necessary page into memory by retrieving it from the disk if it is there.
- The page’s new location in memory is then reflected in the page table.
- Resuming the program: The operating system picks up where it left off when the necessary pages are loaded into memory.
- Page replacement: If there is not enough free memory to hold all the pages a program needs, the operating system may need to replace one or more pages currently in memory with pages currently in memory. on the disk. The page replacement algorithm used by the operating system determines which pages are selected for replacement.
- Page cleanup: When a process terminates, the operating system frees the memory allocated to the process and cleans up the corresponding entries in the page tables.
What is Demand Paging in Operating System?
The concept of query navigation in the operating system. This concept says that we should not load any pages into the main memory until we need them, or keep all pages in secondary memory until we need them.