The main difference between swapping and paging is that, in swapping, the processes move back and forth between the main memory and secondary memory while, in paging, equal size memory blocks, called pages, move between the main memory and the secondary memory.
An operating system handles the main functionalities of the computer system. It handles hardware devices, performs process scheduling, file handling, and many other tasks. Among them, one is memory management. It keeps track of all memory locations and status of whether they are allocated or free. Two memory management techniques of an operating system are swapping and paging.
Key Areas Covered
1. What is Swapping
– Definition, Functionality
2. What is Paging
– Definition, Functionality
3. What is the Difference Between Swapping and Paging
– Comparison of Key Differences
Logical Address, Main Memory, Paging, Physical Address, Swapping, Virtual Memory
What is Swapping
Swapping is the mechanism of moving the processes into the main memory from the secondary memory and moving the processes out of the main memory back to the secondary memory. For example; the programs are initially in the hard disk or secondary memory. When it is necessary to execute them, these programs move into the main memory. The CPU can access the programs faster in the main memory than in the secondary memory.
After completing the execution, the programs go back to the hard disk. Here, the memory allocated to the executing programs gets freed after completing the execution. Then, a new program can use this freed memory. A program in execution is also called a process. Even though swapping affects the performance, it allows running multiple processes in parallel. Therefore, it is also a technique for memory compaction.
What is Paging
Virtual memory is a type of memory that allows the programmers to use more memory for a program than the available main memory. For example, if the main memory is 8GB and the virtual memory is 16GB, the programmer can use that 16GB virtual memory to execute the program. Here, the paging technique helps to implement virtual memory. It divides the process address space into same size blocks called pages. Similarly, it divides the main memory into small fixed-sized blocks called frames.
A page address is called a logical address. The equation is as follows.
Logical address = Page number + page offset
The frame address is called the physical address. The equation is as follows.
Physical address = Frame number + page offset
When allocating a frame to a page, the logical address translates into a physical address. Moreover, the page map table keeps records on the pages of processes and the corresponding main memory frames throughout the execution of the program.
When executing a process, the corresponding pages of that process loads into any available frame in the main memory. When the computer runs out of main memory, the OS moves the unwanted pages to secondary memory and free up the main memory for other processes. This process continues throughout the execution of the program.
Difference Between Swapping and Paging
Swapping is a mechanism in which a process can be swapped temporarily out of main memory to secondary storage and make that memory available to other processes. In contrast, paging is a memory management technique in which a computer stores and retrieves data from secondary storage for use in main memory. These definitions explain the fundamental difference between swapping and paging.
In swapping, the processes move back and forth between the main memory and secondary memory. In paging, equal size memory blocks, called pages, move between the main memory and secondary memory. Hence, the functionality is the main difference between swapping and paging.
Flexibility is also a difference between swapping and paging. Paging is more flexible than swapping because it transfers pages.
Number of Processes in the Main Memory
In swapping, there are more processes in the main memory. However, in paging, there are fewer processes in the main memory. Thus, this is another difference between swapping and paging.
While swapping is suitable for heavy workloads, paging is suitable for small to medium workloads.
One other difference between swapping and paging is the usage. Swapping helps the CPU to access processes faster while paging helps to implement virtual memory.
Swapping and paging are two memory management techniques. The main difference between swapping and paging is that, in swapping, the processes move back and forth between the main memory and secondary memory while in paging, equal size memory blocks called pages moves between the main memory and secondary memory.
1. “Swapping, Swap in, Swap out in Operating Systems (OS).” State Transition Diagram with Example in Software Engineering, Available here.
2. “Paging.” Wikipedia, Wikimedia Foundation, 24 Nov. 2018, Available here.
1. “Memory paging” By Чоймаа – Own work (CC BY-SA 3.0) via Commons Wikimedia
Leave a Reply