aboutsummaryrefslogtreecommitdiffstats
path: root/mm/compaction.c
diff options
context:
space:
mode:
authorJohannes Weiner <hannes@cmpxchg.org>2011-01-20 17:44:21 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2011-01-20 20:02:05 -0500
commit82478fb7bca28e3ca2f3c55c14e690f749dd4dbb (patch)
tree71023f480667dc3bfd255673437c76db77a05aa0 /mm/compaction.c
parent3305de51bf612603c9a4e4dc98ceb839ef933749 (diff)
mm: compaction: prevent division-by-zero during user-requested compaction
Up until 3e7d344 ("mm: vmscan: reclaim order-0 and use compaction instead of lumpy reclaim"), compaction skipped calculating the fragmentation index of a zone when compaction was explicitely requested through the procfs knob. However, when compaction_suitable was introduced, it did not come with an extra check for order == -1, set on explicit compaction requests, and passed this order on to the fragmentation index calculation, where it overshifts the number of requested pages, leading to a division by zero. This patch makes sure that order == -1 is recognized as the flag it is rather than passing it along as valid order parameter. [akpm@linux-foundation.org: add comment, per Mel] Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> Reviewed-by: Mel Gorman <mel@csn.ul.ie> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/compaction.c')
-rw-r--r--mm/compaction.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/mm/compaction.c b/mm/compaction.c
index 6d592a021072..8be430b812de 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -406,6 +406,10 @@ static int compact_finished(struct zone *zone,
406 if (!zone_watermark_ok(zone, cc->order, watermark, 0, 0)) 406 if (!zone_watermark_ok(zone, cc->order, watermark, 0, 0))
407 return COMPACT_CONTINUE; 407 return COMPACT_CONTINUE;
408 408
409 /*
410 * order == -1 is expected when compacting via
411 * /proc/sys/vm/compact_memory
412 */
409 if (cc->order == -1) 413 if (cc->order == -1)
410 return COMPACT_CONTINUE; 414 return COMPACT_CONTINUE;
411 415
@@ -454,6 +458,13 @@ unsigned long compaction_suitable(struct zone *zone, int order)
454 return COMPACT_SKIPPED; 458 return COMPACT_SKIPPED;
455 459
456 /* 460 /*
461 * order == -1 is expected when compacting via
462 * /proc/sys/vm/compact_memory
463 */
464 if (order == -1)
465 return COMPACT_CONTINUE;
466
467 /*
457 * fragmentation index determines if allocation failures are due to 468 * fragmentation index determines if allocation failures are due to
458 * low memory or external fragmentation 469 * low memory or external fragmentation
459 * 470 *