[PATCH 4/4] mm: skip to reserve pageblock crossed zone boundary for HIGHATOMIC

From: Minchan Kim
Date: Fri Oct 07 2016 - 01:46:28 EST


In CONFIG_SPARSEMEM, VM shares a pageblock_flags of a mem_section
between two zones if the pageblock cross zone boundaries. It means
a zone lock cannot protect pageblock migratype change's race.

It might be not a problem because migratetype inherently was racy
but intrdocuing with CMA, it was not true any more and have been fixed.
(I hope it should be solved more general approach however...)
And then, it's time for MIGRATE_HIGHATOMIC.

More importantly, HIGHATOMIC migratetype is not big(i.e., 1%) reserve
in system so let's skip such crippled pageblock to try to reserve
full 1% free memory.

Debugged-by: Joonsoo Kim <iamjoonsoo.kim@xxxxxxx>
Signed-off-by: Minchan Kim <minchan@xxxxxxxxxx>
---
mm/page_alloc.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index eeb047bb0e9d..d76bb50baf61 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2098,6 +2098,24 @@ static void reserve_highatomic_pageblock(struct page *page, struct zone *zone,
mt = get_pageblock_migratetype(page);
if (mt != MIGRATE_HIGHATOMIC &&
!is_migrate_isolate(mt) && !is_migrate_cma(mt)) {
+ /*
+ * If the pageblock cross zone boundaries, we need both
+ * zone locks but doesn't want to make complex because
+ * highatomic pageblock is small so that we want to reserve
+ * sane(?) pageblock.
+ */
+ unsigned long start_pfn, end_pfn;
+
+ start_pfn = page_to_pfn(page);
+ start_pfn = start_pfn & ~(pageblock_nr_pages - 1);
+
+ if (!zone_spans_pfn(zone, start_pfn))
+ goto out_unlock;
+
+ end_pfn = start_pfn + pageblock_nr_pages - 1;
+ if (!zone_spans_pfn(zone, end_pfn))
+ goto out_unlock;
+
zone->nr_reserved_highatomic += pageblock_nr_pages;
set_pageblock_migratetype(page, MIGRATE_HIGHATOMIC);
move_freepages_block(zone, page, MIGRATE_HIGHATOMIC);
--
2.7.4