×

What is Demand Paging?

Demand Paging is defined as a process in which the pages are loaded into the memory (when the page fault occurs) or on-demand.

It consists of the following steps:

What is Demand Paging
  1. If there is a page that CPU wants to refer, but currently in the Main Memory, that page is not available, then in this situation, an interrupt is generated by the CPU, which indicates that there is memory access fault.
  2. With the help of an operating system, the process which is interrupted is put into the blocking state. To proceed the execution, the operating system takes the page which is needed into the Main Memory.
  3. For the required page, the operating system will search in the logical address space.
  4. From the logical address space to the physical address space, the needed page will be carried.

We use page replacement algorithms to decide which page is replaced in the physical address space. Accordingly, we update the page table.

  • Then, to continue the execution of the program, the signal is sent to the CPU, and the CPU will again place the process into the ready state.

Therefore, the operating system uses the above steps at the time when page fault has occurred, and the needed page is taken into the memory.

Advantages of Demand Paging

The advantages of demand paging are:

  1. Memory can be used more efficiently.
  2. If we use demand paging, then we can have a large virtual memory.
  3. By using demand paging, we can run programs that are larger than physical memory.
  4. In demand paging, there is no requirement of compaction.
  5. In demand paging, the sharing of pages is easy.
  6. In demand paging, partition management is simple because of the fixed partition size and the discontinuous loading.

Disadvantages of Demand Paging

The disadvantages of demand paging are:

  1. In demand paging, there may be a chance of internal fragmentation.
  2. The memory access time is longer (page table lookup).

What is a Page Fault?

Page Fault is a condition in which the page that is referred or requested does not exist in the main memory.  A Page fault is also known as Page miss.

In other words, a page fault is defined as a condition in which the OS (operating system) cannot find the needed data or information in the virtual memory.

Swapping

The process of swapping means removing all the pages of the process from memory, or marking the pages so that we can remove the pages with the help of the page replacement process.

If the process is suspended, it means the process cannot run. but we can swap out the process for sometime. After some time, the process can be swapped back by the system from the secondary memory to the primary memory. The situation where a process is busy with the pages being swapped in and out of that situation is known as thrashing.

Swapping

Thrashing

In thrashing, for any process, there are only some pages which are present in the main memory so we can maintain more processes in the memory. With this, the time is also saved because, for unused pages, there is no requirement of swap-in and swap-out of memory.

Although the operating system should be crafty so that it can handle this scheme. Practically in the steady-state, pages of the processes will occupy the entire main memory. So, the operating system and the processor have direct access to more processes. Therefore, it is must when the operating system carries one page in, and then another page should be thrown out. When the operating system throws a page out before the usage of the page, then in this condition, the operating system will again get the page instantly.

Instead of executing an instruction, system takes more time in the swapping of the pages. So, there is a need of a suitable page replacement algorithm.

We can see in the below diagram that the initial degree of multiprogramming is up to some extent of point (lamda), the utilization of the CPU is too high and 100% the resources of the system are used but if in case the degree of multiprogramming is increased then the utilization of the CPU will fall down extremely, and for the page replacement the system will spent its more time and time taken to finish the process execution is also increased. And this condition is known as thrashing.

Causes of Thrashing

The causes of thrashing are:

  1. Lack of Frames
  2. The high degree of multiprogramming
  1. Lack of Frames: - In this, if the process has less frames, then there will be less pages of that process that are able to exist in the memory. So, there is a need of frequent swapping in and frequent swapping out, and that may cause thrashing. So, in order to avoid thrashing, we need a suitable number of frames for allocation each process.
  2. High Degree of Multiprogramming: - In the memory, if the processes are getting increased, then the number of frames allocated to each process will decrease. So, in this way, there will be a fewer frame available for every process. And because of that, there will be more page fault, and the time of CPU get wasted only in the swapping in and out of pages, and the utilization of the CPU will also be decreased.

Recovery of Thrashing

  1. If there is already a thrashing in the system, then the mid-term scheduler will be instructed that it suspend a few of the processes to recover the system from the thrashing.
  2. To improve the thrashing, we do not permit the system to enter into a thrashing by instructing the long-term scheduler that, after the threshold, it will not take any process into the memory.

Related Topics

Banker’s Algorithm in Operating System

What is Banker’s Algorithm? Bankers algorithm is an algorithm which is used for deadlock avoidance and resource allocation. It was established by Edsger Dijkstra. The reason behind the name ‘banker’s algorithm’...

8 minutes read.

FCFS Scheduling in OS

FCFS: First Come First Serve Scheduling in OS FCFS is a non-preemptive and preemptive scheduling algorithm that is easy to understand and use. In this, the process which reaches first is...

3 minutes read.

Difference between Rotational Latency and Disk Assess Time in Disk Scheduling

Disk scheduling is used by operating systems to arrange the arrival of I/O requests to the disc. Disk scheduling is necessary because several I/O requests may occur from various processes,...

4 minutes read.

File Allocation Methods in Operating System

A file allocation method is a way that an operating system stores and retrieves files on a storage device, such as a hard drive or SSD. The file allocation method...

4 minutes read.

FCFS (First-Come-First-Serve) Disk Scheduling Algorithm

FCFS Disk Scheduling Algorithm FCFS (First-Come-First-Serve) is the easiest disk scheduling algorithm among all the scheduling algorithms. In the FCFS disk scheduling algorithm, each input/output request is served in the order...

4 minutes read.

Lock Variable Mechanism | Operating System

Lock Variable Mechanism The Lock variable mechanism is a synchronization mechanism that is implemented in a user mode. It is a software procedure. Lock variable is a solution for busy waiting that can be...

3 minutes read.

Trap vs Interrupt in Operating System

What is Trap in Operating System? A trap is a synchronous interrupt used to perform functionality when an error occurs in a user process. A trap in an operating system can...

4 minutes read.

Operating System Properties

The Properties of Operating System are: Batch processingMultitaskingMulti-programmingInteractivityReal-Time SystemDistributed Environmentspooling 1. Batch Processing In Batch Processing, the OS first gathers the data and programs together in a batch, then processing starts. The operating system...

3 minutes read.

Types of Operating System

There are various types of operating system: Simple Batch Operating SystemMultiprogramming batch Operating SystemTime-sharing Operating SystemMultiprocessor Operating SystemDistributed Operating SystemNetwork Operating SystemReal-time Operating SystemMobile Operating System Simple Batch operating system In the simple batch operating system, there is no direct communication between...

6 minutes read.

Look Disk Scheduling

Look Disk Scheduling Look disk scheduling is another type of disk scheduling algorithm. Look scheduling is an enhanced version of SCAN disk scheduling. Look disk scheduling is the same as SCAN disk scheduling,...

4 minutes read.

Thrashing in Operating System

A virtual memory system's poor performance when the same pages are loaded repeatedly due to a lack of main memory to store them in secondary memory is referred to as...

3 minutes read.

Priority Scheduling in OS

Priority Scheduling is a type of CPU Scheduling algorithm which is used for process scheduling. In Priority Scheduling, we assign some priorities to each process. The process which has higher priority among all...

5 minutes read.

SCAN Disk Scheduling Algorithm

SCAN Disk Scheduling Algorithm The SCAN disk scheduling algorithm is another type of disk scheduling algorithm. In this algorithm, we move the disk arm into a specific direction (direction can be moved towards...

4 minutes read.

Feedback Queue in Operating System

In a computer or a laptop, there is a processor which do all the tasks. The processor cannot do all the tasks at a time. So, the tasks will be...

3 minutes read.

Fixed Partitioning in Operating System

Fixed Partitioning in OS Fixed Partitioning is also known as Contiguous memory allocation. Fixed Partitioning is the easiest method, which is used to load more than one process into the main memory. In Fixed...

5 minutes read.

Simple Structure in Operating System

An operating system is a piece of software that lets the user applications talk to the hardware of the system. Because it is such a complicated structure, the operating system...

3 minutes read.

Virtual Memory in Operating System

What is Virtual Memory Virtual Memory is a storage scheme in which the users have an illusion that users have a significant amount of Main Memory. We can perform this by taking a...

3 minutes read.

Contiguous Memory Allocation in Operating System

Memory is a place where data, facts, figures, and information are stored for temporary or permanent access the data in future, which is also considered as the storage place. Allocation of...

4 minutes read.

Inter Process Communication in Operating System

Inter-Process Communication or IPC refers to the methods and techniques that allow processes (programs or tasks) to communicate with each other within a computer system. This is typically done through...

3 minutes read.

Deadlock Prevention in Operating System

Deadlock Prevention The conditions which we used for deadlock prevention are: Mutual ExclusionHold and WaitNo PreemptionCircular Wait 1. Mutual Exclusion: - From the resource point of view, the mutual exclusion means that simultaneously more...

4 minutes read.