summaryrefslogtreecommitdiffstats
path: root/mm/hugetlb.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/hugetlb.c')
-rw-r--r--mm/hugetlb.c89
1 files changed, 79 insertions, 10 deletions
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 6d7296dd11b8..ef37c85423a5 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1405,12 +1405,25 @@ pgoff_t __basepage_index(struct page *page)
1405} 1405}
1406 1406
1407static struct page *alloc_buddy_huge_page(struct hstate *h, 1407static struct page *alloc_buddy_huge_page(struct hstate *h,
1408 gfp_t gfp_mask, int nid, nodemask_t *nmask) 1408 gfp_t gfp_mask, int nid, nodemask_t *nmask,
1409 nodemask_t *node_alloc_noretry)
1409{ 1410{
1410 int order = huge_page_order(h); 1411 int order = huge_page_order(h);
1411 struct page *page; 1412 struct page *page;
1413 bool alloc_try_hard = true;
1412 1414
1413 gfp_mask |= __GFP_COMP|__GFP_RETRY_MAYFAIL|__GFP_NOWARN; 1415 /*
1416 * By default we always try hard to allocate the page with
1417 * __GFP_RETRY_MAYFAIL flag. However, if we are allocating pages in
1418 * a loop (to adjust global huge page counts) and previous allocation
1419 * failed, do not continue to try hard on the same node. Use the
1420 * node_alloc_noretry bitmap to manage this state information.
1421 */
1422 if (node_alloc_noretry && node_isset(nid, *node_alloc_noretry))
1423 alloc_try_hard = false;
1424 gfp_mask |= __GFP_COMP|__GFP_NOWARN;
1425 if (alloc_try_hard)
1426 gfp_mask |= __GFP_RETRY_MAYFAIL;
1414 if (nid == NUMA_NO_NODE) 1427 if (nid == NUMA_NO_NODE)
1415 nid = numa_mem_id(); 1428 nid = numa_mem_id();
1416 page = __alloc_pages_nodemask(gfp_mask, order, nid, nmask); 1429 page = __alloc_pages_nodemask(gfp_mask, order, nid, nmask);
@@ -1419,6 +1432,22 @@ static struct page *alloc_buddy_huge_page(struct hstate *h,
1419 else 1432 else
1420 __count_vm_event(HTLB_BUDDY_PGALLOC_FAIL); 1433 __count_vm_event(HTLB_BUDDY_PGALLOC_FAIL);
1421 1434
1435 /*
1436 * If we did not specify __GFP_RETRY_MAYFAIL, but still got a page this
1437 * indicates an overall state change. Clear bit so that we resume
1438 * normal 'try hard' allocations.
1439 */
1440 if (node_alloc_noretry && page && !alloc_try_hard)
1441 node_clear(nid, *node_alloc_noretry);
1442
1443 /*
1444 * If we tried hard to get a page but failed, set bit so that
1445 * subsequent attempts will not try as hard until there is an
1446 * overall state change.
1447 */
1448 if (node_alloc_noretry && !page && alloc_try_hard)
1449 node_set(nid, *node_alloc_noretry);
1450
1422 return page; 1451 return page;
1423} 1452}
1424 1453
@@ -1427,7 +1456,8 @@ static struct page *alloc_buddy_huge_page(struct hstate *h,
1427 * should use this function to get new hugetlb pages 1456 * should use this function to get new hugetlb pages
1428 */ 1457 */
1429static struct page *alloc_fresh_huge_page(struct hstate *h, 1458static struct page *alloc_fresh_huge_page(struct hstate *h,
1430 gfp_t gfp_mask, int nid, nodemask_t *nmask) 1459 gfp_t gfp_mask, int nid, nodemask_t *nmask,
1460 nodemask_t *node_alloc_noretry)
1431{ 1461{
1432 struct page *page; 1462 struct page *page;
1433 1463
@@ -1435,7 +1465,7 @@ static struct page *alloc_fresh_huge_page(struct hstate *h,
1435 page = alloc_gigantic_page(h, gfp_mask, nid, nmask); 1465 page = alloc_gigantic_page(h, gfp_mask, nid, nmask);
1436 else 1466 else
1437 page = alloc_buddy_huge_page(h, gfp_mask, 1467 page = alloc_buddy_huge_page(h, gfp_mask,
1438 nid, nmask); 1468 nid, nmask, node_alloc_noretry);
1439 if (!page) 1469 if (!page)
1440 return NULL; 1470 return NULL;
1441 1471
@@ -1450,14 +1480,16 @@ static struct page *alloc_fresh_huge_page(struct hstate *h,
1450 * Allocates a fresh page to the hugetlb allocator pool in the node interleaved 1480 * Allocates a fresh page to the hugetlb allocator pool in the node interleaved
1451 * manner. 1481 * manner.
1452 */ 1482 */
1453static int alloc_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed) 1483static int alloc_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed,
1484 nodemask_t *node_alloc_noretry)
1454{ 1485{
1455 struct page *page; 1486 struct page *page;
1456 int nr_nodes, node; 1487 int nr_nodes, node;
1457 gfp_t gfp_mask = htlb_alloc_mask(h) | __GFP_THISNODE; 1488 gfp_t gfp_mask = htlb_alloc_mask(h) | __GFP_THISNODE;
1458 1489
1459 for_each_node_mask_to_alloc(h, nr_nodes, node, nodes_allowed) { 1490 for_each_node_mask_to_alloc(h, nr_nodes, node, nodes_allowed) {
1460 page = alloc_fresh_huge_page(h, gfp_mask, node, nodes_allowed); 1491 page = alloc_fresh_huge_page(h, gfp_mask, node, nodes_allowed,
1492 node_alloc_noretry);
1461 if (page) 1493 if (page)
1462 break; 1494 break;
1463 } 1495 }
@@ -1601,7 +1633,7 @@ static struct page *alloc_surplus_huge_page(struct hstate *h, gfp_t gfp_mask,
1601 goto out_unlock; 1633 goto out_unlock;
1602 spin_unlock(&hugetlb_lock); 1634 spin_unlock(&hugetlb_lock);
1603 1635
1604 page = alloc_fresh_huge_page(h, gfp_mask, nid, nmask); 1636 page = alloc_fresh_huge_page(h, gfp_mask, nid, nmask, NULL);
1605 if (!page) 1637 if (!page)
1606 return NULL; 1638 return NULL;
1607 1639
@@ -1637,7 +1669,7 @@ struct page *alloc_migrate_huge_page(struct hstate *h, gfp_t gfp_mask,
1637 if (hstate_is_gigantic(h)) 1669 if (hstate_is_gigantic(h))
1638 return NULL; 1670 return NULL;
1639 1671
1640 page = alloc_fresh_huge_page(h, gfp_mask, nid, nmask); 1672 page = alloc_fresh_huge_page(h, gfp_mask, nid, nmask, NULL);
1641 if (!page) 1673 if (!page)
1642 return NULL; 1674 return NULL;
1643 1675
@@ -2207,13 +2239,33 @@ static void __init gather_bootmem_prealloc(void)
2207static void __init hugetlb_hstate_alloc_pages(struct hstate *h) 2239static void __init hugetlb_hstate_alloc_pages(struct hstate *h)
2208{ 2240{
2209 unsigned long i; 2241 unsigned long i;
2242 nodemask_t *node_alloc_noretry;
2243
2244 if (!hstate_is_gigantic(h)) {
2245 /*
2246 * Bit mask controlling how hard we retry per-node allocations.
2247 * Ignore errors as lower level routines can deal with
2248 * node_alloc_noretry == NULL. If this kmalloc fails at boot
2249 * time, we are likely in bigger trouble.
2250 */
2251 node_alloc_noretry = kmalloc(sizeof(*node_alloc_noretry),
2252 GFP_KERNEL);
2253 } else {
2254 /* allocations done at boot time */
2255 node_alloc_noretry = NULL;
2256 }
2257
2258 /* bit mask controlling how hard we retry per-node allocations */
2259 if (node_alloc_noretry)
2260 nodes_clear(*node_alloc_noretry);
2210 2261
2211 for (i = 0; i < h->max_huge_pages; ++i) { 2262 for (i = 0; i < h->max_huge_pages; ++i) {
2212 if (hstate_is_gigantic(h)) { 2263 if (hstate_is_gigantic(h)) {
2213 if (!alloc_bootmem_huge_page(h)) 2264 if (!alloc_bootmem_huge_page(h))
2214 break; 2265 break;
2215 } else if (!alloc_pool_huge_page(h, 2266 } else if (!alloc_pool_huge_page(h,
2216 &node_states[N_MEMORY])) 2267 &node_states[N_MEMORY],
2268 node_alloc_noretry))
2217 break; 2269 break;
2218 cond_resched(); 2270 cond_resched();
2219 } 2271 }
@@ -2225,6 +2277,8 @@ static void __init hugetlb_hstate_alloc_pages(struct hstate *h)
2225 h->max_huge_pages, buf, i); 2277 h->max_huge_pages, buf, i);
2226 h->max_huge_pages = i; 2278 h->max_huge_pages = i;
2227 } 2279 }
2280
2281 kfree(node_alloc_noretry);
2228} 2282}
2229 2283
2230static void __init hugetlb_init_hstates(void) 2284static void __init hugetlb_init_hstates(void)
@@ -2323,6 +2377,17 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid,
2323 nodemask_t *nodes_allowed) 2377 nodemask_t *nodes_allowed)
2324{ 2378{
2325 unsigned long min_count, ret; 2379 unsigned long min_count, ret;
2380 NODEMASK_ALLOC(nodemask_t, node_alloc_noretry, GFP_KERNEL);
2381
2382 /*
2383 * Bit mask controlling how hard we retry per-node allocations.
2384 * If we can not allocate the bit mask, do not attempt to allocate
2385 * the requested huge pages.
2386 */
2387 if (node_alloc_noretry)
2388 nodes_clear(*node_alloc_noretry);
2389 else
2390 return -ENOMEM;
2326 2391
2327 spin_lock(&hugetlb_lock); 2392 spin_lock(&hugetlb_lock);
2328 2393
@@ -2356,6 +2421,7 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid,
2356 if (hstate_is_gigantic(h) && !IS_ENABLED(CONFIG_CONTIG_ALLOC)) { 2421 if (hstate_is_gigantic(h) && !IS_ENABLED(CONFIG_CONTIG_ALLOC)) {
2357 if (count > persistent_huge_pages(h)) { 2422 if (count > persistent_huge_pages(h)) {
2358 spin_unlock(&hugetlb_lock); 2423 spin_unlock(&hugetlb_lock);
2424 NODEMASK_FREE(node_alloc_noretry);
2359 return -EINVAL; 2425 return -EINVAL;
2360 } 2426 }
2361 /* Fall through to decrease pool */ 2427 /* Fall through to decrease pool */
@@ -2388,7 +2454,8 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid,
2388 /* yield cpu to avoid soft lockup */ 2454 /* yield cpu to avoid soft lockup */
2389 cond_resched(); 2455 cond_resched();
2390 2456
2391 ret = alloc_pool_huge_page(h, nodes_allowed); 2457 ret = alloc_pool_huge_page(h, nodes_allowed,
2458 node_alloc_noretry);
2392 spin_lock(&hugetlb_lock); 2459 spin_lock(&hugetlb_lock);
2393 if (!ret) 2460 if (!ret)
2394 goto out; 2461 goto out;
@@ -2429,6 +2496,8 @@ out:
2429 h->max_huge_pages = persistent_huge_pages(h); 2496 h->max_huge_pages = persistent_huge_pages(h);
2430 spin_unlock(&hugetlb_lock); 2497 spin_unlock(&hugetlb_lock);
2431 2498
2499 NODEMASK_FREE(node_alloc_noretry);
2500
2432 return 0; 2501 return 0;
2433} 2502}
2434 2503