提交 3957c776 编写于 作者: M Michal Hocko 提交者: Linus Torvalds

mm: compaction: fix special case -1 order checks

Commit 56de7263 ("mm: compaction: direct compact when a high-order
allocation fails") introduced a check for cc->order == -1 in
compact_finished.  We should continue compacting in that case because
the request came from userspace and there is no particular order to
compact for.  Similar check has been added by 82478fb7 (mm: compaction:
prevent division-by-zero during user-requested compaction) for
compaction_suitable.

The check is, however, done after zone_watermark_ok which uses order as a
right hand argument for shifts.  Not only watermark check is pointless if
we can break out without it but it also uses 1 << -1 which is not well
defined (at least from C standard).  Let's move the -1 check above
zone_watermark_ok.

[minchan.kim@gmail.com> - caught compaction_suitable]
Signed-off-by: NMichal Hocko <mhocko@suse.cz>
Cc: Mel Gorman <mgorman@suse.de>
Reviewed-by: NMinchan Kim <minchan.kim@gmail.com>
Reviewed-by: NKAMEZAWA Hiroyuki <kamezawa.hioryu@jp.fujitsu.com>
Acked-by: NMel Gorman <mgorman@suse.de>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 5f1a1907
...@@ -420,13 +420,6 @@ static int compact_finished(struct zone *zone, ...@@ -420,13 +420,6 @@ static int compact_finished(struct zone *zone,
if (cc->free_pfn <= cc->migrate_pfn) if (cc->free_pfn <= cc->migrate_pfn)
return COMPACT_COMPLETE; return COMPACT_COMPLETE;
/* Compaction run is not finished if the watermark is not met */
watermark = low_wmark_pages(zone);
watermark += (1 << cc->order);
if (!zone_watermark_ok(zone, cc->order, watermark, 0, 0))
return COMPACT_CONTINUE;
/* /*
* order == -1 is expected when compacting via * order == -1 is expected when compacting via
* /proc/sys/vm/compact_memory * /proc/sys/vm/compact_memory
...@@ -434,6 +427,13 @@ static int compact_finished(struct zone *zone, ...@@ -434,6 +427,13 @@ static int compact_finished(struct zone *zone,
if (cc->order == -1) if (cc->order == -1)
return COMPACT_CONTINUE; return COMPACT_CONTINUE;
/* Compaction run is not finished if the watermark is not met */
watermark = low_wmark_pages(zone);
watermark += (1 << cc->order);
if (!zone_watermark_ok(zone, cc->order, watermark, 0, 0))
return COMPACT_CONTINUE;
/* Direct compactor: Is a suitable page free? */ /* Direct compactor: Is a suitable page free? */
for (order = cc->order; order < MAX_ORDER; order++) { for (order = cc->order; order < MAX_ORDER; order++) {
/* Job done if page is free of the right migratetype */ /* Job done if page is free of the right migratetype */
...@@ -460,6 +460,13 @@ unsigned long compaction_suitable(struct zone *zone, int order) ...@@ -460,6 +460,13 @@ unsigned long compaction_suitable(struct zone *zone, int order)
int fragindex; int fragindex;
unsigned long watermark; unsigned long watermark;
/*
* order == -1 is expected when compacting via
* /proc/sys/vm/compact_memory
*/
if (order == -1)
return COMPACT_CONTINUE;
/* /*
* Watermarks for order-0 must be met for compaction. Note the 2UL. * Watermarks for order-0 must be met for compaction. Note the 2UL.
* This is because during migration, copies of pages need to be * This is because during migration, copies of pages need to be
...@@ -469,13 +476,6 @@ unsigned long compaction_suitable(struct zone *zone, int order) ...@@ -469,13 +476,6 @@ unsigned long compaction_suitable(struct zone *zone, int order)
if (!zone_watermark_ok(zone, 0, watermark, 0, 0)) if (!zone_watermark_ok(zone, 0, watermark, 0, 0))
return COMPACT_SKIPPED; return COMPACT_SKIPPED;
/*
* order == -1 is expected when compacting via
* /proc/sys/vm/compact_memory
*/
if (order == -1)
return COMPACT_CONTINUE;
/* /*
* fragmentation index determines if allocation failures are due to * fragmentation index determines if allocation failures are due to
* low memory or external fragmentation * low memory or external fragmentation
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册