Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 18: Page Reclaim and Swapping


Once the kernel has finished all the required management work at the beginning ofbalance_pgdat(the
prime task is to create aswap_controlinstance), two nested loops are executed. The outer loop runs
backward through the integer variableprioritystarting atDEF_PRIORITY(typically declared as 12 in
mm/vmscan.c). This generates a priority forshrink_zone.Ahighernumber corresponds to alowerpriority;
this has a corresponding impact on calculation of page selection behavior inrefill_inactive_zone.
By applying descending priorities, the kernel attempts to achieve its goal with the minimum of effort
and therefore with the minimum of system disruption. The inner loop iterates over all zones of the
NUMA node.


Before the inner loop is entered, the kernel must determine the zone (starting atZONE_DMA)uptowhich
scanning is to be performed. To this end, the zones are traversed in descending order and their state
is checked usingzone_watermark_ok(this function is discussed in detail in Chapter 3). If scanning
is performed with highest priority (i.e., priority 0), the swap token is disabled because preventing
pages from being swapped out to accelerate tasks is not desirable in situations that are desperate for
memory:


mm/vmscan.c
static unsigned long balance_pgdat(pg_data_t *pgdat, unsigned long nr_pages,
int order)
{
...
for (priority = DEF_PRIORITY; priority >= 0; priority--) {
int end_zone = 0; /* Inclusive. 0 = ZONE_DMA */
unsigned long lru_pages = 0;

/* The swap token gets in the way of swapout... */
if (!priority)
disable_swap_token();

all_zones_ok = 1;

/*
* Scan in the highmem->dma direction for the highest
* zone which needs scanning
*/
for (i = pgdat->nr_zones - 1; i >= 0; i--) {
struct zone *zone = pgdat->node_zones + i;

if (!populated_zone(zone))
continue;

if (zone_is_all_unreclaimable(zone) &&
priority != DEF_PRIORITY)
continue;

if (!zone_watermark_ok(zone, order, zone->pages_high,
0, 0)) {
end_zone = i;
break;
}
}
if (i < 0)
goto out;
Free download pdf