Merge tag 'block-5.9-2020-09-04' of git://git.kernel.dk/linux-block
[linux-2.6-microblaze.git] / mm / hugetlb.c
index b66bf74..a301c2d 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/memblock.h>
 #include <linux/sysfs.h>
 #include <linux/slab.h>
+#include <linux/sched/mm.h>
 #include <linux/mmdebug.h>
 #include <linux/sched/signal.h>
 #include <linux/rmap.h>
@@ -1040,10 +1041,16 @@ static void enqueue_huge_page(struct hstate *h, struct page *page)
 static struct page *dequeue_huge_page_node_exact(struct hstate *h, int nid)
 {
        struct page *page;
+       bool nocma = !!(current->flags & PF_MEMALLOC_NOCMA);
+
+       list_for_each_entry(page, &h->hugepage_freelists[nid], lru) {
+               if (nocma && is_migrate_cma_page(page))
+                       continue;
 
-       list_for_each_entry(page, &h->hugepage_freelists[nid], lru)
                if (!PageHWPoison(page))
                        break;
+       }
+
        /*
         * if 'non-isolated free hugepage' not found on the list,
         * the allocation fails.
@@ -1093,15 +1100,6 @@ retry_cpuset:
        return NULL;
 }
 
-/* Movability of hugepages depends on migration support. */
-static inline gfp_t htlb_alloc_mask(struct hstate *h)
-{
-       if (hugepage_movable_supported(h))
-               return GFP_HIGHUSER_MOVABLE;
-       else
-               return GFP_HIGHUSER;
-}
-
 static struct page *dequeue_huge_page_vma(struct hstate *h,
                                struct vm_area_struct *vma,
                                unsigned long address, int avoid_reserve,
@@ -1944,7 +1942,7 @@ out_unlock:
        return page;
 }
 
-struct page *alloc_migrate_huge_page(struct hstate *h, gfp_t gfp_mask,
+static struct page *alloc_migrate_huge_page(struct hstate *h, gfp_t gfp_mask,
                                     int nid, nodemask_t *nmask)
 {
        struct page *page;
@@ -1985,32 +1983,10 @@ struct page *alloc_buddy_huge_page_with_mpol(struct hstate *h,
        return page;
 }
 
-/* page migration callback function */
-struct page *alloc_huge_page_node(struct hstate *h, int nid)
-{
-       gfp_t gfp_mask = htlb_alloc_mask(h);
-       struct page *page = NULL;
-
-       if (nid != NUMA_NO_NODE)
-               gfp_mask |= __GFP_THISNODE;
-
-       spin_lock(&hugetlb_lock);
-       if (h->free_huge_pages - h->resv_huge_pages > 0)
-               page = dequeue_huge_page_nodemask(h, gfp_mask, nid, NULL);
-       spin_unlock(&hugetlb_lock);
-
-       if (!page)
-               page = alloc_migrate_huge_page(h, gfp_mask, nid, NULL);
-
-       return page;
-}
-
 /* page migration callback function */
 struct page *alloc_huge_page_nodemask(struct hstate *h, int preferred_nid,
-               nodemask_t *nmask)
+               nodemask_t *nmask, gfp_t gfp_mask)
 {
-       gfp_t gfp_mask = htlb_alloc_mask(h);
-
        spin_lock(&hugetlb_lock);
        if (h->free_huge_pages - h->resv_huge_pages > 0) {
                struct page *page;
@@ -2038,7 +2014,7 @@ struct page *alloc_huge_page_vma(struct hstate *h, struct vm_area_struct *vma,
 
        gfp_mask = htlb_alloc_mask(h);
        node = huge_node(vma, address, gfp_mask, &mpol, &nodemask);
-       page = alloc_huge_page_nodemask(h, node, nodemask);
+       page = alloc_huge_page_nodemask(h, node, nodemask, gfp_mask);
        mpol_cond_put(mpol);
 
        return page;