Demand Paging in OS (Operating System): Examples, Advantages, Working

Demand Paging in OS (Operating System): Examples, Advantages, Working

What is Demand Paging

Definition: Demand paging is a process of swapping in the Virtual Memory system. In this process, all data is not moved from hard drive to main memory because while using this demand paging, when some programs are getting demand then data will be transferred. But, if required data is already existed into memory then not need to copy of data. The demand paging system is done with swapping from auxiliary storage to primary memory, so it is known as “Lazy Evaluation”.
Demand Paging

Diagram of Demand Paging

Some Page Replacement Algorithms are used in the demand paging concept to replace different pages – such as FIFO, LIFO, Optimal Algorithm, LRU Page, and Random Replacement Page Replacement Algorithms.

How Does Demand Paging Working

Demand paging system is totally depend on the page table implementation because page table helps to maps logical memory to physical memory. Bitwise operators are implemented in the page table to indication that pages are ok or not (valid or invalid). All valid pages are existed into primary memory, and other side invalid pages are existed into secondary memory.

Now all process go ahead to access all pages, then some things will be happened.  Such as –

  • Attempt to currently access page.
  • If page is ok (Valid), then all processing instructions work as normal.
  • If, anyone page is found as invalid, then page- fault issue is arise.
  • Now memory reference is determined that valid reference is existed on the auxiliary memory or not. If not existed, then process is terminated, otherwise needed pages are paged in.
  • Now disk operations are implemented to fetch the required page into primary memory.

Example of Demand Paging

Memory Access Time = 200 nanoseconds

Average Page Fault Service Time = 8 milliseconds

EAT = (1-p)*200+p(8 milliseconds)

    = (1-p)*200+p*8000000

    = 200+p*7999800

EAT means direct proportional to the page fault rate.

 Advantages of Demand Paging

  • Memory can be utilized with better efficiently.
  • If, any program is larger to physical memory then It helps to run this program.
  • No need of compaction.
  • Easy to share all pages
  • Partition management is more simply.
  • Discards external fragmentation
  • Easy to swap all pages
  • It allows pre-paging concept.
  • Easy to swap out page least likely to be used
  • All pages can be mapped appropriately.
  • All data can be collected over PM

Disadvantages of Demand Paging

  • It has more probability of internal fragmentation.
  • Its memory access time is longer.
  • Page map table is needed additional memory and registers.

Pure Demand Paging

In this section, we will discuss about difference between demand paging and pure demand paging.

In the initially stage, if anyone page is not loaded into primary memory then page faults are occurred, and then paged are loaded with on demanding of the process. This process is known as “Pure Demand Paging”.

Pure demand paging is not able to load single page into main memory, otherwise it will be fired the Page-Fault.

In pure demand paging, when process will be started up then all memory is swapped from auxiliary memory to primary memory.

Demand Segmentation in OS

Operating system implements demand segmentation like demand paging. While using “Demand Paging”,  if it to get lack of hardware resources, then OS implements the demand segmentation.

Segment table keeps all information related to demand segmentation such as valid bit because on the behalf of valid bit can be specified that segment has existed in the physical memory or not. If, anytime physical memory is not capable to store their segments then to get segment fault, and then it try to fetch required segments from physical memory. Similar to page fault.

Demand segmentation helps to decrease the number of page faults in the paging system.