mm: accurately calculate zone->managed_pages for highmem zones
[firefly-linux-kernel-4.4.55.git] / mm / nobootmem.c
index bdd3fa2fc73b8395fa78979874eb46c2e3ab20c5..0ae8d91365af26de7d5d2cfc541f40a32c868fdb 100644 (file)
@@ -137,20 +137,25 @@ static unsigned long __init free_low_memory_core_early(void)
        return count;
 }
 
-static void reset_node_lowmem_managed_pages(pg_data_t *pgdat)
+static int reset_managed_pages_done __initdata;
+
+static inline void __init reset_node_managed_pages(pg_data_t *pgdat)
 {
        struct zone *z;
 
-       /*
-        * In free_area_init_core(), highmem zone's managed_pages is set to
-        * present_pages, and bootmem allocator doesn't allocate from highmem
-        * zones. So there's no need to recalculate managed_pages because all
-        * highmem pages will be managed by the buddy system. Here highmem
-        * zone also includes highmem movable zone.
-        */
+       if (reset_managed_pages_done)
+               return;
        for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++)
-               if (!is_highmem(z))
-                       z->managed_pages = 0;
+               z->managed_pages = 0;
+}
+
+void __init reset_all_zones_managed_pages(void)
+{
+       struct pglist_data *pgdat;
+
+       for_each_online_pgdat(pgdat)
+               reset_node_managed_pages(pgdat);
+       reset_managed_pages_done = 1;
 }
 
 /**
@@ -160,10 +165,7 @@ static void reset_node_lowmem_managed_pages(pg_data_t *pgdat)
  */
 unsigned long __init free_all_bootmem(void)
 {
-       struct pglist_data *pgdat;
-
-       for_each_online_pgdat(pgdat)
-               reset_node_lowmem_managed_pages(pgdat);
+       reset_all_zones_managed_pages();
 
        /*
         * We need to use MAX_NUMNODES instead of NODE_DATA(0)->node_id