Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 18: Page Reclaim and Swapping


Iterate over all suitable zones

Enough pages
freed?

Iterate over decreasing priorities

Determine number of pages on LRU list

Stop scanning

Pdflush required?

Possible congestion?

Highest priority?

try_to_free_pages

shrink_zone

shrink_zone

shrink_slab

wakeup_pdflush

blk_congestion_wait

Store priority

disable_swap_token

Figure 18-22: Code flow diagram fortry_to_free_pages.

It is first necessary to determine the number of pages in the LRU cache as this information is required as
the parameter for subsequent functions. The kernel acquires this information as before inbalance_pgdat.
Again, similar to before, the main part oftry_to_free_pagesis a large loop that runs through all priori-
ties fromDEF_PRIORITYto 0. If the kernel operates with highest priority, then the swap token is disabled.


The decision as tohow manypages are to be freed is delegated toshrink_zonesimplemented in
mm/vmscan.c.


Theshrink_zonesfunction is not the same as theshrink_zonefunction discussed
above — note the ‘‘s’’ at the end.

As in thekswapdmechanism,shrink_zonesiterates over all zones of the current NUMA node and
invokesshrink_zoneif this is possible. The kernel dispenses with the call if there are no pages in a zone,
if all pages in the zone are pinned, or if the current CPU is not permitted to act on the zone; but this is
very rare.


After the slab caches have been shrunk withshrink_slab— more on this in the next section — the
kernel must decide whether enough pages have been freed. If so,try_to_free_pagescan be terminated
since the target has been reached (the kernel then jumps to theoutlabel at the end of the function). In the
code excerpt below,nr_reclaimedindicates how many pages have been freed so far:


mm/vmscan.c
for (priority = DEF_PRIORITY; priority >= 0; priority--) {
......
total_scanned += sc.nr_scanned;
if (nr_reclaimed >= sc.swap_cluster_max) {
ret = 1;
goto out;
}
Free download pdf