Swapping
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:
Pages that belong to an anonymous memory region of a process (User Mode stack or heap)
Dirty pages that belong to a private memory mapping of a process
Pages that belong to an IPC shared memory region (see the section "IPC Shared Memory" in Chapter 19)
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 ...
Get Understanding the Linux Kernel, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.