mm: vmscan: reduce size of inactive file list
[cascardo/linux.git] / mm / page_alloc.c
index 34f688b..edbdf56 100644 (file)
@@ -352,6 +352,106 @@ static inline bool update_defer_init(pg_data_t *pgdat,
 }
 #endif
 
+/* Return a pointer to the bitmap storing bits affecting a block of pages */
+static inline unsigned long *get_pageblock_bitmap(struct page *page,
+                                                       unsigned long pfn)
+{
+#ifdef CONFIG_SPARSEMEM
+       return __pfn_to_section(pfn)->pageblock_flags;
+#else
+       return page_zone(page)->pageblock_flags;
+#endif /* CONFIG_SPARSEMEM */
+}
+
+static inline int pfn_to_bitidx(struct page *page, unsigned long pfn)
+{
+#ifdef CONFIG_SPARSEMEM
+       pfn &= (PAGES_PER_SECTION-1);
+       return (pfn >> pageblock_order) * NR_PAGEBLOCK_BITS;
+#else
+       pfn = pfn - round_down(page_zone(page)->zone_start_pfn, pageblock_nr_pages);
+       return (pfn >> pageblock_order) * NR_PAGEBLOCK_BITS;
+#endif /* CONFIG_SPARSEMEM */
+}
+
+/**
+ * get_pfnblock_flags_mask - Return the requested group of flags for the pageblock_nr_pages block of pages
+ * @page: The page within the block of interest
+ * @pfn: The target page frame number
+ * @end_bitidx: The last bit of interest to retrieve
+ * @mask: mask of bits that the caller is interested in
+ *
+ * Return: pageblock_bits flags
+ */
+static __always_inline unsigned long __get_pfnblock_flags_mask(struct page *page,
+                                       unsigned long pfn,
+                                       unsigned long end_bitidx,
+                                       unsigned long mask)
+{
+       unsigned long *bitmap;
+       unsigned long bitidx, word_bitidx;
+       unsigned long word;
+
+       bitmap = get_pageblock_bitmap(page, pfn);
+       bitidx = pfn_to_bitidx(page, pfn);
+       word_bitidx = bitidx / BITS_PER_LONG;
+       bitidx &= (BITS_PER_LONG-1);
+
+       word = bitmap[word_bitidx];
+       bitidx += end_bitidx;
+       return (word >> (BITS_PER_LONG - bitidx - 1)) & mask;
+}
+
+unsigned long get_pfnblock_flags_mask(struct page *page, unsigned long pfn,
+                                       unsigned long end_bitidx,
+                                       unsigned long mask)
+{
+       return __get_pfnblock_flags_mask(page, pfn, end_bitidx, mask);
+}
+
+static __always_inline int get_pfnblock_migratetype(struct page *page, unsigned long pfn)
+{
+       return __get_pfnblock_flags_mask(page, pfn, PB_migrate_end, MIGRATETYPE_MASK);
+}
+
+/**
+ * set_pfnblock_flags_mask - Set the requested group of flags for a pageblock_nr_pages block of pages
+ * @page: The page within the block of interest
+ * @flags: The flags to set
+ * @pfn: The target page frame number
+ * @end_bitidx: The last bit of interest
+ * @mask: mask of bits that the caller is interested in
+ */
+void set_pfnblock_flags_mask(struct page *page, unsigned long flags,
+                                       unsigned long pfn,
+                                       unsigned long end_bitidx,
+                                       unsigned long mask)
+{
+       unsigned long *bitmap;
+       unsigned long bitidx, word_bitidx;
+       unsigned long old_word, word;
+
+       BUILD_BUG_ON(NR_PAGEBLOCK_BITS != 4);
+
+       bitmap = get_pageblock_bitmap(page, pfn);
+       bitidx = pfn_to_bitidx(page, pfn);
+       word_bitidx = bitidx / BITS_PER_LONG;
+       bitidx &= (BITS_PER_LONG-1);
+
+       VM_BUG_ON_PAGE(!zone_spans_pfn(page_zone(page), pfn), page);
+
+       bitidx += end_bitidx;
+       mask <<= (BITS_PER_LONG - bitidx - 1);
+       flags <<= (BITS_PER_LONG - bitidx - 1);
+
+       word = READ_ONCE(bitmap[word_bitidx]);
+       for (;;) {
+               old_word = cmpxchg(&bitmap[word_bitidx], word, (word & ~mask) | flags);
+               if (word == old_word)
+                       break;
+               word = old_word;
+       }
+}
 
 void set_pageblock_migratetype(struct page *page, int migratetype)
 {
@@ -784,10 +884,35 @@ out:
        zone->free_area[order].nr_free++;
 }
 
-static inline int free_pages_check(struct page *page)
+/*
+ * A bad page could be due to a number of fields. Instead of multiple branches,
+ * try and check multiple fields with one check. The caller must do a detailed
+ * check if necessary.
+ */
+static inline bool page_expected_state(struct page *page,
+                                       unsigned long check_flags)
 {
-       const char *bad_reason = NULL;
-       unsigned long bad_flags = 0;
+       if (unlikely(atomic_read(&page->_mapcount) != -1))
+               return false;
+
+       if (unlikely((unsigned long)page->mapping |
+                       page_ref_count(page) |
+#ifdef CONFIG_MEMCG
+                       (unsigned long)page->mem_cgroup |
+#endif
+                       (page->flags & check_flags)))
+               return false;
+
+       return true;
+}
+
+static void free_pages_check_bad(struct page *page)
+{
+       const char *bad_reason;
+       unsigned long bad_flags;
+
+       bad_reason = NULL;
+       bad_flags = 0;
 
        if (unlikely(atomic_read(&page->_mapcount) != -1))
                bad_reason = "nonzero mapcount";
@@ -803,16 +928,146 @@ static inline int free_pages_check(struct page *page)
        if (unlikely(page->mem_cgroup))
                bad_reason = "page still charged to cgroup";
 #endif
-       if (unlikely(bad_reason)) {
-               bad_page(page, bad_reason, bad_flags);
-               return 1;
+       bad_page(page, bad_reason, bad_flags);
+}
+
+static inline int free_pages_check(struct page *page)
+{
+       if (likely(page_expected_state(page, PAGE_FLAGS_CHECK_AT_FREE)))
+               return 0;
+
+       /* Something has gone sideways, find it */
+       free_pages_check_bad(page);
+       return 1;
+}
+
+static int free_tail_pages_check(struct page *head_page, struct page *page)
+{
+       int ret = 1;
+
+       /*
+        * We rely page->lru.next never has bit 0 set, unless the page
+        * is PageTail(). Let's make sure that's true even for poisoned ->lru.
+        */
+       BUILD_BUG_ON((unsigned long)LIST_POISON1 & 1);
+
+       if (!IS_ENABLED(CONFIG_DEBUG_VM)) {
+               ret = 0;
+               goto out;
+       }
+       switch (page - head_page) {
+       case 1:
+               /* the first tail page: ->mapping is compound_mapcount() */
+               if (unlikely(compound_mapcount(page))) {
+                       bad_page(page, "nonzero compound_mapcount", 0);
+                       goto out;
+               }
+               break;
+       case 2:
+               /*
+                * the second tail page: ->mapping is
+                * page_deferred_list().next -- ignore value.
+                */
+               break;
+       default:
+               if (page->mapping != TAIL_MAPPING) {
+                       bad_page(page, "corrupted mapping in tail page", 0);
+                       goto out;
+               }
+               break;
        }
+       if (unlikely(!PageTail(page))) {
+               bad_page(page, "PageTail not set", 0);
+               goto out;
+       }
+       if (unlikely(compound_head(page) != head_page)) {
+               bad_page(page, "compound_head not consistent", 0);
+               goto out;
+       }
+       ret = 0;
+out:
+       page->mapping = NULL;
+       clear_compound_head(page);
+       return ret;
+}
+
+static __always_inline bool free_pages_prepare(struct page *page,
+                                       unsigned int order, bool check_free)
+{
+       int bad = 0;
+
+       VM_BUG_ON_PAGE(PageTail(page), page);
+
+       trace_mm_page_free(page, order);
+       kmemcheck_free_shadow(page, order);
+       kasan_free_pages(page, order);
+
+       /*
+        * Check tail pages before head page information is cleared to
+        * avoid checking PageCompound for order-0 pages.
+        */
+       if (unlikely(order)) {
+               bool compound = PageCompound(page);
+               int i;
+
+               VM_BUG_ON_PAGE(compound && compound_order(page) != order, page);
+
+               for (i = 1; i < (1 << order); i++) {
+                       if (compound)
+                               bad += free_tail_pages_check(page, page + i);
+                       if (unlikely(free_pages_check(page + i))) {
+                               bad++;
+                               continue;
+                       }
+                       (page + i)->flags &= ~PAGE_FLAGS_CHECK_AT_PREP;
+               }
+       }
+       if (PageAnonHead(page))
+               page->mapping = NULL;
+       if (check_free)
+               bad += free_pages_check(page);
+       if (bad)
+               return false;
+
        page_cpupid_reset_last(page);
-       if (page->flags & PAGE_FLAGS_CHECK_AT_PREP)
-               page->flags &= ~PAGE_FLAGS_CHECK_AT_PREP;
-       return 0;
+       page->flags &= ~PAGE_FLAGS_CHECK_AT_PREP;
+       reset_page_owner(page, order);
+
+       if (!PageHighMem(page)) {
+               debug_check_no_locks_freed(page_address(page),
+                                          PAGE_SIZE << order);
+               debug_check_no_obj_freed(page_address(page),
+                                          PAGE_SIZE << order);
+       }
+       arch_free_page(page, order);
+       kernel_poison_pages(page, 1 << order, 0);
+       kernel_map_pages(page, 1 << order, 0);
+
+       return true;
 }
 
+#ifdef CONFIG_DEBUG_VM
+static inline bool free_pcp_prepare(struct page *page)
+{
+       return free_pages_prepare(page, 0, true);
+}
+
+static inline bool bulkfree_pcp_prepare(struct page *page)
+{
+       return false;
+}
+#else
+static bool free_pcp_prepare(struct page *page)
+{
+       return free_pages_prepare(page, 0, false);
+}
+
+static bool bulkfree_pcp_prepare(struct page *page)
+{
+       return free_pages_check(page);
+}
+#endif /* CONFIG_DEBUG_VM */
+
 /*
  * Frees a number of pages from the PCP lists
  * Assumes all pages on list are in same zone, and of same order.
@@ -829,15 +1084,16 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 {
        int migratetype = 0;
        int batch_free = 0;
-       int to_free = count;
        unsigned long nr_scanned;
+       bool isolated_pageblocks;
 
        spin_lock(&zone->lock);
+       isolated_pageblocks = has_isolate_pageblock(zone);
        nr_scanned = zone_page_state(zone, NR_PAGES_SCANNED);
        if (nr_scanned)
                __mod_zone_page_state(zone, NR_PAGES_SCANNED, -nr_scanned);
 
-       while (to_free) {
+       while (count) {
                struct page *page;
                struct list_head *list;
 
@@ -857,7 +1113,7 @@ static void free_pcppages_bulk(struct zone *zone, int count,
 
                /* This is the only non-empty list. Free them all. */
                if (batch_free == MIGRATE_PCPTYPES)
-                       batch_free = to_free;
+                       batch_free = count;
 
                do {
                        int mt; /* migratetype of the to-be-freed page */
@@ -870,12 +1126,15 @@ static void free_pcppages_bulk(struct zone *zone, int count,
                        /* MIGRATE_ISOLATE page should not go to pcplists */
                        VM_BUG_ON_PAGE(is_migrate_isolate(mt), page);
                        /* Pageblock could have been isolated meanwhile */
-                       if (unlikely(has_isolate_pageblock(zone)))
+                       if (unlikely(isolated_pageblocks))
                                mt = get_pageblock_migratetype(page);
 
+                       if (bulkfree_pcp_prepare(page))
+                               continue;
+
                        __free_one_page(page, page_to_pfn(page), zone, 0, mt);
                        trace_mm_page_pcpu_drain(page, 0, mt);
-               } while (--to_free && --batch_free && !list_empty(list));
+               } while (--count && --batch_free && !list_empty(list));
        }
        spin_unlock(&zone->lock);
 }
@@ -899,56 +1158,6 @@ static void free_one_page(struct zone *zone,
        spin_unlock(&zone->lock);
 }
 
-static int free_tail_pages_check(struct page *head_page, struct page *page)
-{
-       int ret = 1;
-
-       /*
-        * We rely page->lru.next never has bit 0 set, unless the page
-        * is PageTail(). Let's make sure that's true even for poisoned ->lru.
-        */
-       BUILD_BUG_ON((unsigned long)LIST_POISON1 & 1);
-
-       if (!IS_ENABLED(CONFIG_DEBUG_VM)) {
-               ret = 0;
-               goto out;
-       }
-       switch (page - head_page) {
-       case 1:
-               /* the first tail page: ->mapping is compound_mapcount() */
-               if (unlikely(compound_mapcount(page))) {
-                       bad_page(page, "nonzero compound_mapcount", 0);
-                       goto out;
-               }
-               break;
-       case 2:
-               /*
-                * the second tail page: ->mapping is
-                * page_deferred_list().next -- ignore value.
-                */
-               break;
-       default:
-               if (page->mapping != TAIL_MAPPING) {
-                       bad_page(page, "corrupted mapping in tail page", 0);
-                       goto out;
-               }
-               break;
-       }
-       if (unlikely(!PageTail(page))) {
-               bad_page(page, "PageTail not set", 0);
-               goto out;
-       }
-       if (unlikely(compound_head(page) != head_page)) {
-               bad_page(page, "compound_head not consistent", 0);
-               goto out;
-       }
-       ret = 0;
-out:
-       page->mapping = NULL;
-       clear_compound_head(page);
-       return ret;
-}
-
 static void __meminit __init_single_page(struct page *page, unsigned long pfn,
                                unsigned long zone, int nid)
 {
@@ -1017,47 +1226,9 @@ void __meminit reserve_bootmem_region(unsigned long start, unsigned long end)
                        /* Avoid false-positive PageTail() */
                        INIT_LIST_HEAD(&page->lru);
 
-                       SetPageReserved(page);
-               }
-       }
-}
-
-static bool free_pages_prepare(struct page *page, unsigned int order)
-{
-       bool compound = PageCompound(page);
-       int i, bad = 0;
-
-       VM_BUG_ON_PAGE(PageTail(page), page);
-       VM_BUG_ON_PAGE(compound && compound_order(page) != order, page);
-
-       trace_mm_page_free(page, order);
-       kmemcheck_free_shadow(page, order);
-       kasan_free_pages(page, order);
-
-       if (PageAnon(page))
-               page->mapping = NULL;
-       bad += free_pages_check(page);
-       for (i = 1; i < (1 << order); i++) {
-               if (compound)
-                       bad += free_tail_pages_check(page, page + i);
-               bad += free_pages_check(page + i);
-       }
-       if (bad)
-               return false;
-
-       reset_page_owner(page, order);
-
-       if (!PageHighMem(page)) {
-               debug_check_no_locks_freed(page_address(page),
-                                          PAGE_SIZE << order);
-               debug_check_no_obj_freed(page_address(page),
-                                          PAGE_SIZE << order);
-       }
-       arch_free_page(page, order);
-       kernel_poison_pages(page, 1 << order, 0);
-       kernel_map_pages(page, 1 << order, 0);
-
-       return true;
+                       SetPageReserved(page);
+               }
+       }
 }
 
 static void __free_pages_ok(struct page *page, unsigned int order)
@@ -1066,7 +1237,7 @@ static void __free_pages_ok(struct page *page, unsigned int order)
        int migratetype;
        unsigned long pfn = page_to_pfn(page);
 
-       if (!free_pages_prepare(page, order))
+       if (!free_pages_prepare(page, order, true))
                return;
 
        migratetype = get_pfnblock_migratetype(page, pfn);
@@ -1476,10 +1647,7 @@ static inline void expand(struct zone *zone, struct page *page,
        }
 }
 
-/*
- * This page is about to be returned from the page allocator
- */
-static inline int check_new_page(struct page *page)
+static void check_new_page_bad(struct page *page)
 {
        const char *bad_reason = NULL;
        unsigned long bad_flags = 0;
@@ -1502,11 +1670,20 @@ static inline int check_new_page(struct page *page)
        if (unlikely(page->mem_cgroup))
                bad_reason = "page still charged to cgroup";
 #endif
-       if (unlikely(bad_reason)) {
-               bad_page(page, bad_reason, bad_flags);
-               return 1;
-       }
-       return 0;
+       bad_page(page, bad_reason, bad_flags);
+}
+
+/*
+ * This page is about to be returned from the page allocator
+ */
+static inline int check_new_page(struct page *page)
+{
+       if (likely(page_expected_state(page,
+                               PAGE_FLAGS_CHECK_AT_PREP|__PG_HWPOISON)))
+               return 0;
+
+       check_new_page_bad(page);
+       return 1;
 }
 
 static inline bool free_pages_prezeroed(bool poisoned)
@@ -1515,16 +1692,48 @@ static inline bool free_pages_prezeroed(bool poisoned)
                page_poisoning_enabled() && poisoned;
 }
 
-static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags,
-                                                               int alloc_flags)
+#ifdef CONFIG_DEBUG_VM
+static bool check_pcp_refill(struct page *page)
+{
+       return false;
+}
+
+static bool check_new_pcp(struct page *page)
+{
+       return check_new_page(page);
+}
+#else
+static bool check_pcp_refill(struct page *page)
+{
+       return check_new_page(page);
+}
+static bool check_new_pcp(struct page *page)
+{
+       return false;
+}
+#endif /* CONFIG_DEBUG_VM */
+
+static bool check_new_pages(struct page *page, unsigned int order)
+{
+       int i;
+       for (i = 0; i < (1 << order); i++) {
+               struct page *p = page + i;
+
+               if (unlikely(check_new_page(p)))
+                       return true;
+       }
+
+       return false;
+}
+
+static void prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags,
+                                                       unsigned int alloc_flags)
 {
        int i;
        bool poisoned = true;
 
        for (i = 0; i < (1 << order); i++) {
                struct page *p = page + i;
-               if (unlikely(check_new_page(p)))
-                       return 1;
                if (poisoned)
                        poisoned &= page_is_poisoned(p);
        }
@@ -1556,8 +1765,6 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags,
                set_page_pfmemalloc(page);
        else
                clear_page_pfmemalloc(page);
-
-       return 0;
 }
 
 /*
@@ -1979,6 +2186,9 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order,
                if (unlikely(page == NULL))
                        break;
 
+               if (unlikely(check_pcp_refill(page)))
+                       continue;
+
                /*
                 * Split buddy pages returned by expand() are received here
                 * in physical page order. The page is added to the callers and
@@ -2156,6 +2366,10 @@ void mark_free_pages(struct zone *zone)
        for (pfn = zone->zone_start_pfn; pfn < max_zone_pfn; pfn++)
                if (pfn_valid(pfn)) {
                        page = pfn_to_page(pfn);
+
+                       if (page_zone(page) != zone)
+                               continue;
+
                        if (!swsusp_page_is_forbidden(page))
                                swsusp_unset_page_free(page);
                }
@@ -2186,7 +2400,7 @@ void free_hot_cold_page(struct page *page, bool cold)
        unsigned long pfn = page_to_pfn(page);
        int migratetype;
 
-       if (!free_pages_prepare(page, 0))
+       if (!free_pcp_prepare(page))
                return;
 
        migratetype = get_pfnblock_migratetype(page, pfn);
@@ -2341,13 +2555,45 @@ int split_free_page(struct page *page)
        return nr_pages;
 }
 
+/*
+ * Update NUMA hit/miss statistics
+ *
+ * Must be called with interrupts disabled.
+ *
+ * When __GFP_OTHER_NODE is set assume the node of the preferred
+ * zone is the local node. This is useful for daemons who allocate
+ * memory on behalf of other processes.
+ */
+static inline void zone_statistics(struct zone *preferred_zone, struct zone *z,
+                                                               gfp_t flags)
+{
+#ifdef CONFIG_NUMA
+       int local_nid = numa_node_id();
+       enum zone_stat_item local_stat = NUMA_LOCAL;
+
+       if (unlikely(flags & __GFP_OTHER_NODE)) {
+               local_stat = NUMA_OTHER;
+               local_nid = preferred_zone->node;
+       }
+
+       if (z->node == local_nid) {
+               __inc_zone_state(z, NUMA_HIT);
+               __inc_zone_state(z, local_stat);
+       } else {
+               __inc_zone_state(z, NUMA_MISS);
+               __inc_zone_state(preferred_zone, NUMA_FOREIGN);
+       }
+#endif
+}
+
 /*
  * Allocate a page from the given zone. Use pcplists for order-0 allocations.
  */
 static inline
 struct page *buffered_rmqueue(struct zone *preferred_zone,
                        struct zone *zone, unsigned int order,
-                       gfp_t gfp_flags, int alloc_flags, int migratetype)
+                       gfp_t gfp_flags, unsigned int alloc_flags,
+                       int migratetype)
 {
        unsigned long flags;
        struct page *page;
@@ -2358,21 +2604,24 @@ struct page *buffered_rmqueue(struct zone *preferred_zone,
                struct list_head *list;
 
                local_irq_save(flags);
-               pcp = &this_cpu_ptr(zone->pageset)->pcp;
-               list = &pcp->lists[migratetype];
-               if (list_empty(list)) {
-                       pcp->count += rmqueue_bulk(zone, 0,
-                                       pcp->batch, list,
-                                       migratetype, cold);
-                       if (unlikely(list_empty(list)))
-                               goto failed;
-               }
+               do {
+                       pcp = &this_cpu_ptr(zone->pageset)->pcp;
+                       list = &pcp->lists[migratetype];
+                       if (list_empty(list)) {
+                               pcp->count += rmqueue_bulk(zone, 0,
+                                               pcp->batch, list,
+                                               migratetype, cold);
+                               if (unlikely(list_empty(list)))
+                                       goto failed;
+                       }
 
-               if (cold)
-                       page = list_last_entry(list, struct page, lru);
-               else
-                       page = list_first_entry(list, struct page, lru);
+                       if (cold)
+                               page = list_last_entry(list, struct page, lru);
+                       else
+                               page = list_first_entry(list, struct page, lru);
+               } while (page && check_new_pcp(page));
 
+               __dec_zone_state(zone, NR_ALLOC_BATCH);
                list_del(&page->lru);
                pcp->count--;
        } else {
@@ -2383,22 +2632,24 @@ struct page *buffered_rmqueue(struct zone *preferred_zone,
                WARN_ON_ONCE((gfp_flags & __GFP_NOFAIL) && (order > 1));
                spin_lock_irqsave(&zone->lock, flags);
 
-               page = NULL;
-               if (alloc_flags & ALLOC_HARDER) {
-                       page = __rmqueue_smallest(zone, order, MIGRATE_HIGHATOMIC);
-                       if (page)
-                               trace_mm_page_alloc_zone_locked(page, order, migratetype);
-               }
-               if (!page)
-                       page = __rmqueue(zone, order, migratetype);
+               do {
+                       page = NULL;
+                       if (alloc_flags & ALLOC_HARDER) {
+                               page = __rmqueue_smallest(zone, order, MIGRATE_HIGHATOMIC);
+                               if (page)
+                                       trace_mm_page_alloc_zone_locked(page, order, migratetype);
+                       }
+                       if (!page)
+                               page = __rmqueue(zone, order, migratetype);
+               } while (page && check_new_pages(page, order));
                spin_unlock(&zone->lock);
                if (!page)
                        goto failed;
+               __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
                __mod_zone_freepage_state(zone, -(1 << order),
                                          get_pcppage_migratetype(page));
        }
 
-       __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
        if (atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
            !test_bit(ZONE_FAIR_DEPLETED, &zone->flags))
                set_bit(ZONE_FAIR_DEPLETED, &zone->flags);
@@ -2500,12 +2751,13 @@ static inline bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)
  * to check in the allocation paths if no pages are free.
  */
 static bool __zone_watermark_ok(struct zone *z, unsigned int order,
-                       unsigned long mark, int classzone_idx, int alloc_flags,
+                       unsigned long mark, int classzone_idx,
+                       unsigned int alloc_flags,
                        long free_pages)
 {
        long min = mark;
        int o;
-       const int alloc_harder = (alloc_flags & ALLOC_HARDER);
+       const bool alloc_harder = (alloc_flags & ALLOC_HARDER);
 
        /* free_pages may go negative - that's OK */
        free_pages -= (1 << order) - 1;
@@ -2568,12 +2820,38 @@ static bool __zone_watermark_ok(struct zone *z, unsigned int order,
 }
 
 bool zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark,
-                     int classzone_idx, int alloc_flags)
+                     int classzone_idx, unsigned int alloc_flags)
 {
        return __zone_watermark_ok(z, order, mark, classzone_idx, alloc_flags,
                                        zone_page_state(z, NR_FREE_PAGES));
 }
 
+static inline bool zone_watermark_fast(struct zone *z, unsigned int order,
+               unsigned long mark, int classzone_idx, unsigned int alloc_flags)
+{
+       long free_pages = zone_page_state(z, NR_FREE_PAGES);
+       long cma_pages = 0;
+
+#ifdef CONFIG_CMA
+       /* If allocation can't use CMA areas don't use free CMA pages */
+       if (!(alloc_flags & ALLOC_CMA))
+               cma_pages = zone_page_state(z, NR_FREE_CMA_PAGES);
+#endif
+
+       /*
+        * Fast check for order-0 only. If this fails then the reserves
+        * need to be calculated. There is a corner case where the check
+        * passes but only the high-order atomic reserve are free. If
+        * the caller is !atomic then it'll uselessly search the free
+        * list. That corner case is then slower but it is harmless.
+        */
+       if (!order && (free_pages - cma_pages) > mark + z->lowmem_reserve[classzone_idx])
+               return true;
+
+       return __zone_watermark_ok(z, order, mark, classzone_idx, alloc_flags,
+                                       free_pages);
+}
+
 bool zone_watermark_ok_safe(struct zone *z, unsigned int order,
                        unsigned long mark, int classzone_idx)
 {
@@ -2629,27 +2907,24 @@ static struct page *
 get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags,
                                                const struct alloc_context *ac)
 {
-       struct zonelist *zonelist = ac->zonelist;
-       struct zoneref *z;
-       struct page *page = NULL;
+       struct zoneref *z = ac->preferred_zoneref;
        struct zone *zone;
-       int nr_fair_skipped = 0;
-       bool zonelist_rescan;
+       bool fair_skipped = false;
+       bool apply_fair = (alloc_flags & ALLOC_FAIR);
 
 zonelist_scan:
-       zonelist_rescan = false;
-
        /*
         * Scan zonelist, looking for a zone with enough free.
         * See also __cpuset_node_allowed() comment in kernel/cpuset.c.
         */
-       for_each_zone_zonelist_nodemask(zone, z, zonelist, ac->high_zoneidx,
+       for_next_zone_zonelist_nodemask(zone, z, ac->zonelist, ac->high_zoneidx,
                                                                ac->nodemask) {
+               struct page *page;
                unsigned long mark;
 
                if (cpusets_enabled() &&
                        (alloc_flags & ALLOC_CPUSET) &&
-                       !cpuset_zone_allowed(zone, gfp_mask))
+                       !__cpuset_zone_allowed(zone, gfp_mask))
                                continue;
                /*
                 * Distribute pages in proportion to the individual
@@ -2657,13 +2932,16 @@ zonelist_scan:
                 * page was allocated in should have no effect on the
                 * time the page has in memory before being reclaimed.
                 */
-               if (alloc_flags & ALLOC_FAIR) {
-                       if (!zone_local(ac->preferred_zone, zone))
-                               break;
+               if (apply_fair) {
                        if (test_bit(ZONE_FAIR_DEPLETED, &zone->flags)) {
-                               nr_fair_skipped++;
+                               fair_skipped = true;
                                continue;
                        }
+                       if (!zone_local(ac->preferred_zoneref->zone, zone)) {
+                               if (fair_skipped)
+                                       goto reset_fair;
+                               apply_fair = false;
+                       }
                }
                /*
                 * When allocating a page cache page for writing, we
@@ -2695,8 +2973,8 @@ zonelist_scan:
                        continue;
 
                mark = zone->watermark[alloc_flags & ALLOC_WMARK_MASK];
-               if (!zone_watermark_ok(zone, order, mark,
-                                      ac->classzone_idx, alloc_flags)) {
+               if (!zone_watermark_fast(zone, order, mark,
+                                      ac_classzone_idx(ac), alloc_flags)) {
                        int ret;
 
                        /* Checked here to keep the fast path fast */
@@ -2705,7 +2983,7 @@ zonelist_scan:
                                goto try_this_zone;
 
                        if (zone_reclaim_mode == 0 ||
-                           !zone_allows_reclaim(ac->preferred_zone, zone))
+                           !zone_allows_reclaim(ac->preferred_zoneref->zone, zone))
                                continue;
 
                        ret = zone_reclaim(zone, gfp_mask, order);
@@ -2719,7 +2997,7 @@ zonelist_scan:
                        default:
                                /* did we reclaim enough */
                                if (zone_watermark_ok(zone, order, mark,
-                                               ac->classzone_idx, alloc_flags))
+                                               ac_classzone_idx(ac), alloc_flags))
                                        goto try_this_zone;
 
                                continue;
@@ -2727,11 +3005,10 @@ zonelist_scan:
                }
 
 try_this_zone:
-               page = buffered_rmqueue(ac->preferred_zone, zone, order,
+               page = buffered_rmqueue(ac->preferred_zoneref->zone, zone, order,
                                gfp_mask, alloc_flags, ac->migratetype);
                if (page) {
-                       if (prep_new_page(page, order, gfp_mask, alloc_flags))
-                               goto try_this_zone;
+                       prep_new_page(page, order, gfp_mask, alloc_flags);
 
                        /*
                         * If this is a high-order atomic allocation then check
@@ -2752,18 +3029,13 @@ try_this_zone:
         * include remote zones now, before entering the slowpath and waking
         * kswapd: prefer spilling to a remote zone over swapping locally.
         */
-       if (alloc_flags & ALLOC_FAIR) {
-               alloc_flags &= ~ALLOC_FAIR;
-               if (nr_fair_skipped) {
-                       zonelist_rescan = true;
-                       reset_alloc_batches(ac->preferred_zone);
-               }
-               if (nr_online_nodes > 1)
-                       zonelist_rescan = true;
-       }
-
-       if (zonelist_rescan)
+       if (fair_skipped) {
+reset_fair:
+               apply_fair = false;
+               fair_skipped = false;
+               reset_alloc_batches(ac->preferred_zoneref->zone);
                goto zonelist_scan;
+       }
 
        return NULL;
 }
@@ -2871,22 +3143,18 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order,
                /* The OOM killer does not needlessly kill tasks for lowmem */
                if (ac->high_zoneidx < ZONE_NORMAL)
                        goto out;
-               /* The OOM killer does not compensate for IO-less reclaim */
-               if (!(gfp_mask & __GFP_FS)) {
-                       /*
-                        * XXX: Page reclaim didn't yield anything,
-                        * and the OOM killer can't be invoked, but
-                        * keep looping as per tradition.
-                        *
-                        * But do not keep looping if oom_killer_disable()
-                        * was already called, for the system is trying to
-                        * enter a quiescent state during suspend.
-                        */
-                       *did_some_progress = !oom_killer_disabled;
-                       goto out;
-               }
                if (pm_suspended_storage())
                        goto out;
+               /*
+                * XXX: GFP_NOFS allocations should rather fail than rely on
+                * other request to make a forward progress.
+                * We are in an unfortunate situation where out_of_memory cannot
+                * do much for this context but let's try it to at least get
+                * access to memory reserved if the current task is killed (see
+                * out_of_memory). Once filesystems are ready to handle allocation
+                * failures more gracefully we should just bail out here.
+                */
+
                /* The OOM killer may not free memory on a specific node */
                if (gfp_mask & __GFP_THISNODE)
                        goto out;
@@ -2916,7 +3184,7 @@ out:
 /* Try memory compaction for high-order allocations before reclaim */
 static struct page *
 __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
-               int alloc_flags, const struct alloc_context *ac,
+               unsigned int alloc_flags, const struct alloc_context *ac,
                enum migrate_mode mode, int *contended_compaction,
                bool *deferred_compaction)
 {
@@ -2972,7 +3240,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
 #else
 static inline struct page *
 __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
-               int alloc_flags, const struct alloc_context *ac,
+               unsigned int alloc_flags, const struct alloc_context *ac,
                enum migrate_mode mode, int *contended_compaction,
                bool *deferred_compaction)
 {
@@ -3012,7 +3280,7 @@ __perform_reclaim(gfp_t gfp_mask, unsigned int order,
 /* The really slow allocator path where we enter direct reclaim */
 static inline struct page *
 __alloc_pages_direct_reclaim(gfp_t gfp_mask, unsigned int order,
-               int alloc_flags, const struct alloc_context *ac,
+               unsigned int alloc_flags, const struct alloc_context *ac,
                unsigned long *did_some_progress)
 {
        struct page *page = NULL;
@@ -3048,13 +3316,13 @@ static void wake_all_kswapds(unsigned int order, const struct alloc_context *ac)
 
        for_each_zone_zonelist_nodemask(zone, z, ac->zonelist,
                                                ac->high_zoneidx, ac->nodemask)
-               wakeup_kswapd(zone, order, zone_idx(ac->preferred_zone));
+               wakeup_kswapd(zone, order, ac_classzone_idx(ac));
 }
 
-static inline int
+static inline unsigned int
 gfp_to_alloc_flags(gfp_t gfp_mask)
 {
-       int alloc_flags = ALLOC_WMARK_MIN | ALLOC_CPUSET;
+       unsigned int alloc_flags = ALLOC_WMARK_MIN | ALLOC_CPUSET;
 
        /* __GFP_HIGH is assumed to be the same as ALLOC_HIGH to save a branch. */
        BUILD_BUG_ON(__GFP_HIGH != (__force gfp_t) ALLOC_HIGH);
@@ -3115,7 +3383,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
 {
        bool can_direct_reclaim = gfp_mask & __GFP_DIRECT_RECLAIM;
        struct page *page = NULL;
-       int alloc_flags;
+       unsigned int alloc_flags;
        unsigned long pages_reclaimed = 0;
        unsigned long did_some_progress;
        enum migrate_mode migration_mode = MIGRATE_ASYNC;
@@ -3152,17 +3420,6 @@ retry:
         */
        alloc_flags = gfp_to_alloc_flags(gfp_mask);
 
-       /*
-        * Find the true preferred zone if the allocation is unconstrained by
-        * cpusets.
-        */
-       if (!(alloc_flags & ALLOC_CPUSET) && !ac->nodemask) {
-               struct zoneref *preferred_zoneref;
-               preferred_zoneref = first_zones_zonelist(ac->zonelist,
-                               ac->high_zoneidx, NULL, &ac->preferred_zone);
-               ac->classzone_idx = zonelist_zone_idx(preferred_zoneref);
-       }
-
        /* This is the last chance, in general, before the goto nopage. */
        page = get_page_from_freelist(gfp_mask, order,
                                alloc_flags & ~ALLOC_NO_WATERMARKS, ac);
@@ -3277,7 +3534,7 @@ retry:
        if ((did_some_progress && order <= PAGE_ALLOC_COSTLY_ORDER) ||
            ((gfp_mask & __GFP_REPEAT) && pages_reclaimed < (1 << order))) {
                /* Wait for some write requests to complete then retry */
-               wait_iff_congested(ac->preferred_zone, BLK_RW_ASYNC, HZ/50);
+               wait_iff_congested(ac->preferred_zoneref->zone, BLK_RW_ASYNC, HZ/50);
                goto retry;
        }
 
@@ -3315,17 +3572,24 @@ struct page *
 __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
                        struct zonelist *zonelist, nodemask_t *nodemask)
 {
-       struct zoneref *preferred_zoneref;
-       struct page *page = NULL;
+       struct page *page;
        unsigned int cpuset_mems_cookie;
-       int alloc_flags = ALLOC_WMARK_LOW|ALLOC_CPUSET|ALLOC_FAIR;
-       gfp_t alloc_mask; /* The gfp_t that was actually used for allocation */
+       unsigned int alloc_flags = ALLOC_WMARK_LOW|ALLOC_FAIR;
+       gfp_t alloc_mask = gfp_mask; /* The gfp_t that was actually used for allocation */
        struct alloc_context ac = {
                .high_zoneidx = gfp_zone(gfp_mask),
+               .zonelist = zonelist,
                .nodemask = nodemask,
                .migratetype = gfpflags_to_migratetype(gfp_mask),
        };
 
+       if (cpusets_enabled()) {
+               alloc_mask |= __GFP_HARDWALL;
+               alloc_flags |= ALLOC_CPUSET;
+               if (!ac.nodemask)
+                       ac.nodemask = &cpuset_current_mems_allowed;
+       }
+
        gfp_mask &= gfp_allowed_mask;
 
        lockdep_trace_alloc(gfp_mask);
@@ -3349,49 +3613,54 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
 retry_cpuset:
        cpuset_mems_cookie = read_mems_allowed_begin();
 
-       /* We set it here, as __alloc_pages_slowpath might have changed it */
-       ac.zonelist = zonelist;
-
        /* Dirty zone balancing only done in the fast path */
        ac.spread_dirty_pages = (gfp_mask & __GFP_WRITE);
 
        /* The preferred zone is used for statistics later */
-       preferred_zoneref = first_zones_zonelist(ac.zonelist, ac.high_zoneidx,
-                               ac.nodemask ? : &cpuset_current_mems_allowed,
-                               &ac.preferred_zone);
-       if (!ac.preferred_zone)
-               goto out;
-       ac.classzone_idx = zonelist_zone_idx(preferred_zoneref);
+       ac.preferred_zoneref = first_zones_zonelist(ac.zonelist,
+                                       ac.high_zoneidx, ac.nodemask);
+       if (!ac.preferred_zoneref) {
+               page = NULL;
+               goto no_zone;
+       }
 
        /* First allocation attempt */
-       alloc_mask = gfp_mask|__GFP_HARDWALL;
        page = get_page_from_freelist(alloc_mask, order, alloc_flags, &ac);
-       if (unlikely(!page)) {
-               /*
-                * Runtime PM, block IO and its error handling path
-                * can deadlock because I/O on the device might not
-                * complete.
-                */
-               alloc_mask = memalloc_noio_flags(gfp_mask);
-               ac.spread_dirty_pages = false;
-
-               page = __alloc_pages_slowpath(alloc_mask, order, &ac);
-       }
+       if (likely(page))
+               goto out;
 
-       if (kmemcheck_enabled && page)
-               kmemcheck_pagealloc_alloc(page, order, gfp_mask);
+       /*
+        * Runtime PM, block IO and its error handling path can deadlock
+        * because I/O on the device might not complete.
+        */
+       alloc_mask = memalloc_noio_flags(gfp_mask);
+       ac.spread_dirty_pages = false;
 
-       trace_mm_page_alloc(page, order, alloc_mask, ac.migratetype);
+       /*
+        * Restore the original nodemask if it was potentially replaced with
+        * &cpuset_current_mems_allowed to optimize the fast-path attempt.
+        */
+       if (cpusets_enabled())
+               ac.nodemask = nodemask;
+       page = __alloc_pages_slowpath(alloc_mask, order, &ac);
 
-out:
+no_zone:
        /*
         * When updating a task's mems_allowed, it is possible to race with
         * parallel threads in such a way that an allocation can fail while
         * the mask is being updated. If a page allocation is about to fail,
         * check if the cpuset changed during allocation and if so, retry.
         */
-       if (unlikely(!page && read_mems_allowed_retry(cpuset_mems_cookie)))
+       if (unlikely(!page && read_mems_allowed_retry(cpuset_mems_cookie))) {
+               alloc_mask = gfp_mask;
                goto retry_cpuset;
+       }
+
+out:
+       if (kmemcheck_enabled && page)
+               kmemcheck_pagealloc_alloc(page, order, gfp_mask);
+
+       trace_mm_page_alloc(page, order, alloc_mask, ac.migratetype);
 
        return page;
 }
@@ -3789,6 +4058,8 @@ void si_meminfo_node(struct sysinfo *val, int nid)
 {
        int zone_type;          /* needs to be signed */
        unsigned long managed_pages = 0;
+       unsigned long managed_highpages = 0;
+       unsigned long free_highpages = 0;
        pg_data_t *pgdat = NODE_DATA(nid);
 
        for (zone_type = 0; zone_type < MAX_NR_ZONES; zone_type++)
@@ -3797,12 +4068,19 @@ void si_meminfo_node(struct sysinfo *val, int nid)
        val->sharedram = node_page_state(nid, NR_SHMEM);
        val->freeram = node_page_state(nid, NR_FREE_PAGES);
 #ifdef CONFIG_HIGHMEM
-       val->totalhigh = pgdat->node_zones[ZONE_HIGHMEM].managed_pages;
-       val->freehigh = zone_page_state(&pgdat->node_zones[ZONE_HIGHMEM],
-                       NR_FREE_PAGES);
+       for (zone_type = 0; zone_type < MAX_NR_ZONES; zone_type++) {
+               struct zone *zone = &pgdat->node_zones[zone_type];
+
+               if (is_highmem(zone)) {
+                       managed_highpages += zone->managed_pages;
+                       free_highpages += zone_page_state(zone, NR_FREE_PAGES);
+               }
+       }
+       val->totalhigh = managed_highpages;
+       val->freehigh = free_highpages;
 #else
-       val->totalhigh = 0;
-       val->freehigh = 0;
+       val->totalhigh = managed_highpages;
+       val->freehigh = free_highpages;
 #endif
        val->mem_unit = PAGE_SIZE;
 }
@@ -4389,13 +4667,12 @@ static void build_zonelists(pg_data_t *pgdat)
  */
 int local_memory_node(int node)
 {
-       struct zone *zone;
+       struct zoneref *z;
 
-       (void)first_zones_zonelist(node_zonelist(node, GFP_KERNEL),
+       z = first_zones_zonelist(node_zonelist(node, GFP_KERNEL),
                                   gfp_zone(GFP_KERNEL),
-                                  NULL,
-                                  &zone);
-       return zone->node;
+                                  NULL);
+       return z->zone->node;
 }
 #endif
 
@@ -6393,49 +6670,6 @@ void setup_per_zone_wmarks(void)
        mutex_unlock(&zonelists_mutex);
 }
 
-/*
- * The inactive anon list should be small enough that the VM never has to
- * do too much work, but large enough that each inactive page has a chance
- * to be referenced again before it is swapped out.
- *
- * The inactive_anon ratio is the target ratio of ACTIVE_ANON to
- * INACTIVE_ANON pages on this zone's LRU, maintained by the
- * pageout code. A zone->inactive_ratio of 3 means 3:1 or 25% of
- * the anonymous pages are kept on the inactive list.
- *
- * total     target    max
- * memory    ratio     inactive anon
- * -------------------------------------
- *   10MB       1         5MB
- *  100MB       1        50MB
- *    1GB       3       250MB
- *   10GB      10       0.9GB
- *  100GB      31         3GB
- *    1TB     101        10GB
- *   10TB     320        32GB
- */
-static void __meminit calculate_zone_inactive_ratio(struct zone *zone)
-{
-       unsigned int gb, ratio;
-
-       /* Zone size in gigabytes */
-       gb = zone->managed_pages >> (30 - PAGE_SHIFT);
-       if (gb)
-               ratio = int_sqrt(10 * gb);
-       else
-               ratio = 1;
-
-       zone->inactive_ratio = ratio;
-}
-
-static void __meminit setup_per_zone_inactive_ratio(void)
-{
-       struct zone *zone;
-
-       for_each_zone(zone)
-               calculate_zone_inactive_ratio(zone);
-}
-
 /*
  * Initialise min_free_kbytes.
  *
@@ -6481,7 +6715,6 @@ int __meminit init_per_zone_wmark_min(void)
        setup_per_zone_wmarks();
        refresh_zone_stat_thresholds();
        setup_per_zone_lowmem_reserve();
-       setup_per_zone_inactive_ratio();
        return 0;
 }
 core_initcall(init_per_zone_wmark_min)
@@ -6724,98 +6957,6 @@ void *__init alloc_large_system_hash(const char *tablename,
        return table;
 }
 
-/* Return a pointer to the bitmap storing bits affecting a block of pages */
-static inline unsigned long *get_pageblock_bitmap(struct zone *zone,
-                                                       unsigned long pfn)
-{
-#ifdef CONFIG_SPARSEMEM
-       return __pfn_to_section(pfn)->pageblock_flags;
-#else
-       return zone->pageblock_flags;
-#endif /* CONFIG_SPARSEMEM */
-}
-
-static inline int pfn_to_bitidx(struct zone *zone, unsigned long pfn)
-{
-#ifdef CONFIG_SPARSEMEM
-       pfn &= (PAGES_PER_SECTION-1);
-       return (pfn >> pageblock_order) * NR_PAGEBLOCK_BITS;
-#else
-       pfn = pfn - round_down(zone->zone_start_pfn, pageblock_nr_pages);
-       return (pfn >> pageblock_order) * NR_PAGEBLOCK_BITS;
-#endif /* CONFIG_SPARSEMEM */
-}
-
-/**
- * get_pfnblock_flags_mask - Return the requested group of flags for the pageblock_nr_pages block of pages
- * @page: The page within the block of interest
- * @pfn: The target page frame number
- * @end_bitidx: The last bit of interest to retrieve
- * @mask: mask of bits that the caller is interested in
- *
- * Return: pageblock_bits flags
- */
-unsigned long get_pfnblock_flags_mask(struct page *page, unsigned long pfn,
-                                       unsigned long end_bitidx,
-                                       unsigned long mask)
-{
-       struct zone *zone;
-       unsigned long *bitmap;
-       unsigned long bitidx, word_bitidx;
-       unsigned long word;
-
-       zone = page_zone(page);
-       bitmap = get_pageblock_bitmap(zone, pfn);
-       bitidx = pfn_to_bitidx(zone, pfn);
-       word_bitidx = bitidx / BITS_PER_LONG;
-       bitidx &= (BITS_PER_LONG-1);
-
-       word = bitmap[word_bitidx];
-       bitidx += end_bitidx;
-       return (word >> (BITS_PER_LONG - bitidx - 1)) & mask;
-}
-
-/**
- * set_pfnblock_flags_mask - Set the requested group of flags for a pageblock_nr_pages block of pages
- * @page: The page within the block of interest
- * @flags: The flags to set
- * @pfn: The target page frame number
- * @end_bitidx: The last bit of interest
- * @mask: mask of bits that the caller is interested in
- */
-void set_pfnblock_flags_mask(struct page *page, unsigned long flags,
-                                       unsigned long pfn,
-                                       unsigned long end_bitidx,
-                                       unsigned long mask)
-{
-       struct zone *zone;
-       unsigned long *bitmap;
-       unsigned long bitidx, word_bitidx;
-       unsigned long old_word, word;
-
-       BUILD_BUG_ON(NR_PAGEBLOCK_BITS != 4);
-
-       zone = page_zone(page);
-       bitmap = get_pageblock_bitmap(zone, pfn);
-       bitidx = pfn_to_bitidx(zone, pfn);
-       word_bitidx = bitidx / BITS_PER_LONG;
-       bitidx &= (BITS_PER_LONG-1);
-
-       VM_BUG_ON_PAGE(!zone_spans_pfn(zone, pfn), page);
-
-       bitidx += end_bitidx;
-       mask <<= (BITS_PER_LONG - bitidx - 1);
-       flags <<= (BITS_PER_LONG - bitidx - 1);
-
-       word = READ_ONCE(bitmap[word_bitidx]);
-       for (;;) {
-               old_word = cmpxchg(&bitmap[word_bitidx], word, (word & ~mask) | flags);
-               if (word == old_word)
-                       break;
-               word = old_word;
-       }
-}
-
 /*
  * This function checks whether pageblock includes unmovable pages or not.
  * If @count is not zero, it is okay to include less @count unmovable pages
@@ -7176,7 +7317,8 @@ void zone_pcp_reset(struct zone *zone)
 
 #ifdef CONFIG_MEMORY_HOTREMOVE
 /*
- * All pages in the range must be isolated before calling this.
+ * All pages in the range must be in a single zone and isolated
+ * before calling this.
  */
 void
 __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn)