O'Reilly logo

Understanding the Linux Kernel by Marco Cesati, Daniel P. Bovet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required