mm, memory_hotplug: drop CONFIG_MOVABLE_NODE
[GitHub/moto-9609/android_kernel_motorola_exynos9610.git] / mm / page_alloc.c
index ceb45a8e1359a52d875a89d6af48266b0847c525..bd65b60939b611e18d3772d26079421d0b4eb495 100644 (file)
@@ -113,9 +113,7 @@ nodemask_t node_states[NR_NODE_STATES] __read_mostly = {
 #ifdef CONFIG_HIGHMEM
        [N_HIGH_MEMORY] = { { [0] = 1UL } },
 #endif
-#ifdef CONFIG_MOVABLE_NODE
        [N_MEMORY] = { { [0] = 1UL } },
-#endif
        [N_CPU] = { { [0] = 1UL } },
 #endif /* NUMA */
 };
@@ -3677,6 +3675,39 @@ should_reclaim_retry(gfp_t gfp_mask, unsigned order,
        return false;
 }
 
+static inline bool
+check_retry_cpuset(int cpuset_mems_cookie, struct alloc_context *ac)
+{
+       /*
+        * It's possible that cpuset's mems_allowed and the nodemask from
+        * mempolicy don't intersect. This should be normally dealt with by
+        * policy_nodemask(), but it's possible to race with cpuset update in
+        * such a way the check therein was true, and then it became false
+        * before we got our cpuset_mems_cookie here.
+        * This assumes that for all allocations, ac->nodemask can come only
+        * from MPOL_BIND mempolicy (whose documented semantics is to be ignored
+        * when it does not intersect with the cpuset restrictions) or the
+        * caller can deal with a violated nodemask.
+        */
+       if (cpusets_enabled() && ac->nodemask &&
+                       !cpuset_nodemask_valid_mems_allowed(ac->nodemask)) {
+               ac->nodemask = NULL;
+               return true;
+       }
+
+       /*
+        * When updating a task's mems_allowed or mempolicy nodemask, it is
+        * possible to race with parallel threads in such a way that our
+        * allocation can fail while the mask is being updated. If we are about
+        * to fail, check if the cpuset changed during allocation and if so,
+        * retry.
+        */
+       if (read_mems_allowed_retry(cpuset_mems_cookie))
+               return true;
+
+       return false;
+}
+
 static inline struct page *
 __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
                                                struct alloc_context *ac)
@@ -3872,11 +3903,9 @@ retry:
                                &compaction_retries))
                goto retry;
 
-       /*
-        * It's possible we raced with cpuset update so the OOM would be
-        * premature (see below the nopage: label for full explanation).
-        */
-       if (read_mems_allowed_retry(cpuset_mems_cookie))
+
+       /* Deal with possible cpuset update races before we start OOM killing */
+       if (check_retry_cpuset(cpuset_mems_cookie, ac))
                goto retry_cpuset;
 
        /* Reclaim has failed us, start killing things */
@@ -3897,14 +3926,8 @@ retry:
        }
 
 nopage:
-       /*
-        * When updating a task's mems_allowed or mempolicy nodemask, it is
-        * possible to race with parallel threads in such a way that our
-        * allocation can fail while the mask is being updated. If we are about
-        * to fail, check if the cpuset changed during allocation and if so,
-        * retry.
-        */
-       if (read_mems_allowed_retry(cpuset_mems_cookie))
+       /* Deal with possible cpuset update races before we fail */
+       if (check_retry_cpuset(cpuset_mems_cookie, ac))
                goto retry_cpuset;
 
        /*
@@ -3955,12 +3978,12 @@ got_pg:
 }
 
 static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order,
-               struct zonelist *zonelist, nodemask_t *nodemask,
+               int preferred_nid, nodemask_t *nodemask,
                struct alloc_context *ac, gfp_t *alloc_mask,
                unsigned int *alloc_flags)
 {
        ac->high_zoneidx = gfp_zone(gfp_mask);
-       ac->zonelist = zonelist;
+       ac->zonelist = node_zonelist(preferred_nid, gfp_mask);
        ac->nodemask = nodemask;
        ac->migratetype = gfpflags_to_migratetype(gfp_mask);
 
@@ -4005,8 +4028,8 @@ static inline void finalise_ac(gfp_t gfp_mask,
  * This is the 'heart' of the zoned buddy allocator.
  */
 struct page *
-__alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
-                       struct zonelist *zonelist, nodemask_t *nodemask)
+__alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, int preferred_nid,
+                                                       nodemask_t *nodemask)
 {
        struct page *page;
        unsigned int alloc_flags = ALLOC_WMARK_LOW;
@@ -4014,7 +4037,7 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
        struct alloc_context ac = { };
 
        gfp_mask &= gfp_allowed_mask;
-       if (!prepare_alloc_pages(gfp_mask, order, zonelist, nodemask, &ac, &alloc_mask, &alloc_flags))
+       if (!prepare_alloc_pages(gfp_mask, order, preferred_nid, nodemask, &ac, &alloc_mask, &alloc_flags))
                return NULL;
 
        finalise_ac(gfp_mask, order, &ac);
@@ -4618,8 +4641,6 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask)
                        " present:%lukB"
                        " managed:%lukB"
                        " mlocked:%lukB"
-                       " slab_reclaimable:%lukB"
-                       " slab_unreclaimable:%lukB"
                        " kernel_stack:%lukB"
                        " pagetables:%lukB"
                        " bounce:%lukB"
@@ -4641,8 +4662,6 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask)
                        K(zone->present_pages),
                        K(zone->managed_pages),
                        K(zone_page_state(zone, NR_MLOCK)),
-                       K(zone_page_state(zone, NR_SLAB_RECLAIMABLE)),
-                       K(zone_page_state(zone, NR_SLAB_UNRECLAIMABLE)),
                        zone_page_state(zone, NR_KERNEL_STACK_KB),
                        K(zone_page_state(zone, NR_PAGETABLE)),
                        K(zone_page_state(zone, NR_BOUNCE)),
@@ -5128,6 +5147,7 @@ static void build_zonelists(pg_data_t *pgdat)
  */
 static void setup_pageset(struct per_cpu_pageset *p, unsigned long batch);
 static DEFINE_PER_CPU(struct per_cpu_pageset, boot_pageset);
+static DEFINE_PER_CPU(struct per_cpu_nodestat, boot_nodestats);
 static void setup_zone_pageset(struct zone *zone);
 
 /*
@@ -6028,6 +6048,8 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat)
        spin_lock_init(&pgdat->lru_lock);
        lruvec_init(node_lruvec(pgdat));
 
+       pgdat->per_cpu_nodestats = &boot_nodestats;
+
        for (j = 0; j < MAX_NR_ZONES; j++) {
                struct zone *zone = pgdat->node_zones + j;
                unsigned long size, realsize, freesize, memmap_pages;