Skip to content

Commit 1d4746d

Browse files
Michal Hockotorvalds
authored andcommitted
mm, compaction: distinguish COMPACT_DEFERRED from COMPACT_SKIPPED
try_to_compact_pages() can currently return COMPACT_SKIPPED even when the compaction is defered for some zone just because zone DMA is skipped in 99% of cases due to watermark checks. This makes COMPACT_DEFERRED basically unusable for the page allocator as a feedback mechanism. Make sure we distinguish those two states properly and switch their ordering in the enum. This would mean that the COMPACT_SKIPPED will be returned only when all eligible zones are skipped. As a result COMPACT_DEFERRED handling for THP in __alloc_pages_slowpath will be more precise and we would bail out rather than reclaim. 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 c46649d commit 1d4746d

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

include/linux/compaction.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
/* Return values for compact_zone() and try_to_compact_pages() */
55
/* When adding new states, please adjust include/trace/events/compaction.h */
66
enum compact_result {
7-
/* compaction didn't start as it was deferred due to past failures */
8-
COMPACT_DEFERRED,
97
/*
108
* compaction didn't start as it was not possible or direct reclaim
119
* was more suitable
1210
*/
1311
COMPACT_SKIPPED,
12+
/* compaction didn't start as it was deferred due to past failures */
13+
COMPACT_DEFERRED,
14+
/* compaction not active last round */
15+
COMPACT_INACTIVE = COMPACT_DEFERRED,
16+
1417
/* compaction should continue to another pageblock */
1518
COMPACT_CONTINUE,
1619
/*

include/trace/events/compaction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include <trace/events/mmflags.h>
1111

1212
#define COMPACTION_STATUS \
13-
EM( COMPACT_DEFERRED, "deferred") \
1413
EM( COMPACT_SKIPPED, "skipped") \
14+
EM( COMPACT_DEFERRED, "deferred") \
1515
EM( COMPACT_CONTINUE, "continue") \
1616
EM( COMPACT_PARTIAL, "partial") \
1717
EM( COMPACT_COMPLETE, "complete") \

mm/compaction.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
15781578
int may_perform_io = gfp_mask & __GFP_IO;
15791579
struct zoneref *z;
15801580
struct zone *zone;
1581-
enum compact_result rc = COMPACT_DEFERRED;
1581+
enum compact_result rc = COMPACT_SKIPPED;
15821582
int all_zones_contended = COMPACT_CONTENDED_LOCK; /* init for &= op */
15831583

15841584
*contended = COMPACT_CONTENDED_NONE;
@@ -1595,8 +1595,10 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
15951595
enum compact_result status;
15961596
int zone_contended;
15971597

1598-
if (compaction_deferred(zone, order))
1598+
if (compaction_deferred(zone, order)) {
1599+
rc = max_t(enum compact_result, COMPACT_DEFERRED, rc);
15991600
continue;
1601+
}
16001602

16011603
status = compact_zone_order(zone, order, gfp_mask, mode,
16021604
&zone_contended, alloc_flags,
@@ -1667,7 +1669,7 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
16671669
* If at least one zone wasn't deferred or skipped, we report if all
16681670
* zones that were tried were lock contended.
16691671
*/
1670-
if (rc > COMPACT_SKIPPED && all_zones_contended)
1672+
if (rc > COMPACT_INACTIVE && all_zones_contended)
16711673
*contended = COMPACT_CONTENDED_LOCK;
16721674

16731675
return rc;

0 commit comments

Comments
 (0)