Skip to content

Commit cab1802

Browse files
Michal Hockotorvalds
authored andcommitted
mm, compaction: abstract compaction feedback to helpers
Compaction can provide a wild variation of feedback to the caller. Many of them are implementation specific and the caller of the compaction (especially the page allocator) shouldn't be bound to specifics of the current implementation. This patch abstracts the feedback into three basic types: - compaction_made_progress - compaction was active and made some progress. - compaction_failed - compaction failed and further attempts to invoke it would most probably fail and therefore it is not worth retrying - compaction_withdrawn - compaction wasn't invoked for an implementation specific reasons. In the current implementation it means that the compaction was deferred, contended or the page scanners met too early without any progress. Retrying is still worthwhile. [[email protected]: do not change thp back off behavior] [[email protected]: fix typo in comment, per Hillf] Signed-off-by: Michal Hocko <[email protected]> Acked-by: Hillf Danton <[email protected]> Acked-by: Vlastimil Babka <[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 c5d01d0 commit cab1802

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

include/linux/compaction.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,70 @@ extern void compaction_defer_reset(struct zone *zone, int order,
7878
bool alloc_success);
7979
extern bool compaction_restarting(struct zone *zone, int order);
8080

81+
/* Compaction has made some progress and retrying makes sense */
82+
static inline bool compaction_made_progress(enum compact_result result)
83+
{
84+
/*
85+
* Even though this might sound confusing this in fact tells us
86+
* that the compaction successfully isolated and migrated some
87+
* pageblocks.
88+
*/
89+
if (result == COMPACT_PARTIAL)
90+
return true;
91+
92+
return false;
93+
}
94+
95+
/* Compaction has failed and it doesn't make much sense to keep retrying. */
96+
static inline bool compaction_failed(enum compact_result result)
97+
{
98+
/* All zones were scanned completely and still not result. */
99+
if (result == COMPACT_COMPLETE)
100+
return true;
101+
102+
return false;
103+
}
104+
105+
/*
106+
* Compaction has backed off for some reason. It might be throttling or
107+
* lock contention. Retrying is still worthwhile.
108+
*/
109+
static inline bool compaction_withdrawn(enum compact_result result)
110+
{
111+
/*
112+
* Compaction backed off due to watermark checks for order-0
113+
* so the regular reclaim has to try harder and reclaim something.
114+
*/
115+
if (result == COMPACT_SKIPPED)
116+
return true;
117+
118+
/*
119+
* If compaction is deferred for high-order allocations, it is
120+
* because sync compaction recently failed. If this is the case
121+
* and the caller requested a THP allocation, we do not want
122+
* to heavily disrupt the system, so we fail the allocation
123+
* instead of entering direct reclaim.
124+
*/
125+
if (result == COMPACT_DEFERRED)
126+
return true;
127+
128+
/*
129+
* If compaction in async mode encounters contention or blocks higher
130+
* priority task we back off early rather than cause stalls.
131+
*/
132+
if (result == COMPACT_CONTENDED)
133+
return true;
134+
135+
/*
136+
* Page scanners have met but we haven't scanned full zones so this
137+
* is a back off in fact.
138+
*/
139+
if (result == COMPACT_PARTIAL_SKIPPED)
140+
return true;
141+
142+
return false;
143+
}
144+
81145
extern int kcompactd_run(int nid);
82146
extern void kcompactd_stop(int nid);
83147
extern void wakeup_kcompactd(pg_data_t *pgdat, int order, int classzone_idx);
@@ -114,6 +178,21 @@ static inline bool compaction_deferred(struct zone *zone, int order)
114178
return true;
115179
}
116180

181+
static inline bool compaction_made_progress(enum compact_result result)
182+
{
183+
return false;
184+
}
185+
186+
static inline bool compaction_failed(enum compact_result result)
187+
{
188+
return false;
189+
}
190+
191+
static inline bool compaction_withdrawn(enum compact_result result)
192+
{
193+
return true;
194+
}
195+
117196
static inline int kcompactd_run(int nid)
118197
{
119198
return 0;

0 commit comments

Comments
 (0)