Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 18: Page Reclaim and Swapping


for synchronous writeout. In the first case, writeout requests are handed to the block layer without fur-
ther ado, while in the second case, the kernel waits for the write operations to complete after issuing a
corresponding request.

Shrinking the InactiveList


Asshrink_inactive_listis responsible only for removing pages from thezone->inactive_list
chunk-by-chunk, its implementation is not particularly complicated, as the code flow diagram in
Figure 18-16 shows.

Put back unfreeable
pages to LRU lists

Return number of reclaimed pages

Iterate until desired number of pages have been reclaimedor the maximal number hasbeen processed

Handle direct reclaim

shrink_page_list

isolate_lru_pages

lru_add_drain

shrink_cache

Figure 18-16: Code flow diagram for
shrink_cache.

The first step is to invoke the familiarlru_add_drainfunction to distribute the current content of the
LRU cache to the lists of active and inactive pages in the various zones. This is necessary to coverall
inactive pages currently present in the system.

A loop is then repeatedly executed until either the maximum permissible number of pages has been
scanned or the required number of pages has been written back. Both numbers are passed to the proce-
dure as a parameter.

Within the loop, theisolate_lru_pagesfunction, as discussed in Section 18.6.5, is invoked to remove a
bundle of pages from the back of the list of inactive pages so that the most inactive pages are swapped
out by preference. The kernel essentially passes the finished list toshrink_page_list, which initiates
writing back the pages on the list. However, things are slightly complicated by lumpy writeback:

mm/vmscan.c
nr_taken = isolate_lru_pages(sc->swap_cluster_max,
&zone->inactive_list,
&page_list, &nr_scan, sc->order,
(sc->order > PAGE_ALLOC_COSTLY_ORDER)?
ISOLATE_BOTH : ISOLATE_INACTIVE);
nr_active = clear_active_flags(&page_list);
...
/* Handle page accounting */
...
nr_freed = shrink_page_list(&page_list, sc, PAGEOUT_IO_ASYNC);
Free download pdf