[PATCH] mm/compaction: fix isolated page counting bug in compaction

From: Joonsoo Kim
Date: Mon Sep 29 2014 - 02:08:07 EST


acct_isolated() is the function to adjust isolated page count. It
iterates cc->migratepages list and add
NR_ISOLATED_ANON/NR_ISOLATED_FILE count according to number of anon,
file pages in migratepages list, respectively. Before commit (mm,
compaction: move pageblock checks up from isolate_migratepages_range()),
it is called just once in isolate_migratepages_range(), but, after commit,
it is called in newly introduced isolate_migratepages_block() and this
isolate_migratepages_block() could be called many times in
isolate_migratepages_range() so that some page could be counted more
than once. This duplicate counting bug results in hang in cma_alloc(),
because too_many_isolated() returns true continually.

This patch fixes this bug by moving acct_isolated() into upper layer
function, isolate_migratepages_range() and isolate_migratepages().
After this change, isolated page would be counted only once so
problem would be gone.

Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@xxxxxxx>
---
mm/compaction.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/mm/compaction.c b/mm/compaction.c
index 7d9d92e..48129b6 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -514,22 +514,19 @@ isolate_freepages_range(struct compact_control *cc,
}

/* Update the number of anon and file isolated pages in the zone */
-static void acct_isolated(struct zone *zone, bool locked, struct compact_control *cc)
+static void acct_isolated(struct zone *zone, struct compact_control *cc)
{
struct page *page;
unsigned int count[2] = { 0, };

+ if (list_empty(&cc->migratepages))
+ return;
+
list_for_each_entry(page, &cc->migratepages, lru)
count[!!page_is_file_cache(page)]++;

- /* If locked we can use the interrupt unsafe versions */
- if (locked) {
- __mod_zone_page_state(zone, NR_ISOLATED_ANON, count[0]);
- __mod_zone_page_state(zone, NR_ISOLATED_FILE, count[1]);
- } else {
- mod_zone_page_state(zone, NR_ISOLATED_ANON, count[0]);
- mod_zone_page_state(zone, NR_ISOLATED_FILE, count[1]);
- }
+ mod_zone_page_state(zone, NR_ISOLATED_ANON, count[0]);
+ mod_zone_page_state(zone, NR_ISOLATED_FILE, count[1]);
}

/* Similar to reclaim, but different enough that they don't share logic */
@@ -726,8 +723,6 @@ isolate_success:
if (unlikely(low_pfn > end_pfn))
low_pfn = end_pfn;

- acct_isolated(zone, locked, cc);
-
if (locked)
spin_unlock_irqrestore(&zone->lru_lock, flags);

@@ -789,6 +784,7 @@ isolate_migratepages_range(struct compact_control *cc, unsigned long start_pfn,
break;
}
}
+ acct_isolated(cc->zone, cc);

return pfn;
}
@@ -1028,6 +1024,7 @@ static isolate_migrate_t isolate_migratepages(struct zone *zone,
break;
}

+ acct_isolated(zone, cc);
/* Record where migration scanner will be restarted */
cc->migrate_pfn = low_pfn;

--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/