Swapping in Pages

Swap in must take place when a process attempts to address a page within its address space that has been swapped out to disk. The Page Fault exception handler triggers a swap-in operation when the following conditions occur (see Section 8.4.2):

  • The page including the address that caused the exception is a valid one—that is, it belongs to a memory region of the current process.

  • The page is not present in memory—that is, the Present flag in the Page Table entry is cleared.

  • The Page Table entry associated with the page is not null, which means it contains a swapped-out page identifier.

As described in Section 8.4.3, the handle_pte_fault( ) function, invoked by the do_page_fault( ) exception handler, checks whether the Page Table entry is non-null. If so, it invokes a quite handy do_swap_page( ) function to swap in the page required.

The do_swap_page( ) Function

This do_swap_page( ) function acts on the following parameters:

mm

Memory descriptor address of the process that caused the Page Fault exception

vma

Memory region descriptor address of the region that includes address

address

Linear address that causes the exception

page_table

Address of the Page Table entry that maps address

orig_pte

Content of the Page Table entry that maps address

write_access

Flag denoting whether the attempted access was a read or a write

Contrary to other functions, do_swap_page( ) never returns 0. It returns 1 if the page is already in the swap cache (minor fault), 2 if the page ...

Get Understanding the Linux Kernel, Second 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.