Skip to content

Commit c8f7de0

Browse files
Michal Hockotorvalds
authored andcommitted
mm, compaction: distinguish between full and partial COMPACT_COMPLETE
COMPACT_COMPLETE now means that compaction and free scanner met. This is not very useful information if somebody just wants to use this feedback and make any decisions based on that. The current caller might be a poor guy who just happened to scan tiny portion of the zone and that could be the reason no suitable pages were compacted. Make sure we distinguish the full and partial zone walks. Consumers should treat COMPACT_PARTIAL_SKIPPED as a potential success and be optimistic in retrying. The existing users of COMPACT_COMPLETE are conservatively changed to use COMPACT_PARTIAL_SKIPPED as well but some of them should be probably reconsidered and only defer the compaction only for COMPACT_COMPLETE with the new semantic. This patch shouldn't introduce any functional changes. Signed-off-by: Michal Hocko <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Acked-by: Hillf Danton <[email protected]> Cc: David Rientjes <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Joonsoo Kim <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Tetsuo Handa <[email protected]> Cc: Vladimir Davydov <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 1d4746d commit c8f7de0

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

include/linux/compaction.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ enum compact_result {
2121
* pages
2222
*/
2323
COMPACT_PARTIAL,
24-
/* The full zone was compacted */
24+
/*
25+
* direct compaction has scanned part of the zone but wasn't successfull
26+
* to compact suitable pages.
27+
*/
28+
COMPACT_PARTIAL_SKIPPED,
29+
/*
30+
* The full zone was compacted scanned but wasn't successfull to compact
31+
* suitable pages.
32+
*/
2533
COMPACT_COMPLETE,
2634
/* For more detailed tracepoint output */
2735
COMPACT_NO_SUITABLE_PAGE,

include/trace/events/compaction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
EM( COMPACT_DEFERRED, "deferred") \
1515
EM( COMPACT_CONTINUE, "continue") \
1616
EM( COMPACT_PARTIAL, "partial") \
17+
EM( COMPACT_PARTIAL_SKIPPED, "partial_skipped") \
1718
EM( COMPACT_COMPLETE, "complete") \
1819
EM( COMPACT_NO_SUITABLE_PAGE, "no_suitable_page") \
1920
EM( COMPACT_NOT_SUITABLE_ZONE, "not_suitable_zone") \

mm/compaction.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,10 @@ static enum compact_result __compact_finished(struct zone *zone, struct compact_
12521252
if (cc->direct_compaction)
12531253
zone->compact_blockskip_flush = true;
12541254

1255-
return COMPACT_COMPLETE;
1255+
if (cc->whole_zone)
1256+
return COMPACT_COMPLETE;
1257+
else
1258+
return COMPACT_PARTIAL_SKIPPED;
12561259
}
12571260

12581261
if (is_via_compact_memory(cc->order))
@@ -1413,6 +1416,10 @@ static enum compact_result compact_zone(struct zone *zone, struct compact_contro
14131416
zone->compact_cached_migrate_pfn[0] = cc->migrate_pfn;
14141417
zone->compact_cached_migrate_pfn[1] = cc->migrate_pfn;
14151418
}
1419+
1420+
if (cc->migrate_pfn == start_pfn)
1421+
cc->whole_zone = true;
1422+
14161423
cc->last_migrated_pfn = 0;
14171424

14181425
trace_mm_compaction_begin(start_pfn, cc->migrate_pfn,
@@ -1634,7 +1641,8 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
16341641
goto break_loop;
16351642
}
16361643

1637-
if (mode != MIGRATE_ASYNC && status == COMPACT_COMPLETE) {
1644+
if (mode != MIGRATE_ASYNC && (status == COMPACT_COMPLETE ||
1645+
status == COMPACT_PARTIAL_SKIPPED)) {
16381646
/*
16391647
* We think that allocation won't succeed in this zone
16401648
* so we defer compaction there. If it ends up
@@ -1881,7 +1889,7 @@ static void kcompactd_do_work(pg_data_t *pgdat)
18811889
cc.classzone_idx, 0)) {
18821890
success = true;
18831891
compaction_defer_reset(zone, cc.order, false);
1884-
} else if (status == COMPACT_COMPLETE) {
1892+
} else if (status == COMPACT_PARTIAL_SKIPPED || status == COMPACT_COMPLETE) {
18851893
/*
18861894
* We use sync migration mode here, so we defer like
18871895
* sync direct compaction does.

mm/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ struct compact_control {
174174
enum migrate_mode mode; /* Async or sync migration mode */
175175
bool ignore_skip_hint; /* Scan blocks even if marked skip */
176176
bool direct_compaction; /* False from kcompactd or /proc/... */
177+
bool whole_zone; /* Whole zone has been scanned */
177178
int order; /* order a direct compactor needs */
178179
const gfp_t gfp_mask; /* gfp mask of a direct compactor */
179180
const unsigned int alloc_flags; /* alloc flags of a direct compactor */

0 commit comments

Comments
 (0)