Difference Swapping and Paging

54,421

Solution 1

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!

Solution 2

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.

Solution 3

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

Solution 4

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

Solution 5

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

Share:
54,421
nitin_cherian
Author by

nitin_cherian

nitin_cherian: Sneior Lead Engineer at ADVA Optical Networking, Bangalore, India Languages worked on: C, C++, Python Operating systems worked on: Linux Current Interests: Python Language, Game development in Python. Crafting Quality code in Python. Online Courses: Cryptography1, Interactive Programming in Python @ www.coursera.com. Hobbies: Reading short articles in newspaper and magazines.

Updated on September 09, 2020

Comments

  • nitin_cherian
    nitin_cherian over 3 years

    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.

  • 0xC0000022L
    0xC0000022L over 12 years
    @LinuxPenseur: although I agree with you to some extent, in practice the terms are often used interchangeably.
  • Val
    Val almost 11 years
    @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!!!