From 86c79f6b5426ce118d32c73fa9e328f0a86ab590 Mon Sep 17 00:00:00 2001 From: Mel Gorman Date: Thu, 28 Jul 2016 15:45:59 -0700 Subject: mm: vmscan: do not reclaim from kswapd if there is any eligible zone kswapd scans from highest to lowest for a zone that requires balancing. This was necessary when reclaim was per-zone to fairly age pages on lower zones. Now that we are reclaiming on a per-node basis, any eligible zone can be used and pages will still be aged fairly. This patch avoids reclaiming excessively unless buffer_heads are over the limit and it's necessary to reclaim from a higher zone than requested by the waker of kswapd to relieve low memory pressure. [hillf.zj@alibaba-inc.com: Force kswapd reclaim no more than needed] Link: http://lkml.kernel.org/r/1466518566-30034-12-git-send-email-mgorman@techsingularity.net Link: http://lkml.kernel.org/r/1467970510-21195-13-git-send-email-mgorman@techsingularity.net Signed-off-by: Mel Gorman Signed-off-by: Hillf Danton Acked-by: Vlastimil Babka Acked-by: Johannes Weiner Cc: Joonsoo Kim Cc: Michal Hocko Cc: Minchan Kim Cc: Rik van Riel Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- mm/vmscan.c | 59 +++++++++++++++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 32 deletions(-) (limited to 'mm') diff --git a/mm/vmscan.c b/mm/vmscan.c index 8b39b903bd14..b7a276f4b1b0 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3144,31 +3144,39 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx) sc.nr_reclaimed = 0; - /* Scan from the highest requested zone to dma */ - for (i = classzone_idx; i >= 0; i--) { - zone = pgdat->node_zones + i; - if (!populated_zone(zone)) - continue; - - /* - * If the number of buffer_heads in the machine - * exceeds the maximum allowed level and this node - * has a highmem zone, force kswapd to reclaim from - * it to relieve lowmem pressure. - */ - if (buffer_heads_over_limit && is_highmem_idx(i)) { - classzone_idx = i; - break; - } + /* + * If the number of buffer_heads in the machine exceeds the + * maximum allowed level then reclaim from all zones. This is + * not specific to highmem as highmem may not exist but it is + * it is expected that buffer_heads are stripped in writeback. + */ + if (buffer_heads_over_limit) { + for (i = MAX_NR_ZONES - 1; i >= 0; i--) { + zone = pgdat->node_zones + i; + if (!populated_zone(zone)) + continue; - if (!zone_balanced(zone, order, 0)) { classzone_idx = i; break; } } - if (i < 0) - goto out; + /* + * Only reclaim if there are no eligible zones. Check from + * high to low zone as allocations prefer higher zones. + * Scanning from low to high zone would allow congestion to be + * cleared during a very small window when a small low + * zone was balanced even under extreme pressure when the + * overall node may be congested. + */ + for (i = classzone_idx; i >= 0; i--) { + zone = pgdat->node_zones + i; + if (!populated_zone(zone)) + continue; + + if (zone_balanced(zone, sc.order, classzone_idx)) + goto out; + } /* * Do some background aging of the anon list, to give @@ -3213,19 +3221,6 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx) if (try_to_freeze() || kthread_should_stop()) break; - /* - * Stop reclaiming if any eligible zone is balanced and clear - * node writeback or congested. - */ - for (i = 0; i <= classzone_idx; i++) { - zone = pgdat->node_zones + i; - if (!populated_zone(zone)) - continue; - - if (zone_balanced(zone, sc.order, classzone_idx)) - goto out; - } - /* * Raise priority if scanning rate is too low or there was no * progress in reclaiming pages -- cgit v1.2.3