41

What are the differences between Swapping and Paging with reference to Process Memory Management ?

Also guide me to the tutorials if any where I could get more information.

7 Answers 7

63

Swapping refers to copying the entire process address space, or at any rate, the non-shareable-text data segment, out to the swap device, or back, in one go (typically disk).

Whereas paging refers to copying in/out one or more pages of the address space. In particular, this is at a much finer grain. For example, there are ~250,000 4 KB pages in a 1 GB RAM address space.

Swapping was used in the early days, e.g. DEC pdp-11 era Unix, 1975-80 ish. For all you could want to know and more, may I recommend The Lions Document a.k.a. Lions' Commentary on Unix 6th Ed. with Source Code, John Lions, ISBN 1-57398-013-7?

You will surely appreciate Chapter 14, "Program Swapping" which begins: "Unix, like all time-sharing systems, and some multiprogramming systems, uses "program swapping" (also called "roll-in/roll-out") to share the limited resource of the main physical memory among several processes."

Paging (on Unix) arrived with the BSD (Berkeley Systems Distribution) on the VAX-11/780 starting around 1980.

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.g. base and bound, or a simple one level fixed size page mapping table (e.g. divide the 64 KB data address space into 8, 8KB pages in a larger physical address space (256 KB ... 4 MB)).

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. The machine also needs to automatically (transparently to the application program) fetch and interpret page table entries as necessary to map each virtual address to its physical address, and/or take a page fault exception to enable the OS to make the page accessible and/or schedule an I/O to load it to physical RAM.

Happy hacking!

5

Although both terms are considered distinct by the, say, mainstream academic media, the fact is that some authors do use them as synonyms. To quote the excellent book on computers architectures written by David and Sarah Harris (Digital Design and Computer Architecture), "writing the physical page back to disk and reloading it with a different virtual page is called swapping,so the disk in a virtual memory system is sometimes called swap space". So, Tyler actually answered the question correctly and his answer should not be downvoted at all.

5

Jan did a great job explaining in detail but if you just want a birds eye difference here is what each does notice the bold font to indicate the main difference.

Paging: is when individual memory segments, or pages, are moved to or from the swap area/swap partition

Swapping: is when entire processes were swapped and moved to or from the swap area/swap partition

4

None. It's usually referred too as swapping on unix platforms, and paging on Windows. Same concept though.

2
  • 1
    @LinuxPenseur: although I agree with you to some extent, in practice the terms are often used interchangeably. Nov 10, 2011 at 21:47
  • @LinuxPenseur The comment is inappropriate. You should delete it. Moreover, I believe that the difference is a matter of convention, which Tyler Eaves has provided but you did not!!!
    – Val
    May 22, 2013 at 14:07
2

Great answer by Siddharth Teotia over on Quora that helped me understand these concepts:

Swapping is the procedure of copying out the entire process(its address space) from main memory to some sort of secondary storage(typically hard disk or tape storage). Usually this is done as a result of CPU scheduling.

[...]

The most important thing to note here is that the complete process is swapped in/out. There is no granularity over here as to what part of process's address space is swapped back to disk. The complete process image in its entirety is swapped back to disk. This should be very clear when we are trying to understand the differences between paging and swapping.

Paging on the other hand is a memory allocation technique that allows the physical address space of the process to be non-contiguous. In other words, a process can be allocated memory wherever it is available and the unit of allocation is the size of page or frame (usually 4KB , but it is system dependent). Wherever a free frame is available in main memory, a physical page belonging to the process can be loaded into it and the page table of process will take care of mapping the logical address (logical page numbers) to correct physical frames in memory (may or may not be contiguous).

[...]

For more detail see his entire answer: https://www.quora.com/What-is-difference-between-paging-and-swapping

0

paging is applicable in case of active process, only active process can perform paging. Swapping is done by inactive proccess

0

Most books are outdated due to fast development of super computers. When people try to describe they merely create new words, this later leads to much confusion. We can easily follow up with memory, which is read/write by CPU. This main memory is classified as RAM. Earilier computer worked mostly one single-process, called "real mode", and computed result could be saved into disk, namely ROM. As you see, the physical disk corresponds to the main memory. Since this memory is huge, people cut it into spaces, namely page. Correspondingly the disk(or secondary memory) cut into frame. Once mapping page and frame, we then get page table.

Current computers work in "protected mode", seemingly multi-process, this is because one CPU can only process one task at one time. Someone might ask what if there are as many CPU as possible? This makes no difference if we watch for just one CPU ---- it is occupied by one certain task unless the task is not real-time. Tasks that can work in background gives the possibility of swap.

At this point, we could easily differ the two terms:

Swapping is for process, between main process(thus including main memory) and a certain background process; Pagging is for pages(frames), between active pages(in main memory) and secondary memory(e.g. disk).

By coincidence, disk can be used in both conditions, especailly in nowadays since all memory is highly allocate/free by MMU. Thus, disk I/O performance is critical to the highly abstraced memory, namely VM.

To most programmers, memory size is no longer a problem now, they can easily allocate small amounts of memory, much smaller than 4KB(4096 page size), using malloc or similar calls efficiently. CPU generates the logical address for a process which consists of two parts that are page number and the page offset. The logical address corresponds to physical address in page table. This is same as looking up word in a dictionary ---- goto page number then goto page offset. What differs is the mmu table is made up by PGD (-> PUD) -> PMD -> PTE, where PUD only used in 64bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.