Signup/Sign In
PUBLISHED ON: MARCH 10, 2021

Swapping in Operating System

In this tutorial, we will be covering the concept of swapping in the Operating system.

Swapping is a memory management technique and is used to temporarily remove the inactive programs from the main memory of the computer system. Any process must be in the memory for its execution, but can be swapped temporarily out of memory to a backing store and then again brought back into the memory to complete its execution. Swapping is done so that other processes get memory for their execution.

Due to the swapping technique performance usually gets affected, but it also helps in running multiple and big processes in parallel. The swapping process is also known as a technique for memory compaction. Basically, low priority processes may be swapped out so that processes with a higher priority may be loaded and executed.

Let us understand this technique with the help of a figure given below:

The above diagram shows swapping of two processes where the disk is used as a Backing store.

In the above diagram, suppose there is a multiprogramming environment with a round-robin scheduling algorithm; whenever the time quantum expires then the memory manager starts to swap out those processes that are just finished and swap another process into the memory that has been freed. And in the meantime, the CPU scheduler allocates the time slice to some other processes in the memory.

The swapping of processes by the memory manager is fast enough that some processes will be in memory, ready to execute, when the CPU scheduler wants to reschedule the CPU.

A variant of the swapping technique is the priority-based scheduling algorithm. If any higher-priority process arrives and wants service, then the memory manager swaps out lower priority processes and then load the higher priority processes and then execute them. When the process with higher priority finishes .then the process with lower priority swapped back in and continues its execution. This variant is sometimes known as roll in and roll out.

There are two more concepts that come in the swapping technique and these are: swap in and swap out.

Swap In and Swap Out in OS

The procedure by which any process gets removed from the hard disk and placed in the main memory or RAM commonly known as Swap In.

On the other hand, Swap Out is the method of removing a process from the main memory or RAM and then adding it to the Hard Disk.

Advantages of Swapping

The advantages/benefits of the Swapping technique are as follows:

  1. The swapping technique mainly helps the CPU to manage multiple processes within a single main memory.

  2. This technique helps to create and use virtual memory.

  3. With the help of this technique, the CPU can perform several tasks simultaneously. Thus, processes need not wait too long before their execution.

  4. This technique is economical.

  5. This technique can be easily applied to priority-based scheduling in order to improve its performance.

Disadvantages of Swapping

The drawbacks of the swapping technique are as follows:

  1. There may occur inefficiency in the case if a resource or a variable is commonly used by those processes that are participating in the swapping process.

  2. If the algorithm used for swapping is not good then the overall method can increase the number of page faults and thus decline the overall performance of processing.

  3. If the computer system loses power at the time of high swapping activity then the user might lose all the information related to the program.



About the author:
Aspiring Software developer working as a content writer. I like computer related subjects like Computer Networks, Operating system, CAO, Database, and I am also learning Python.