Open In App

Swapping in Operating System

Last Updated : 18 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Pre-requisites: Memory Management in Operating System

To increase CPU utilization in multiprogramming, a memory management scheme known as swapping can be used. Swapping is the process of bringing a process into memory and then temporarily copying it to the disc after it has run for a while. The purpose of swapping in an operating system is to access data on a hard disc and move it to RAM so that application programs can use it. It’s important to remember that swapping is only used when data isn’t available in RAM. Although the swapping process degrades system performance, it allows larger and multiple processes to run concurrently. Because of this, swapping is also known as memory compaction.  The CPU scheduler determines which processes are swapped in and which are swapped out. Consider a multiprogramming environment that employs a priority-based scheduling algorithm. When a high-priority process enters the input queue, a low-priority process is swapped out so the high-priority process can be loaded and executed. When this process terminates, the low priority process is swapped back into memory to continue its execution. Below figure shows the swapping process in operating system:

Swapping in Operating System

 

Swapping has been subdivided into two concepts: swap-in and swap-out.

  • Swap-out is a technique for moving a process from RAM to the hard disc.
  • Swap-in is a method of transferring a program from a hard disc to main memory, or RAM.

Advantages

  • If there is low main memory so some processes may has to wait for much long but by using swapping process do not have to wait long for execution on CPU.
  • It utilize the main memory.
  • Using only single main memory, multiple process can be run by CPU using swap partition.
  • The concept of virtual memory start from here and it utilize it in better way.
  • This concept can be useful in priority based scheduling to optimize the swapping process.

Disadvantages

  • If there is low main memory resource and user is executing too many processes and suddenly the power of system goes off there might be a scenario where data get erase of the processes which are took parts in swapping.
  • Chances of number of page faults occur
  • Low processing performance 

Only one process occupies the user program area of memory in a single tasking operating system and remains in memory until the process is completed.
When all of the active processes in a multitasking operating system cannot coordinate in main memory, a process is swapped out of main memory so that other processes can enter it.

For more information, you can refer Difference between Paging and Swapping in OS, and the Difference between Swapping and Context Switching


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads