Swapping has been introduced to offer a backup on disk for unmapped pages. We know from the previous discussion that there are three kinds of pages that must be handled by the swapping subsystem:
Like demand paging, swapping must be transparent to programs. In
other words, no special instruction related to swapping needs to be
inserted into the code. To understand how this can be done, recall from
the section "Regular
Paging" in Chapter 2
that each Page Table entry includes a
Present flag. The kernel exploits this flag to
signal that a page belonging to a process address space has been swapped
out. Besides that flag, Linux also takes advantage of the remaining bits
of the Page Table entry to store into them a "swapped-out page
identifier" that encodes the location of the swapped-out page on disk.
When a Page Fault exception occurs, the corresponding exception handler can
detect that the page is not present in RAM and invoke the function that
swaps in the missing page from disk.
The main features of the swapping subsystem can be summarized as follows:
Set up "swap areas" on disk to store pages that do not have a disk image.
Manage the space on swap areas allocating and freeing "page slots" as the need occurs.
Provide functions both ...