提交 97d47a65 编写于 作者: V Vlastimil Babka 提交者: Linus Torvalds

mm, compaction: simplify deferred compaction

Since commit 53853e2d ("mm, compaction: defer each zone individually
instead of preferred zone"), compaction is deferred for each zone where
sync direct compaction fails, and reset where it succeeds.  However, it
was observed that for DMA zone compaction often appeared to succeed
while subsequent allocation attempt would not, due to different outcome
of watermark check.

In order to properly defer compaction in this zone, the candidate zone
has to be passed back to __alloc_pages_direct_compact() and compaction
deferred in the zone after the allocation attempt fails.

The large source of mismatch between watermark check in compaction and
allocation was the lack of alloc_flags and classzone_idx values in
compaction, which has been fixed in the previous patch.  So with this
problem fixed, we can simplify the code by removing the candidate_zone
parameter and deferring in __alloc_pages_direct_compact().

After this patch, the compaction activity during stress-highalloc
benchmark is still somewhat increased, but it's negligible compared to the
increase that occurred without the better watermark checking.  This
suggests that it is still possible to apparently succeed in compaction but
fail to allocate, possibly due to parallel allocation activity.

[akpm@linux-foundation.org: fix build]
Suggested-by: NJoonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: NVlastimil Babka <vbabka@suse.cz>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Michal Nazarewicz <mina86@mina86.com>
Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 ebff3980
...@@ -33,8 +33,7 @@ extern int fragmentation_index(struct zone *zone, unsigned int order); ...@@ -33,8 +33,7 @@ extern int fragmentation_index(struct zone *zone, unsigned int order);
extern unsigned long try_to_compact_pages(struct zonelist *zonelist, extern unsigned long try_to_compact_pages(struct zonelist *zonelist,
int order, gfp_t gfp_mask, nodemask_t *mask, int order, gfp_t gfp_mask, nodemask_t *mask,
enum migrate_mode mode, int *contended, enum migrate_mode mode, int *contended,
int alloc_flags, int classzone_idx, int alloc_flags, int classzone_idx);
struct zone **candidate_zone);
extern void compact_pgdat(pg_data_t *pgdat, int order); extern void compact_pgdat(pg_data_t *pgdat, int order);
extern void reset_isolation_suitable(pg_data_t *pgdat); extern void reset_isolation_suitable(pg_data_t *pgdat);
extern unsigned long compaction_suitable(struct zone *zone, int order, extern unsigned long compaction_suitable(struct zone *zone, int order,
...@@ -105,8 +104,7 @@ static inline bool compaction_restarting(struct zone *zone, int order) ...@@ -105,8 +104,7 @@ static inline bool compaction_restarting(struct zone *zone, int order)
static inline unsigned long try_to_compact_pages(struct zonelist *zonelist, static inline unsigned long try_to_compact_pages(struct zonelist *zonelist,
int order, gfp_t gfp_mask, nodemask_t *nodemask, int order, gfp_t gfp_mask, nodemask_t *nodemask,
enum migrate_mode mode, int *contended, enum migrate_mode mode, int *contended,
int alloc_flags, int classzone_idx, int alloc_flags, int classzone_idx)
struct zone **candidate_zone)
{ {
return COMPACT_CONTINUE; return COMPACT_CONTINUE;
} }
......
...@@ -1298,15 +1298,13 @@ int sysctl_extfrag_threshold = 500; ...@@ -1298,15 +1298,13 @@ int sysctl_extfrag_threshold = 500;
* @mode: The migration mode for async, sync light, or sync migration * @mode: The migration mode for async, sync light, or sync migration
* @contended: Return value that determines if compaction was aborted due to * @contended: Return value that determines if compaction was aborted due to
* need_resched() or lock contention * need_resched() or lock contention
* @candidate_zone: Return the zone where we think allocation should succeed
* *
* This is the main entry point for direct page compaction. * This is the main entry point for direct page compaction.
*/ */
unsigned long try_to_compact_pages(struct zonelist *zonelist, unsigned long try_to_compact_pages(struct zonelist *zonelist,
int order, gfp_t gfp_mask, nodemask_t *nodemask, int order, gfp_t gfp_mask, nodemask_t *nodemask,
enum migrate_mode mode, int *contended, enum migrate_mode mode, int *contended,
int alloc_flags, int classzone_idx, int alloc_flags, int classzone_idx)
struct zone **candidate_zone)
{ {
enum zone_type high_zoneidx = gfp_zone(gfp_mask); enum zone_type high_zoneidx = gfp_zone(gfp_mask);
int may_enter_fs = gfp_mask & __GFP_FS; int may_enter_fs = gfp_mask & __GFP_FS;
...@@ -1343,7 +1341,6 @@ unsigned long try_to_compact_pages(struct zonelist *zonelist, ...@@ -1343,7 +1341,6 @@ unsigned long try_to_compact_pages(struct zonelist *zonelist,
/* If a normal allocation would succeed, stop compacting */ /* If a normal allocation would succeed, stop compacting */
if (zone_watermark_ok(zone, order, low_wmark_pages(zone), if (zone_watermark_ok(zone, order, low_wmark_pages(zone),
classzone_idx, alloc_flags)) { classzone_idx, alloc_flags)) {
*candidate_zone = zone;
/* /*
* We think the allocation will succeed in this zone, * We think the allocation will succeed in this zone,
* but it is not certain, hence the false. The caller * but it is not certain, hence the false. The caller
......
...@@ -2330,7 +2330,6 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, ...@@ -2330,7 +2330,6 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
int classzone_idx, int migratetype, enum migrate_mode mode, int classzone_idx, int migratetype, enum migrate_mode mode,
int *contended_compaction, bool *deferred_compaction) int *contended_compaction, bool *deferred_compaction)
{ {
struct zone *last_compact_zone = NULL;
unsigned long compact_result; unsigned long compact_result;
struct page *page; struct page *page;
...@@ -2341,8 +2340,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, ...@@ -2341,8 +2340,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
compact_result = try_to_compact_pages(zonelist, order, gfp_mask, compact_result = try_to_compact_pages(zonelist, order, gfp_mask,
nodemask, mode, nodemask, mode,
contended_compaction, contended_compaction,
alloc_flags, classzone_idx, alloc_flags, classzone_idx);
&last_compact_zone);
current->flags &= ~PF_MEMALLOC; current->flags &= ~PF_MEMALLOC;
switch (compact_result) { switch (compact_result) {
...@@ -2379,14 +2377,6 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, ...@@ -2379,14 +2377,6 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
return page; return page;
} }
/*
* last_compact_zone is where try_to_compact_pages thought allocation
* should succeed, so it did not defer compaction. But here we know
* that it didn't succeed, so we do the defer.
*/
if (last_compact_zone && mode != MIGRATE_ASYNC)
defer_compaction(last_compact_zone, order);
/* /*
* It's bad if compaction run occurs and fails. The most likely reason * It's bad if compaction run occurs and fails. The most likely reason
* is that pages exist, but not enough to satisfy watermarks. * is that pages exist, but not enough to satisfy watermarks.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册