Skip to content

Commit 5eeb412

Browse files
committed
mm, compaction: finish pageblocks on complete migration failure
jira LE-4623 Rebuild_History Non-Buildable kernel-4.18.0-553.81.1.el8_10 commit-author Mel Gorman <mgorman@techsingularity.net> commit cfccd2e Commit 7efc3b7 ("mm/compaction: fix set skip in fast_find_migrateblock") address an issue where a pageblock selected by fast_find_migrateblock() was ignored. Unfortunately, the same fix resulted in numerous reports of khugepaged or kcompactd stalling for long periods of time or consuming 100% of CPU. Tracing showed that there was a lot of rescanning between a small subset of pageblocks because the conditions for marking the block skip are not met. The scan is not reaching the end of the pageblock because enough pages were isolated but none were migrated successfully. Eventually it circles back to the same block. Pageblock skip tracking tries to minimise both latency and excessive scanning but tracking exactly when a block is fully scanned requires an excessive amount of state. This patch forcibly rescans a pageblock when all isolated pages fail to migrate even though it could be for transient reasons such as page writeback or page dirty. This will sometimes migrate too many pages but pageblocks will be marked skip and forward progress will be made. "Usemen" from the mmtests configuration workload-usemem-stress-numa-compact was used to stress compaction. The compaction trace events were recorded using a 6.2-rc5 kernel that includes commit 7efc3b7 and count of unique ranges were measured. The top 5 ranges were 3076 range=(0x10ca00-0x10cc00) 3076 range=(0x110a00-0x110c00) 3098 range=(0x13b600-0x13b800) 3104 range=(0x141c00-0x141e00) 11424 range=(0x11b600-0x11b800) While this workload is very different than what the bugs reported, the pattern of the same subset of blocks being repeatedly scanned is observed. At one point, *only* the range range=(0x11b600 ~ 0x11b800) was scanned for 2 seconds. 14 seconds passed between the first migration-related event and the last. With the series applied including this patch, the top 5 ranges were 1 range=(0x11607e-0x116200) 1 range=(0x116200-0x116278) 1 range=(0x116278-0x116400) 1 range=(0x116400-0x116424) 1 range=(0x116424-0x116600) Only unique ranges were scanned and the time between the first migration-related event was 0.11 milliseconds. Link: https://lkml.kernel.org/r/20230125134434.18017-5-mgorman@techsingularity.net Fixes: 7efc3b7 ("mm/compaction: fix set skip in fast_find_migrateblock") Signed-off-by: Mel Gorman <mgorman@techsingularity.net> Cc: Chuyi Zhou <zhouchuyi@bytedance.com> Cc: Jiri Slaby <jirislaby@kernel.org> Cc: Maxim Levitsky <mlevitsk@redhat.com> Cc: Michal Hocko <mhocko@kernel.org> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Pedro Falcato <pedro.falcato@gmail.com> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit cfccd2e) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent b61051e commit 5eeb412

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

mm/compaction.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,6 +2340,7 @@ compact_zone(struct compact_control *cc, struct capture_control *capc)
23402340
cc->rescan = true;
23412341
}
23422342

2343+
rescan:
23432344
switch (isolate_migratepages(cc)) {
23442345
case ISOLATE_ABORT:
23452346
ret = COMPACT_CONTENDED;
@@ -2383,15 +2384,28 @@ compact_zone(struct compact_control *cc, struct capture_control *capc)
23832384
goto out;
23842385
}
23852386
/*
2386-
* We failed to migrate at least one page in the current
2387-
* order-aligned block, so skip the rest of it.
2387+
* If an ASYNC or SYNC_LIGHT fails to migrate a page
2388+
* within the current order-aligned block, scan the
2389+
* remainder of the pageblock. This will mark the
2390+
* pageblock "skip" to avoid rescanning in the near
2391+
* future. This will isolate more pages than necessary
2392+
* for the request but avoid loops due to
2393+
* fast_find_migrateblock revisiting blocks that were
2394+
* recently partially scanned.
23882395
*/
2389-
if (cc->direct_compaction &&
2390-
(cc->mode == MIGRATE_ASYNC)) {
2391-
cc->migrate_pfn = block_end_pfn(
2392-
cc->migrate_pfn - 1, cc->order);
2393-
/* Draining pcplists is useless in this case */
2394-
last_migrated_pfn = 0;
2396+
if (cc->direct_compaction && !cc->finish_pageblock &&
2397+
(cc->mode < MIGRATE_SYNC)) {
2398+
cc->finish_pageblock = true;
2399+
2400+
/*
2401+
* Draining pcplists does not help THP if
2402+
* any page failed to migrate. Even after
2403+
* drain, the pageblock will not be free.
2404+
*/
2405+
if (cc->order == COMPACTION_HPAGE_ORDER)
2406+
last_migrated_pfn = 0;
2407+
2408+
goto rescan;
23952409
}
23962410
}
23972411

0 commit comments

Comments
 (0)