paging v. swapping

Joe Barrera (
Fri, 15 May 1998 13:17:43 -0700

I received a question or two about the difference between paging and
swapping. Here's my answer. One difficulty is that the meaning of the terms
has changed a bit over the years. In particular, "swapping out a process"
used to be simultaneously a scheduling operating and a memory management

With paging, there is no explicit connection between how much of a program's
virtual memory is resident and whether that process is schedulable. A
program in a tight loop might only have one or two pages mapped with the
majority of it being paged out. In other words, the OS just grabs pages away
from processes, and doesn't give them back unless the process asks for them
again (via a page fault).

With swapping, the OS guarantees that the program is resident before
scheduling it. The program may also explicitly manage swapping in areas of
memory, by asking the OS to swap the data in before the program uses it, and
telling the OS it's done afterwards. (Windows allows memory to be managed
this way.)

Paging is preferred over swapping because it does a better job of keeping
only the most important data in memory. However, paging requires restartable
instructions, so that an instruction can be restarted after a page fault has
been handled. You also need an MMU or a TLB to handle the
virtual-to-physical address conversions.

Some systems, like VMS, provide both paging and swapping to guard against
thrashing. Thrashing is when there are too many processes and not enough
physical memory, and so by the time any process has paged in a page that it
needs, it finds that another page that it needs has been stolen by the
operating system to satisfy some other process's page fault. So VMS (for
example) picks a subset of processes that it will schedule, and will swap
out the others. In other words, when VMS sees thrashing, it performs triage
so that some processes can make progress. The only bad thing about a
combined paging/swapping approach is that it makes the scheduler even more
complex, because you don't want to keep the same processes swapped out

- Joe

Joseph S. Barrera III < <>>
< <>>
Phone, Office: (415) 778-8227; Cellular: (415) 601-3719; Home: (650)
Microsoft Research (BARC), 301 Howard Street, San Francisco, CA 94105-6605
The opinions expressed in this message are my own personal views and do not
reflect the official views of Microsoft Corporation.