static unsigned long shrink_zone(int priority, struct zone *zone, struct scan_control *sc) {

unsigned long nr_active; unsigned long nr_inactive; unsigned long nr_to_scan; unsigned long nr_reclaimed = 0;

* Add one to 'nr_to_scan' just to make sure that the kernel will

* slowly sift through the active list.

(zone_page_state(zone, NR_ACTIVE) >> priority) + 1; nr_active = zone->nr_scan_active; if (nr_active >= sc->swap_cluster_max) zone->nr_scan_active = 0;

zone->nr_scan_inactive +=

(zone_page_state(zone, NR_INACTIVE) >> priority) + 1; nr_inactive = zone->nr_scan_inactive; if (nr_inactive >= sc->swap_cluster_max) zone->nr_scan_inactive = 0;

else nr_inactive = 0;

Each time shrink_zone is called, the number of active and inactive pages that are to be scanned in this pass is incremented by the value of nr_scan_active or nr_scan_inactive, which is scaled with the current priority by means of a right shift, that is, approximately an integer division by 2priority. 1 is always added to ensure that the counter is also incremented even if the bit-shift operation results in 0 over a lengthy period; this can happen with certain load situations. Adding 1 also ensures that, in this situation too, the inactive zone is filled or the caches are shrunk at some time or other.

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 variable nr_active or nr_inactive is 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 by sc->swap_cluster_max, as the next part of the function shows:

Continue reading here: Mmvmscanc

Was this article helpful?

0 0