We know Main memory of a system is limited and often not enough for all the programs to exist at the same time. So in order to deal with this we swap in and out programs from the memory. This is called Swapping.
Swapping
A process can not be executed when it is not completely or partially in the main memory. A process that is not being executed by the CPU can be swapped out of the memory to a backing storage like a hard drive or a solid-state drive for freeing the memory for other processes to take.
A process which is being executed or will be executed can also be swapped in to the memory. Swapping is a technique that is used to swap processes into the main memory to execute them and swaps out the processes when they are not being executed or when required.
The swapping is done by the swapper. Consider that the dispatcher tries to load a process to CPU to execute but the process is not in the memory. It will call the swapper to swap the process in the memory and if there is not enough space, swap out some of the processes.
Benefits Of Swapping
Following are some benefits of swapping.
- It allows higher degree of multiprogramming.
- It allows dynamic reloaction.
- It provides better memory utilization.
- It can be applied on priority based scheduling algorithms to improve performance.