Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 18: Page Reclaim and Swapping


If one of the values is greater than or equal to the maximum page number in a current swap cluster, the
value of the zone element is reset to 0, and the value of the local variablenr_activeornr_inactiveis
retained; otherwise, the zone value remains the same, and the local variables are set to 0.

This behavior ensures that the kernel does not start further actions unless the number of active and
inactive pages to be scanned is greater than the threshold value specified bysc->swap_cluster_max,as
the next part of the function shows:

mm/vmscan.c
while (nr_active || nr_inactive) {
if (nr_active) {
sc->nr_to_scan = min(nr_active,
(unsigned long)sc->swap_cluster_max);
nr_active -= sc->nr_to_scan;
shrink_active_list(nr_to_scan, zone, sc, priority);
}

if (nr_inactive) {
sc->nr_to_scan = min(nr_inactive,
(unsigned long)sc->swap_cluster_max);
nr_inactive -= sc->nr_to_scan;
nr_reclaimed += shrink_inactive_list(nr_to_scan, zone,
sc);
}
}
...
return nr_reclaimed;
}

The loop is not executed unless the threshold is exceeded fornr_activeornr_inactive. In the loop, the
kernel makes a distinction as to whether inactive, pages, active pages, or both are to be scanned:

❑ If active pages are to be scanned, the kernel usesshrink_active_listto move pages from the
active to the inactive LRU list. Naturally, the least used of the active pages are moved.
❑ Inactive pages can be removed directly from the caches by means ofshrink_active_list.
The function tries to take the required number of pages to be reclaimed from theinactive
list. The number of pages for which this actually succeeded is returned.

The loop is terminated when sufficient pages of both categories have been scanned and the local counters
have reached 0.

Shrinking the LRU lists inshrink_active_listandshrink_inactive_listrequires a means to select
pages from these lists, so an auxiliary function to perform this job must be introduced before we can
discuss them.

18.6.5 Isolating LRU Pages and Lumpy Reclaim


Both the active and inactive pages of a zone are kept on lists that need to be protected by a spinlock, to
be precise: byzone->lru_lock. To simplify matters, I have ignored this lock until now because it was
not essential for our purposes. Now we need to consider it, though. When operations with the LRU lists
Free download pdf