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.

Similar Reads

What is Demand Paging?

Demand paging can be described as a memory management technique that is used in operating systems to improve memory usage and system performance. Demand paging is a technique used in virtual memory systems where pages enter main memory only when requested or needed by the CPU....

What is Page Fault?

The term “page miss” or “page fault” refers to a situation where a referenced page is not found in the main memory....

What is Thrashing?

Thrashing is the term used to describe a state in which excessive paging activity takes place in computer systems, especially in operating systems that use virtual memory, severely impairing system performance. Thrashing occurs when a system’s high memory demand and low physical memory capacity cause it to spend a large amount of time rotating pages between main memory (RAM) and secondary storage, which is typically a hard disc....

Pure Demand Paging

Pure demand paging is a specific implementation of demand paging. The operating system only loads pages into memory when the program needs them. In on-demand paging only, no pages are initially loaded into memory when the program starts, and all pages are initially marked as being on disk....

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....

Advantages of Demand Paging

So in the Demand Paging technique, there are some benefits that provide efficiency of the operating system....

Disadvantages of Demand Paging

Page Fault Overload: The process of swapping pages between memory and disk can cause a performance overhead, especially if the program frequently accesses pages that are not currently in memory. Degraded performance: If a program frequently accesses pages that are not currently in memory, the system spends a lot of time swapping out pages, which degrades performance. Fragmentation: Query paging can cause physical memory fragmentation, degrading system performance over time. Complexity: Implementing query paging in an operating system can be complex, requiring complex algorithms and data structures to manage page tables and swap space....

FAQs on Demand Paging

Q.1: How does demand paging differ from swapping?...