Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 18: Page Reclaim and Swapping


Performing Page Reclaim


shrink_page_listtakes a list of pages selected for reclaim and attempts to write back to the appro-
priate backing store. This is the last step performed by the policy algorithm — everything else is the
responsibility of the technical part of swapping. Theshrink_page_listfunction forms the interface
between the kernel’s two subsystems. The associated code flow diagram is shown in Figure 18-17. Some
of the many corner cases this function has to deal with are ignored so that inessential details do not
obstruct the view on the essential principles of operation.

Check if page must be kept,
or is being written back

Anonymous page without swap slot?

page_mapped?

pageDirty?

shrink_page_list

Part 2 Part 3

Update statistics

Yes No

Iterate over given set of pages

try_to_unmap

add_to_swap

Figure 18-17: Code flow diagram forshrink_page_list(Part 1)

Here, too, the basic framework of the function is a loop that iterates over the various elements of the
page list until there are none left. As the pages are either passed permanently to the lower layers of the
swapping subsystem or are put on a second list if they cannot be reclaimed, it is certain that the loop will
be finished at some time or other and will not continue to run endlessly.

In each loop iteration, a page is selected from the page list (the list is processed from head to tail again).
First of all, the kernel must decide if the page mustbe kept. This can happen for the following reasons:

❑ The page is locked by some other part of the kernel. If this is the case, the page is not reclaimed;
otherwise, it is locked by the current path and will be reclaimed.
❑ The second condition is more complicated. The following code snippet shows the conditions
under which a page isnotreclaimed, but returned to theactiveLRU list:
mm/vmscan.c
referenced = page_referenced(page, 1);
/* In active use or really unfreeable? Activate it. */
if (sc->order <= PAGE_ALLOC_COSTLY_ORDER &&
referenced && page_mapping_inuse(page))
/* Set PG_active flag and keep page */

page_referencedchecks (as discussed above) if the page was recently referenced by any of
its users. This alone, however, is not sufficient to prevent reclaiming the page. Additionally,
Free download pdf