Skip to content

Commit 3957c77

Browse files
Michal Hockotorvalds
authored andcommitted
mm: compaction: fix special case -1 order checks
Commit 56de726 ("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 82478fb (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>
1 parent 5f1a190 commit 3957c77

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

‎mm/compaction.c‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -420,20 +420,20 @@ static int compact_finished(struct zone *zone,
420420
if (cc->free_pfn <= cc->migrate_pfn)
421421
return COMPACT_COMPLETE;
422422

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-
430423
/*
431424
* order == -1 is expected when compacting via
432425
* /proc/sys/vm/compact_memory
433426
*/
434427
if (cc->order == -1)
435428
return COMPACT_CONTINUE;
436429

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+
437437
/* Direct compactor: Is a suitable page free? */
438438
for (order = cc->order; order < MAX_ORDER; order++) {
439439
/* Job done if page is free of the right migratetype */
@@ -460,6 +460,13 @@ unsigned long compaction_suitable(struct zone *zone, int order)
460460
int fragindex;
461461
unsigned long watermark;
462462

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+
463470
/*
464471
* Watermarks for order-0 must be met for compaction. Note the 2UL.
465472
* This is because during migration, copies of pages need to be
@@ -469,13 +476,6 @@ unsigned long compaction_suitable(struct zone *zone, int order)
469476
if (!zone_watermark_ok(zone, 0, watermark, 0, 0))
470477
return COMPACT_SKIPPED;
471478

472-
/*
473-
* order == -1 is expected when compacting via
474-
* /proc/sys/vm/compact_memory
475-
*/
476-
if (order == -1)
477-
return COMPACT_CONTINUE;
478-
479479
/*
480480
* fragmentation index determines if allocation failures are due to
481481
* low memory or external fragmentation

0 commit comments

Comments
 (0)