Swapping – Memory Management

By | October 22, 2021
  • Swapping is a technique of removing a process from main memory and storing it into secondary memory, usually a hard disk temporarily and then bringing it back into main memory for continued execution.
  • Swapping is a memory management technique used in multiprogramming environments which have limited memory capacity.
  • Thus, in multiprogramming swapping may be used to increase the number of process sharing the CPU.
  • In a uni-tasking operating system, only one process occupies the user program area in the memory and it remains there until the process completes.
  • However, in multiprogramming, there may arise a situation when all the active processes cannot be accommodated in the main memory.
  • In this case, one of the processes may be moved out temporarily from main memory to secondary memory so as to create a space for another active process.
  • This action of moving a process out of main memory is called swap out and the action of moving a process into the main memory is called swap in.
  • The area on the disk where the swapped out processes are stored is called the swap space.
  • For example, in a multiprogramming environment with a round robin CPU scheduling algorithm, the memory manager swaps out the processes whose quantum has expired. In this way it creates memory space for other processes.

Swapping of two processes

  • In priority based scheduling, whenever a higher-priority process arrives and wants service, the memory manager can swap out lower-priority process in order to load & execute higher priority process. When the higher priority process finishes, the lower priority process can be swapped back. This type of swapping is called roll out, roll in.
  • Figure shows the concept of swapping of processes in multitasking system. The various processes are in user program area or space of memory and operating system occupies one part of the memory.

No space for process D


  • Initially memory is allocated to processes A, B and C. The process D requires to be loaded into memory for execution but the available space is not sufficient (Fig. a).

Process A swapped out (b)

  • The process A is swapped out of the memory and is stored in the secondary storage to create space for process D (Fig. b). Lastly process D is swapped in the memory (Fig. c).

Process D swapped in (c)

This usually depends on the type of address binding i.e. the address binding is static or dynamic: 

  1. If the address binding is static i.e. done at assembly or load time, then the process will be swapped to same space. It cannot be moved to different location.
  2. If the binding is dynamic i.e. done at execution or run time then a process can be swapped into a different memory space because the physical addresses are computed during execution time.
  • Swapping can be applied to both variable and fixed size partitioned memory.
  • Swapping should be very fast so that it does not become a large overhead to execute a process.

Leave a Reply

Your email address will not be published. Required fields are marked *