Skip to content

Commit 60cefed

Browse files
hnaztorvalds
authored andcommitted
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: Johannes Weiner <hannes@cmpxchg.org> Reported-by: George Spelvin <linux@horizon.com> Reported-by: Johannes Hirte <johannes.hirte@fem.tu-ilmenau.de> Reported-by: Tomas Racek <tracek@redhat.com> Tested-by: Johannes Hirte <johannes.hirte@fem.tu-ilmenau.de> Reviewed-by: Rik van Riel <riel@redhat.com> Cc: Mel Gorman <mel@csn.ul.ie> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ae64ffc commit 60cefed

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

mm/vmscan.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,6 +2414,19 @@ static void age_active_anon(struct zone *zone, struct scan_control *sc)
24142414
} while (memcg);
24152415
}
24162416

2417+
static bool zone_balanced(struct zone *zone, int order,
2418+
unsigned long balance_gap, int classzone_idx)
2419+
{
2420+
if (!zone_watermark_ok_safe(zone, order, high_wmark_pages(zone) +
2421+
balance_gap, classzone_idx, 0))
2422+
return false;
2423+
2424+
if (COMPACTION_BUILD && order && !compaction_suitable(zone, order))
2425+
return false;
2426+
2427+
return true;
2428+
}
2429+
24172430
/*
24182431
* pgdat_balanced is used when checking if a node is balanced for high-order
24192432
* 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,
24922505
continue;
24932506
}
24942507

2495-
if (!zone_watermark_ok_safe(zone, order, high_wmark_pages(zone),
2496-
i, 0))
2508+
if (!zone_balanced(zone, order, 0, i))
24972509
all_zones_ok = false;
24982510
else
24992511
balanced += zone->present_pages;
@@ -2602,8 +2614,7 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
26022614
break;
26032615
}
26042616

2605-
if (!zone_watermark_ok_safe(zone, order,
2606-
high_wmark_pages(zone), 0, 0)) {
2617+
if (!zone_balanced(zone, order, 0, 0)) {
26072618
end_zone = i;
26082619
break;
26092620
} else {
@@ -2679,9 +2690,8 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
26792690
testorder = 0;
26802691

26812692
if ((buffer_heads_over_limit && is_highmem_idx(i)) ||
2682-
!zone_watermark_ok_safe(zone, testorder,
2683-
high_wmark_pages(zone) + balance_gap,
2684-
end_zone, 0)) {
2693+
!zone_balanced(zone, testorder,
2694+
balance_gap, end_zone)) {
26852695
shrink_zone(zone, &sc);
26862696

26872697
reclaim_state->reclaimed_slab = 0;
@@ -2708,8 +2718,7 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
27082718
continue;
27092719
}
27102720

2711-
if (!zone_watermark_ok_safe(zone, testorder,
2712-
high_wmark_pages(zone), end_zone, 0)) {
2721+
if (!zone_balanced(zone, testorder, 0, end_zone)) {
27132722
all_zones_ok = 0;
27142723
/*
27152724
* We are still under min water mark. This

0 commit comments

Comments
 (0)