Skip to content

Commit f6c9a70

Browse files
hnazgregkh
authored andcommitted
mm: vmscan: fix endless loop in kswapd balancing
commit 60cefed upstream. 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> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent cd4d10a commit f6c9a70

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

mm/vmscan.c

+18-9
Original file line numberDiff line numberDiff line change
@@ -2383,6 +2383,19 @@ static void age_active_anon(struct zone *zone, struct scan_control *sc)
23832383
} while (memcg);
23842384
}
23852385

2386+
static bool zone_balanced(struct zone *zone, int order,
2387+
unsigned long balance_gap, int classzone_idx)
2388+
{
2389+
if (!zone_watermark_ok_safe(zone, order, high_wmark_pages(zone) +
2390+
balance_gap, classzone_idx, 0))
2391+
return false;
2392+
2393+
if (COMPACTION_BUILD && order && !compaction_suitable(zone, order))
2394+
return false;
2395+
2396+
return true;
2397+
}
2398+
23862399
/*
23872400
* pgdat_balanced is used when checking if a node is balanced for high-order
23882401
* allocations. Only zones that meet watermarks and are in a zone allowed
@@ -2461,8 +2474,7 @@ static bool prepare_kswapd_sleep(pg_data_t *pgdat, int order, long remaining,
24612474
continue;
24622475
}
24632476

2464-
if (!zone_watermark_ok_safe(zone, order, high_wmark_pages(zone),
2465-
i, 0))
2477+
if (!zone_balanced(zone, order, 0, i))
24662478
all_zones_ok = false;
24672479
else
24682480
balanced += zone->present_pages;
@@ -2571,8 +2583,7 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
25712583
break;
25722584
}
25732585

2574-
if (!zone_watermark_ok_safe(zone, order,
2575-
high_wmark_pages(zone), 0, 0)) {
2586+
if (!zone_balanced(zone, order, 0, 0)) {
25762587
end_zone = i;
25772588
break;
25782589
} else {
@@ -2648,9 +2659,8 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
26482659
testorder = 0;
26492660

26502661
if ((buffer_heads_over_limit && is_highmem_idx(i)) ||
2651-
!zone_watermark_ok_safe(zone, testorder,
2652-
high_wmark_pages(zone) + balance_gap,
2653-
end_zone, 0)) {
2662+
!zone_balanced(zone, testorder,
2663+
balance_gap, end_zone)) {
26542664
shrink_zone(zone, &sc);
26552665

26562666
reclaim_state->reclaimed_slab = 0;
@@ -2677,8 +2687,7 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
26772687
continue;
26782688
}
26792689

2680-
if (!zone_watermark_ok_safe(zone, testorder,
2681-
high_wmark_pages(zone), end_zone, 0)) {
2690+
if (!zone_balanced(zone, testorder, 0, end_zone)) {
26822691
all_zones_ok = 0;
26832692
/*
26842693
* We are still under min water mark. This

0 commit comments

Comments
 (0)