Chapter 18: Page Reclaim and Swapping
thatrefill_inactive_zoneis among the longer functions in the kernel. It performs the following
principal steps:
- It copies the required number of pages defined bynr_pagesfrom theactivelist to a tempo-
rary, local list usingisolate_lru_pages. - It distributes the pages over the active and inactive lists according to their activity level.
- It frees unimportant pages in bundles.
Figure 18-15 shows the code flow diagram for the firstrefill_inactive_zonestep.
Compute Swap Parameters
refill_inactive_zone
Part2
lru_add_drain
isolate_lru_pages
Figure 18-15: Code flow diagram for
refill_inactive_zone(Part 1).
First of all, the kernel calculates a few parameters to define the aggressiveness and the behavior of the
page reclaim algorithm. Some statistical data are analyzed:
mm/vmscan.c
...
distress = 100 >> min(zone->prev_priority, priority);
mapped_ratio = ((global_page_state(NR_FILE_MAPPED) +
global_page_state(NR_ANON_PAGES)) * 100) /
vm_total_pages;
mapped_ratio = (sc->nr_mapped * 100) / total_memory;
swap_tendency = mapped_ratio / 2 + distress + sc->swappiness;
imbalance = zone_page_state(zone, NR_ACTIVE);
imbalance /= zone_page_state(zone, NR_INACTIVE) + 1;
imbalance *= (vm_swappiness + 1);
imbalance /= 100;
imbalance *= mapped_ratio;
imbalance /= 100;
swap_tendency += imbalance;
if (swap_tendency >= 100)
reclaim_mapped = 1;
...