mm/hugetlb: try preferred node first when alloc gigantic page from cma
[ceph-client.git] / mm / hugetlb.c
index a301c2d672bf5246f1ec4bf709374b3b78489189..5957dc80ebb1856ec19608b885a9cb0a98ffa984 100644 (file)
@@ -1250,21 +1250,32 @@ static struct page *alloc_gigantic_page(struct hstate *h, gfp_t gfp_mask,
                int nid, nodemask_t *nodemask)
 {
        unsigned long nr_pages = 1UL << huge_page_order(h);
+       if (nid == NUMA_NO_NODE)
+               nid = numa_mem_id();
 
 #ifdef CONFIG_CMA
        {
                struct page *page;
                int node;
 
-               for_each_node_mask(node, *nodemask) {
-                       if (!hugetlb_cma[node])
-                               continue;
-
-                       page = cma_alloc(hugetlb_cma[node], nr_pages,
-                                        huge_page_order(h), true);
+               if (hugetlb_cma[nid]) {
+                       page = cma_alloc(hugetlb_cma[nid], nr_pages,
+                                       huge_page_order(h), true);
                        if (page)
                                return page;
                }
+
+               if (!(gfp_mask & __GFP_THISNODE)) {
+                       for_each_node_mask(node, *nodemask) {
+                               if (node == nid || !hugetlb_cma[node])
+                                       continue;
+
+                               page = cma_alloc(hugetlb_cma[node], nr_pages,
+                                               huge_page_order(h), true);
+                               if (page)
+                                       return page;
+                       }
+               }
        }
 #endif