What is the difference between swapping and paging




















Paging vs Swapping. Paging is a memory management method used by operating systems. Paging allows the main memory to use data that is residing on a secondary storage device. These data are stored in the secondary storage device as blocks of equal size called pages. Paging allows the operating system to use data that will not fit in to the main memory. Swapping is a term that is used to describe the act of moving all the segments belonging to a process between the main memory and a secondary storage device.

To swap a process means to move that entire process out of main memory and to the swap area on hard disk, whereby all pages of that process are moved at the same time. This carried the disadvantage of a performance penalty. When a swapped out process becomes active and moves from the sleep queue to the run queue, the kernel has to load an entire process perhaps many pages of memory back into RAM from the swap space.

With large processes this is understandably slow. Enter paging. Paging was introduced as a solution to the inefficiency of swapping entire processes in and out of memory at once. With paging, when the kernel requires more main memory for an active process, only the least recently used pages of processes are moved to the swap space. Therefore when a process that has paged out memory becomes active, it is likely that it will not need access to the pages of memory that have been paged out to the swap space, and if it does then at least only a few pages need to be transferred between disk and RAM.

For efficient paging, the kernel needs to keep regular statistics on the memory activity of processes it keeps track of which pages a process has most recently used. These pages are known as the working set. When the kernel needs memory, it will prefer to keep pages in the working sets of processes in RAM as long as possible and to rather page out the other less recently used pages as they have statistically been proven to be less frequently accessed, and therefore unlikely to be accesses again in the near future.

Paging is more flexible than swapping because it transfers pages. 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. She is passionate about sharing her knowldge in the areas of programming, data science, and computer systems. View all posts. Leave a Reply Cancel reply. For all you could want to know and more, may I recommend The Lions Document a.

Lions' Commentary on Unix 6th Ed. Paging is also usually associated with per-page memory attributes no access, read-only, read-write, no execute, executable , and various virtual memory management tricks like demand-zero-filled pages, copy-on-write pages, and so forth. Hardware-wise, swapping can be performed without any memory management HW whatsoever, although the early machines employed a simple memory mapping scheme e.

In contrast, paging requires page-granularity virtual memory page table entries, which typically encode the physical address of the page, PTE bits such as valid, read, write, etc.



0コメント

  • 1000 / 1000