Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 18: Page Reclaim and Swapping


Although the kernelreclaimsall pages in the same way regardless of their backing
store, this does not apply for the opposite direction. The method described here is
only for anonymously mapped data that are read from one of the system’s swap
areas. When a page belonging to a file mapping is not present, the mechanisms
discussed in Chapter 8 are responsible for providing the data.

18.8.1 Swapping Pages in


You already know from Chapter 4 that page faults as a result of accessing a swapped-out page are han-
dled bydo_swap_pagefrommm/memory.c. As the associated code flow diagram in Figure 18-19 shows,
it is much easier to swap a page in than to swap it out, but it still involves more than just a simple read
operation.

do_swap_page

grab_swap_token

swapin_readahead

read_swap_cache_async

lock_page

mark_page_accessed

swap_free

page_add_rmap

lookup_swap_cache failed?

Figure 18-19: Code flow diagram fordo_swap_page.

The kernel must not only check whether the requested page is still or already in the swap cache, but it
also uses a simple readahead method to read several pages from the swap area in a chunk to anticipate
future possible page faults.

As discussed in Section 18.4.1, the swap area and slot of a swapped-out page are held in the page
table entry (the actual representation differs from machine to machine). To obtain general values, the
kernel first invokes the familiarpte_to_swp_entryfunction to aswp_entry_tinstance with machine-
independent values that uniquely identify the page.

On the basis of these data,lookup_swap_cachechecks whether the required page is in the swap cache.
This applies if either the data have not yet been written or the data are shared and have already been
read earlier by another process.
Free download pdf