Paging and Swapping are two memory management strategies. For execution, each process is required to be placed in main memory. Swapping and Paging both places the process in main memory for execution. Swapping could be added to any CPU scheduling algorithm where processes are swapped from main memory to back store and swapped backed to main memory. Paging allows the physical address space of a process to be noncontiguous. Let us discuss the differences between paging and swapping with the help of comparison chart shown below.
Content: Paging Vs Swapping
|Basis of Comparison||Paging||Segmentation|
|Basic||Paging allows the memory address space of a process to be noncontiguous.||Swapping allows multiple programs to run parallelly in the operating system.|
|Flexibility||Paging is more flexible as only pages of a process are moved.||Swapping is less flexible as it moves entire process back and forth between main memory and back store.|
|Multiprogramming||Paging allows more processes to reside in main memory||Compared to paging swapping allows less processes to reside in main memory.|
Definition of Paging
Paging is a memory management scheme, which allots a noncontiguous address space to a process. Now, when a process’s physical address can be non-contiguous the problem of external fragmentation would not arise.
Paging is implemented by breaking the main memory into fixed-sized blocks that are called frames. The logical memory of a process is broken into the same fixed-sized blocks called pages. The page size and frame size is defined by the hardware. As we know, the process is to be placed in main memory for execution. So, when a process is to be executed, the pages of the process from the source i.e. back store are loaded into any available frames in main memory.
Now let us discuss how paging is implemented. CPU generates the logical address for a process which consists of two parts that are page number and the page offset. The page number is used as an index in the page table.
The page table contains the base address of each page that loaded in main memory. This base address is combined with page offset to generate the address of the page in main memory.
Every operating system has its own way of storing page table. Most of the operating system has a separate page table for each process.
Definition of Swapping
For execution, each process must be placed in the main memory. When we need to execute a process, and the main memory is entirely full, then the memory manager swaps a process from main memory to backing store by evacuating the place for the other processes to execute. The memory manager swaps the processes so frequently that there is always a process in main memory ready for execution.
Due to address binding methods, the process that is swapped out of main memory occupies same address space when it is swapped back to the main memory if the binding is done at the assembly or load time. If the binding is done at execution time, the process can occupy any available address space in main memory as addresses are computed at the execution time.
Although the performance is affected by swapping, it helps in running multiple processes in parallel.
Key Differences Between Paging and Swapping in OS
- The basic difference between paging and swapping is that paging avoids external fragmentation by allowing the physical address space of a process to be noncontiguous whereas, swapping allows multiprogramming.
- Paging would transfer pages of a process back and forth between main memory, and secondary memory hence paging is flexible. However swapping swaps entire process back and forth between the main and secondary memory and hence swapping is less flexible.
- Paging can allow more processes to be in main memory than the swapping.
Paging avoids external fragmentation as utilizes the non-contiguous address spaces in the main memory. Swapping could be added to the CPU scheduling algorithm where process frequently needs to be in and out of main memory.