Difference Swapping and Paging

2019-01-31 09:33发布

问题:

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.

回答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!



回答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.



回答3:

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



回答4:

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



回答5:

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