diff options
| author | Michal Hocko <mhocko@suse.cz> | 2011-06-15 18:08:25 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-06-15 23:04:00 -0400 |
| commit | 3957c7768e5ea02fd3345176ddd340f820e5d285 (patch) | |
| tree | b3cbefeea3ac3adea0ca9d49e140503c9e5754b6 /mm | |
| parent | 5f1a19070b16c20cdc71ed0e981bfa19f8f6a4ee (diff) | |
mm: compaction: fix special case -1 order checks
Commit 56de7263fcf3 ("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: Michal Hocko <mhocko@suse.cz>
Cc: Mel Gorman <mgorman@suse.de>
Reviewed-by: Minchan Kim <minchan.kim@gmail.com>
Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hioryu@jp.fujitsu.com>
Acked-by: Mel Gorman <mgorman@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
| -rw-r--r-- | mm/compaction.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/mm/compaction.c b/mm/compaction.c index 021a2960ef9e..94bdbe1f7caf 100644 --- a/mm/compaction.c +++ b/mm/compaction.c | |||
| @@ -420,13 +420,6 @@ static int compact_finished(struct zone *zone, | |||
| 420 | if (cc->free_pfn <= cc->migrate_pfn) | 420 | if (cc->free_pfn <= cc->migrate_pfn) |
| 421 | return COMPACT_COMPLETE; | 421 | return COMPACT_COMPLETE; |
| 422 | 422 | ||
| 423 | /* Compaction run is not finished if the watermark is not met */ | ||
| 424 | watermark = low_wmark_pages(zone); | ||
| 425 | watermark += (1 << cc->order); | ||
| 426 | |||
| 427 | if (!zone_watermark_ok(zone, cc->order, watermark, 0, 0)) | ||
| 428 | return COMPACT_CONTINUE; | ||
| 429 | |||
| 430 | /* | 423 | /* |
| 431 | * order == -1 is expected when compacting via | 424 | * order == -1 is expected when compacting via |
| 432 | * /proc/sys/vm/compact_memory | 425 | * /proc/sys/vm/compact_memory |
| @@ -434,6 +427,13 @@ static int compact_finished(struct zone *zone, | |||
| 434 | if (cc->order == -1) | 427 | if (cc->order == -1) |
| 435 | return COMPACT_CONTINUE; | 428 | return COMPACT_CONTINUE; |
| 436 | 429 | ||
| 430 | /* Compaction run is not finished if the watermark is not met */ | ||
| 431 | watermark = low_wmark_pages(zone); | ||
| 432 | watermark += (1 << cc->order); | ||
| 433 | |||
| 434 | if (!zone_watermark_ok(zone, cc->order, watermark, 0, 0)) | ||
| 435 | return COMPACT_CONTINUE; | ||
| 436 | |||
| 437 | /* Direct compactor: Is a suitable page free? */ | 437 | /* Direct compactor: Is a suitable page free? */ |
| 438 | for (order = cc->order; order < MAX_ORDER; order++) { | 438 | for (order = cc->order; order < MAX_ORDER; order++) { |
| 439 | /* Job done if page is free of the right migratetype */ | 439 | /* Job done if page is free of the right migratetype */ |
| @@ -461,6 +461,13 @@ unsigned long compaction_suitable(struct zone *zone, int order) | |||
| 461 | unsigned long watermark; | 461 | unsigned long watermark; |
| 462 | 462 | ||
| 463 | /* | 463 | /* |
| 464 | * order == -1 is expected when compacting via | ||
| 465 | * /proc/sys/vm/compact_memory | ||
| 466 | */ | ||
| 467 | if (order == -1) | ||
| 468 | return COMPACT_CONTINUE; | ||
| 469 | |||
| 470 | /* | ||
| 464 | * Watermarks for order-0 must be met for compaction. Note the 2UL. | 471 | * Watermarks for order-0 must be met for compaction. Note the 2UL. |
| 465 | * This is because during migration, copies of pages need to be | 472 | * This is because during migration, copies of pages need to be |
| 466 | * allocated and for a short time, the footprint is higher | 473 | * allocated and for a short time, the footprint is higher |
| @@ -470,13 +477,6 @@ unsigned long compaction_suitable(struct zone *zone, int order) | |||
| 470 | return COMPACT_SKIPPED; | 477 | return COMPACT_SKIPPED; |
| 471 | 478 | ||
| 472 | /* | 479 | /* |
| 473 | * order == -1 is expected when compacting via | ||
| 474 | * /proc/sys/vm/compact_memory | ||
| 475 | */ | ||
| 476 | if (order == -1) | ||
| 477 | return COMPACT_CONTINUE; | ||
| 478 | |||
| 479 | /* | ||
| 480 | * fragmentation index determines if allocation failures are due to | 480 | * fragmentation index determines if allocation failures are due to |
| 481 | * low memory or external fragmentation | 481 | * low memory or external fragmentation |
| 482 | * | 482 | * |
