Presently, when calculating how many huge pages are needed when reserving surplus huge pages, the global count of free huge pages are used. When reserving with a mempolicy, the global count of free huge pages is used even if some/all of those free huge pages are on numa nodes outside of the mempolicy. Fix it so free huge pages only on nodes within the mempolicy are considered. Signed-off-by: Charles Haithcock --- mm/hugetlb.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index f24bf49be0..02752ce735 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2255,6 +2255,23 @@ static nodemask_t *policy_mbind_nodemask(gfp_t gfp) return NULL; } +static unsigned int allowed_mems_nr(struct hstate *h) +{ + int node; + unsigned int nr = 0; + nodemask_t *mbind_nodemask; + unsigned int *array = h->free_huge_pages_node; + gfp_t gfp_mask = htlb_alloc_mask(h); + + mbind_nodemask = policy_mbind_nodemask(gfp_mask); + for_each_node_mask(node, cpuset_current_mems_allowed) { + if (!mbind_nodemask || node_isset(node, *mbind_nodemask)) + nr += array[node]; + } + + return nr; +} + /* * Increase the hugetlb pool such that it can accommodate a reservation * of size 'delta'. @@ -2277,7 +2294,7 @@ static int gather_surplus_pages(struct hstate *h, long delta) alloc_nodemask = cpuset_current_mems_allowed; lockdep_assert_held(&hugetlb_lock); - needed = (h->resv_huge_pages + delta) - h->free_huge_pages; + needed = (h->resv_huge_pages + delta) - allowed_mems_nr(h); if (needed <= 0) { h->resv_huge_pages += delta; return 0; @@ -2312,7 +2329,7 @@ static int gather_surplus_pages(struct hstate *h, long delta) */ spin_lock_irq(&hugetlb_lock); needed = (h->resv_huge_pages + delta) - - (h->free_huge_pages + allocated); + (allowed_mems_nr(h) + allocated); if (needed > 0) { if (alloc_ok) goto retry; @@ -4513,23 +4530,6 @@ static int __init hugepage_alloc_threads_setup(char *s) } __setup("hugepage_alloc_threads=", hugepage_alloc_threads_setup); -static unsigned int allowed_mems_nr(struct hstate *h) -{ - int node; - unsigned int nr = 0; - nodemask_t *mbind_nodemask; - unsigned int *array = h->free_huge_pages_node; - gfp_t gfp_mask = htlb_alloc_mask(h); - - mbind_nodemask = policy_mbind_nodemask(gfp_mask); - for_each_node_mask(node, cpuset_current_mems_allowed) { - if (!mbind_nodemask || node_isset(node, *mbind_nodemask)) - nr += array[node]; - } - - return nr; -} - void hugetlb_report_meminfo(struct seq_file *m) { struct hstate *h; -- 2.54.0