16.5. Page Swap-Out
Section 16.7 explains when pages are swapped out. As we indicated at the beginning of the chapter, swapping out pages is a last resort and appears as part of a general strategy to free memory that uses other tactics as well. In this section, we show how the kernel performs swap-out. This is achieved by the swap_out( ) function, which acts on the following parameters.
priority
An integer value ranging from to 6 that specifies how much time the kernel should spend trying to locate a page to be swapped; lower values correspond to longer search times. We shall describe how this parameter is set in Section 16.7.5 later in this chapter.
gfp_mask
If the function has been invoked as a consequence of a memory allocation request, this parameter is a copy of the gfp_mask parameter passed to the allocator function (see Section 6.1.1 in Chapter 6. The parameter tells the kernel how to treat the page, notably how urgent the request is and whether the kernel control path can be suspended.
The swap_out( ) function scans existing processes and tries to swap out the pages referenced in each process's page tables. It terminates as soon as one of the following conditions occurs:
The function succeeds in swapping out a page.
The function performs some blocking operation. It doesn't bother resuming activity because the process being examined could have been destroyed while the current process was sleeping, and thus no further page scanning would be needed.
The function failed to ...
Get Understanding the Linux Kernel 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.