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

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

What is Demand Paging in OS

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

Diagram of Demand PagingDemand 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.

Demand Paging in OS Tutorial Headlines

In this section, we will show you all headlines about this entire article; you can check them as your choice; below shown all:

  1. Why Demand Paging?
  2. How Does Demand Paging Working
  3. Example of Demand Paging
  4. Advantages of Demand Paging
  5. Disadvantages of Demand Paging
  6. Pure Demand Paging
  7. Demand Segmentation in OS
  8. Demand Paging in OS Related Things
  • What is Page Fault?
  • What is Swapping?
  • What is Thrashing?
  1. FAQs (Frequently Asked Questions)
  • What is demand paging in OS explain with example?
  • What is demand paging in virtual memory?
  • What is demand paging how it is implemented?
  • What is performance of demand paging in OS?

Let’s Start!!

Why Demand Paging?

Each process has a multiple pages. But, it not enough to insert all pages of that process into primary memory because, RAM size is limited as well. Therefore, while getting to execute all process then loading the pages as per the requirement. It may be probability that any application does not require all its pages for executing the applications.

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.

Also Read: Multiprogramming Operating System: Examples, Types, and Advantage!!

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.

Valid-Invalid Bit

Here, we are going to explain it along with an example as showing an image:

demand-paging-in-OS

  • Along with every page table entry, a valid or invalid bit is linked (whereas 1 represents existed in the memory and 0 denotes not presented in the memory).
  • Firstly, a valid and invalid bit is must be set to 0 for all table entries that deals to ‘Page Fault’.
  • When the bit is going to set to ‘Valid’ then attached page is both legal and in the memory.
  • If bit is ‘Invalid’, then it denotes that page is either not valid or page is valid but at present time not available on the disk.
  • For those pages, which are fetched into memory, then page table is set as usual.
  • But those pages, which are not available in the main memory, and then page table is either simply named as invalid or it has the address of page on the disk.

While getting to demand paging process, many components are involved like as Main Memory, CPU, Secondary Memory, Interrupt, Physical Address space, Logical Address space, Operating System, and Page Table.

If the process needs more pages that are not getting to properly load into main memory then page fault condition will be triggered then following few steps are followed.

  • The memory address that is referred by process is first checked, then to get verify the request constructed by the process.
  • When it gets found to be invalid the process is aborted.
  • If, the valid request by the process then free frame is assigned, probability from free frame list, where as needed page will be deleted.
  • Next, new one phase is getting schedule to transfer the mandatory page from disk to the verified memory location.
  • Whenever I/O activities are done then process’s page table will be modify along with new frame number and invalid bit is alter to valid.
  • If, page fault is occurred then should be restarted from starting.

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

There are many benefits of demand paging in operating system such as:

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

Demand Paging in OS Related Things

What is Page Fault?

Page fault in OS is getting to happen whenever the page that is requested doesn’t present in the primary memory. Page fault is also called the ‘Page Miss’.

Other definition: A page fault is occurred in the operating system when it is unable to locate the required data or information in the virtual memory.

What is Swapping?

Swapping process comprises either deleting all pages of the process from the main memory or creating the pages so that we are eligible to remove the pages through the page replacement techniques.

When the process is getting to suspend that means the process are unable to execute, but we are eligible to swap out the process for some time. After passing few times, the process is able to swap back by the system from different types of secondary memory to primary memory. If any condition is happened, while process is getting to busy being swapped in and out of that situation is called the ‘Thrashing’.

What is Thrashing?

In thrashing, for any process, there are only few pages, which are available in the primary memory, so we are able to maintain many processes in the main memory. The time is also kept save because for waited pages (Unused), there is not necessary of swap-in and swap-out of memory.

What Are Reasons of Thrashing?

There are two caused like as lack of Frames and higher degree of multiprogramming.

Lack of Frames: When process contains few frames, then there will be some pages of that process that are eligible to present in the memory. Therefore, here it is requiring of quickly swapping in and quickly swapping out. So, it is getting to ignore, we have to need a perfect number of framed for assignment every process.

High Degree of Multiprogramming: In the main memory, if processes are increasing then the amount of frames assigned to every process will be decrease. Therefore, in this order, each process has some frame. Then, there will be higher page fault and CPU’s times are wasted only in the swapping in and out of pages, and CPU’s utilization of CPU will also getting decrease.

FAQs (Frequently Asked Questions)

What is demand paging in OS explain with example?

Demand paging is a process where data is transferred from secondary memory to main memory as per the demand that means all data is not saved into primary memory (RAM) because RAM has limited space for execution.

What is demand paging in virtual memory?

This concept already we have explain above in this article, you can read them.

What is demand paging how it is implemented?

Virtual memory is implemented by using Demand Paging in operating system, and then you can read this article: Virtual Memory in OS – Complete Guide!!

What is performance of demand paging in OS?

Demand paging can affect the performance of a computer system, so you should be calculate the effective access time for a demand paged.

Effective access time = (1 – p)*ma + p*page fault time

Closure

Through this post, we have explained in depth about demand paging in operating systems with their working, example, advantages, and disadvantage. As well as, we are also providing short introductions along with page fault, swapping, thrashing, pure demand paging, and demand segmentation in OS concepts.

If this content is helpful for you, then please share it along with your friends, family members or relatives over social media platforms like as Facebook, Instagram, Linked In, Twitter, and more.

Also Read: Unix OS (Operating System): Examples, Types, and Functions!!

If you have any experience, tips, tricks, or query regarding this issue? You can drop a comment!

Happy Learning!!