Commit 60cefed4 authored by Johannes Weiner's avatar Johannes Weiner Committed by Linus Torvalds

mm: vmscan: fix endless loop in kswapd balancing

Kswapd does not in all places have the same criteria for a balanced
zone.  Zones are only being reclaimed when their high watermark is
breached, but compaction checks loop over the zonelist again when the
zone does not meet the low watermark plus two times the size of the
allocation.  This gets kswapd stuck in an endless loop over a small
zone, like the DMA zone, where the high watermark is smaller than the
compaction requirement.

Add a function, zone_balanced(), that checks the watermark, and, for
higher order allocations, if compaction has enough free memory.  Then
use it uniformly to check for balanced zones.

This makes sure that when the compaction watermark is not met, at least
reclaim happens and progress is made - or the zone is declared
unreclaimable at some point and skipped entirely.
Signed-off-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
Reported-by: default avatarGeorge Spelvin <linux@horizon.com>
Reported-by: default avatarJohannes Hirte <johannes.hirte@fem.tu-ilmenau.de>
Reported-by: default avatarTomas Racek <tracek@redhat.com>
Tested-by: default avatarJohannes Hirte <johannes.hirte@fem.tu-ilmenau.de>
Reviewed-by: default avatarRik van Riel <riel@redhat.com>
Cc: Mel Gorman <mel@csn.ul.ie>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ae64ffca
...@@ -2414,6 +2414,19 @@ static void age_active_anon(struct zone *zone, struct scan_control *sc) ...@@ -2414,6 +2414,19 @@ static void age_active_anon(struct zone *zone, struct scan_control *sc)
} while (memcg); } while (memcg);
} }
static bool zone_balanced(struct zone *zone, int order,
unsigned long balance_gap, int classzone_idx)
{
if (!zone_watermark_ok_safe(zone, order, high_wmark_pages(zone) +
balance_gap, classzone_idx, 0))
return false;
if (COMPACTION_BUILD && order && !compaction_suitable(zone, order))
return false;
return true;
}
/* /*
* pgdat_balanced is used when checking if a node is balanced for high-order * pgdat_balanced is used when checking if a node is balanced for high-order
* allocations. Only zones that meet watermarks and are in a zone allowed * allocations. Only zones that meet watermarks and are in a zone allowed
...@@ -2492,8 +2505,7 @@ static bool prepare_kswapd_sleep(pg_data_t *pgdat, int order, long remaining, ...@@ -2492,8 +2505,7 @@ static bool prepare_kswapd_sleep(pg_data_t *pgdat, int order, long remaining,
continue; continue;
} }
if (!zone_watermark_ok_safe(zone, order, high_wmark_pages(zone), if (!zone_balanced(zone, order, 0, i))
i, 0))
all_zones_ok = false; all_zones_ok = false;
else else
balanced += zone->present_pages; balanced += zone->present_pages;
...@@ -2602,8 +2614,7 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order, ...@@ -2602,8 +2614,7 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
break; break;
} }
if (!zone_watermark_ok_safe(zone, order, if (!zone_balanced(zone, order, 0, 0)) {
high_wmark_pages(zone), 0, 0)) {
end_zone = i; end_zone = i;
break; break;
} else { } else {
...@@ -2679,9 +2690,8 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order, ...@@ -2679,9 +2690,8 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
testorder = 0; testorder = 0;
if ((buffer_heads_over_limit && is_highmem_idx(i)) || if ((buffer_heads_over_limit && is_highmem_idx(i)) ||
!zone_watermark_ok_safe(zone, testorder, !zone_balanced(zone, testorder,
high_wmark_pages(zone) + balance_gap, balance_gap, end_zone)) {
end_zone, 0)) {
shrink_zone(zone, &sc); shrink_zone(zone, &sc);
reclaim_state->reclaimed_slab = 0; reclaim_state->reclaimed_slab = 0;
...@@ -2708,8 +2718,7 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order, ...@@ -2708,8 +2718,7 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
continue; continue;
} }
if (!zone_watermark_ok_safe(zone, testorder, if (!zone_balanced(zone, testorder, 0, end_zone)) {
high_wmark_pages(zone), end_zone, 0)) {
all_zones_ok = 0; all_zones_ok = 0;
/* /*
* We are still under min water mark. This * We are still under min water mark. This
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment