]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - mm/page_alloc.c
scripts/spelling.txt: add "algined" pattern and fix typo instances
[linux.git] / mm / page_alloc.c
index 65876feb86f3357d6a44827b218ae9763a05aea8..a7a6aac95a6d158690e1ca0981b1b652820248d4 100644 (file)
@@ -59,7 +59,6 @@
 #include <linux/prefetch.h>
 #include <linux/mm_inline.h>
 #include <linux/migrate.h>
-#include <linux/page_ext.h>
 #include <linux/hugetlb.h>
 #include <linux/sched/rt.h>
 #include <linux/page_owner.h>
@@ -92,6 +91,10 @@ EXPORT_PER_CPU_SYMBOL(_numa_mem_);
 int _node_numa_mem_[MAX_NUMNODES];
 #endif
 
+/* work_structs for global per-cpu drains */
+DEFINE_MUTEX(pcpu_drain_mutex);
+DEFINE_PER_CPU(struct work_struct, pcpu_drain);
+
 #ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY
 volatile unsigned long latent_entropy __latent_entropy;
 EXPORT_SYMBOL(latent_entropy);
@@ -2360,7 +2363,6 @@ static void drain_local_pages_wq(struct work_struct *work)
  */
 void drain_all_pages(struct zone *zone)
 {
-       struct work_struct __percpu *works;
        int cpu;
 
        /*
@@ -2373,7 +2375,16 @@ void drain_all_pages(struct zone *zone)
        if (current->flags & PF_WQ_WORKER)
                return;
 
-       works = alloc_percpu_gfp(struct work_struct, GFP_ATOMIC);
+       /*
+        * Do not drain if one is already in progress unless it's specific to
+        * a zone. Such callers are primarily CMA and memory hotplug and need
+        * the drain to be complete when the call returns.
+        */
+       if (unlikely(!mutex_trylock(&pcpu_drain_mutex))) {
+               if (!zone)
+                       return;
+               mutex_lock(&pcpu_drain_mutex);
+       }
 
        /*
         * We don't care about racing with CPU hotplug event
@@ -2406,23 +2417,15 @@ void drain_all_pages(struct zone *zone)
                        cpumask_clear_cpu(cpu, &cpus_with_pcps);
        }
 
-       if (works) {
-               for_each_cpu(cpu, &cpus_with_pcps) {
-                       struct work_struct *work = per_cpu_ptr(works, cpu);
-                       INIT_WORK(work, drain_local_pages_wq);
-                       schedule_work_on(cpu, work);
-               }
-               for_each_cpu(cpu, &cpus_with_pcps)
-                       flush_work(per_cpu_ptr(works, cpu));
-       } else {
-               for_each_cpu(cpu, &cpus_with_pcps) {
-                       struct work_struct work;
-
-                       INIT_WORK(&work, drain_local_pages_wq);
-                       schedule_work_on(cpu, &work);
-                       flush_work(&work);
-               }
+       for_each_cpu(cpu, &cpus_with_pcps) {
+               struct work_struct *work = per_cpu_ptr(&pcpu_drain, cpu);
+               INIT_WORK(work, drain_local_pages_wq);
+               schedule_work_on(cpu, work);
        }
+       for_each_cpu(cpu, &cpus_with_pcps)
+               flush_work(per_cpu_ptr(&pcpu_drain, cpu));
+
+       mutex_unlock(&pcpu_drain_mutex);
 }
 
 #ifdef CONFIG_HIBERNATION
@@ -2941,7 +2944,7 @@ bool zone_watermark_ok_safe(struct zone *z, unsigned int order,
 #ifdef CONFIG_NUMA
 static bool zone_allows_reclaim(struct zone *local_zone, struct zone *zone)
 {
-       return node_distance(zone_to_nid(local_zone), zone_to_nid(zone)) <
+       return node_distance(zone_to_nid(local_zone), zone_to_nid(zone)) <=
                                RECLAIM_DISTANCE;
 }
 #else  /* CONFIG_NUMA */
@@ -3903,9 +3906,10 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order,
 
        if (cpusets_enabled()) {
                *alloc_mask |= __GFP_HARDWALL;
-               *alloc_flags |= ALLOC_CPUSET;
                if (!ac->nodemask)
                        ac->nodemask = &cpuset_current_mems_allowed;
+               else
+                       *alloc_flags |= ALLOC_CPUSET;
        }
 
        lockdep_trace_alloc(gfp_mask);
@@ -5921,7 +5925,7 @@ static unsigned long __paginginit calc_memmap_size(unsigned long spanned_pages,
         * the zone and SPARSEMEM is in use. If there are holes within the
         * zone, each populated memory region may cost us one or two extra
         * memmap pages due to alignment because memmap pages for each
-        * populated regions may not naturally algined on page boundary.
+        * populated regions may not be naturally aligned on page boundary.
         * So the (present_pages >> 4) heuristic is a tradeoff for that.
         */
        if (spanned_pages > present_pages + (present_pages >> 4) &&
@@ -6485,8 +6489,6 @@ void __init free_area_init_nodes(unsigned long *max_zone_pfn)
 
                start_pfn = end_pfn;
        }
-       arch_zone_lowest_possible_pfn[ZONE_MOVABLE] = 0;
-       arch_zone_highest_possible_pfn[ZONE_MOVABLE] = 0;
 
        /* Find the PFNs that ZONE_MOVABLE begins at in each node */
        memset(zone_movable_pfn, 0, sizeof(zone_movable_pfn));
@@ -7222,8 +7224,9 @@ void *__init alloc_large_system_hash(const char *tablename,
  * If @count is not zero, it is okay to include less @count unmovable pages
  *
  * PageLRU check without isolation or lru_lock could race so that
- * MIGRATE_MOVABLE block might include unmovable pages. It means you can't
- * expect this function should be exact.
+ * MIGRATE_MOVABLE block might include unmovable pages. And __PageMovable
+ * check without lock_page also may miss some movable non-lru pages at
+ * race condition. So you can't expect this function should be exact.
  */
 bool has_unmovable_pages(struct zone *zone, struct page *page, int count,
                         bool skip_hwpoisoned_pages)
@@ -7279,6 +7282,9 @@ bool has_unmovable_pages(struct zone *zone, struct page *page, int count,
                if (skip_hwpoisoned_pages && PageHWPoison(page))
                        continue;
 
+               if (__PageMovable(page))
+                       continue;
+
                if (!PageLRU(page))
                        found++;
                /*
@@ -7390,6 +7396,7 @@ static int __alloc_contig_migrate_range(struct compact_control *cc,
  *                     #MIGRATE_MOVABLE or #MIGRATE_CMA).  All pageblocks
  *                     in range must have the same migratetype and it must
  *                     be either of the two.
+ * @gfp_mask:  GFP mask to use during compaction
  *
  * The PFN range does not have to be pageblock or MAX_ORDER_NR_PAGES
  * aligned, however it's the caller's responsibility to guarantee that
@@ -7403,7 +7410,7 @@ static int __alloc_contig_migrate_range(struct compact_control *cc,
  * need to be freed with free_contig_range().
  */
 int alloc_contig_range(unsigned long start, unsigned long end,
-                      unsigned migratetype)
+                      unsigned migratetype, gfp_t gfp_mask)
 {
        unsigned long outer_start, outer_end;
        unsigned int order;
@@ -7415,7 +7422,7 @@ int alloc_contig_range(unsigned long start, unsigned long end,
                .zone = page_zone(pfn_to_page(start)),
                .mode = MIGRATE_SYNC,
                .ignore_skip_hint = true,
-               .gfp_mask = GFP_KERNEL,
+               .gfp_mask = memalloc_noio_flags(gfp_mask),
        };
        INIT_LIST_HEAD(&cc.migratepages);