Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 18: Page Reclaim and Swapping


the allocation order for which the current reclaim pass works must be below or equal to
PAGE_ALLOC_COSTLY_ORDER, that is, less than or equal to eight pages. Besides, the page must
fulfill one of the following conditions:

❑ The page is mapped into a page table as checked bypage_mapped— see Section 4.8.3 —
or is used in a user-mode virtual address space.
❑ The page is contained in the swap cache.
❑ The page is contained in an anonymous mapping.
❑ The page is mapped into userland via a file mapping. This case is not checked with the help
of page tables, but bymapping->i_mmapandmapping_i_map_nonlinear, which contain the
mapping information for regular and nonlinear mappings.

page_mapping_in_usechecks for these conditions. Fulfilling any of them does not mean that
the page cannot be reclaimed at all — the pressure from high allocation orders that wait to be
fulfilled just needs to be large enough.

Recall thatshrink_inactive_listcan callshrink_page_listtwice: first in asynchronous and then
in synchronous writeback mode. Therefore, it canhappen that the considered page is currently under
writeback as indicated by the page flagPG_writeback. If the current pass requests synchronous write-
back, thenwait_on_page_writebackis used to wait until all pending I/O operations on the page have
been finished.

If the page currently being considered byshrink_page_listis not associated with a backing store, then
the page has been generated anonymously by a process. When pages of this type must be reclaimed,
their data are written into the swap area. When a page of this type is encountered and no swap slot has
been reserved yet,add_to_swapis invoked to reserve a slot and add the page to the swap cache. At the
same time, the relevantpageinstance is provided withswapper_space(see Section 18.4.2) as a mapping
so that it can be handled in the same way as all other pages that already have a mapping.

If the page is mapped into the address tables of one or more processes (as before, checked using
page_mapped), the page table entries that point to the page must be removed from the page tables
ofallprocesses that reference it. The rmap subsystem provides thetry_to_unmapfunction for this
purpose; it unmaps the page fromallprocesses that use it (we do not examine this function in detail
because its implementation is not particularly interesting). In addition, the architecture-specific
page table entries are replaced with a reference indicating where the data can now be found. This
is done intry_to_unmap_one. The necessary information is obtained from the page’s address space
structure, which contains all backing store data. It is important that two bits arenotset in the new page
table entry:

❑ A missing_PAGE_PRESENTbit indicates that the page has been swapped out. This is important
when a process accesses the page: A page fault is generated, and the kernel needs to detect that
the page has been swapped out.
❑ A missing_PAGE_FILEbit indicates that the page is in the swap cache. Recall from Section 4.7.3
that page table entries used for nonlinear mappings also lack_PAGE_PRESENT,butcanbedistin-
guished from swap pages by aset_PAGE_FILEbit.
Clearing the page table entry withptep_clear_flushdelivers a copy of the previous page
table entry (PTE). If it contains the dirty bit, then the page was modified by some user during
the reverse mapping process. It needs to be synchronized with the backing store (in this case
Free download pdf