Skip to content

Commit bbe8875

Browse files
JoonsooKimtorvalds
authored andcommitted
mm/hugetlb: make hugetlb migration callback CMA aware
new_non_cma_page() in gup.c requires to allocate the new page that is not on the CMA area. new_non_cma_page() implements it by using allocation scope APIs. However, there is a work-around for hugetlb. Normal hugetlb page allocation API for migration is alloc_huge_page_nodemask(). It consists of two steps. First is dequeing from the pool. Second is, if there is no available page on the queue, allocating by using the page allocator. new_non_cma_page() can't use this API since first step (deque) isn't aware of scope API to exclude CMA area. So, new_non_cma_page() exports hugetlb internal function for the second step, alloc_migrate_huge_page(), to global scope and uses it directly. This is suboptimal since hugetlb pages on the queue cannot be utilized. This patch tries to fix this situation by making the deque function on hugetlb CMA aware. In the deque function, CMA memory is skipped if PF_MEMALLOC_NOCMA flag is found. Signed-off-by: Joonsoo Kim <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Acked-by: Mike Kravetz <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: "Aneesh Kumar K . V" <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Naoya Horiguchi <[email protected]> Cc: Roman Gushchin <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 41b4dc1 commit bbe8875

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

include/linux/hugetlb.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,6 @@ struct page *alloc_huge_page_nodemask(struct hstate *h, int preferred_nid,
511511
nodemask_t *nmask, gfp_t gfp_mask);
512512
struct page *alloc_huge_page_vma(struct hstate *h, struct vm_area_struct *vma,
513513
unsigned long address);
514-
struct page *alloc_migrate_huge_page(struct hstate *h, gfp_t gfp_mask,
515-
int nid, nodemask_t *nmask);
516514
int huge_add_to_page_cache(struct page *page, struct address_space *mapping,
517515
pgoff_t idx);
518516

mm/gup.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,11 +1635,7 @@ static struct page *new_non_cma_page(struct page *page, unsigned long private)
16351635
struct hstate *h = page_hstate(page);
16361636

16371637
gfp_mask = htlb_modify_alloc_mask(h, gfp_mask);
1638-
/*
1639-
* We don't want to dequeue from the pool because pool pages will
1640-
* mostly be from the CMA region.
1641-
*/
1642-
return alloc_migrate_huge_page(h, gfp_mask, nid, NULL);
1638+
return alloc_huge_page_nodemask(h, nid, NULL, gfp_mask);
16431639
}
16441640
#endif
16451641
if (PageTransHuge(page)) {

mm/hugetlb.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/memblock.h>
2020
#include <linux/sysfs.h>
2121
#include <linux/slab.h>
22+
#include <linux/sched/mm.h>
2223
#include <linux/mmdebug.h>
2324
#include <linux/sched/signal.h>
2425
#include <linux/rmap.h>
@@ -1040,10 +1041,16 @@ static void enqueue_huge_page(struct hstate *h, struct page *page)
10401041
static struct page *dequeue_huge_page_node_exact(struct hstate *h, int nid)
10411042
{
10421043
struct page *page;
1044+
bool nocma = !!(current->flags & PF_MEMALLOC_NOCMA);
1045+
1046+
list_for_each_entry(page, &h->hugepage_freelists[nid], lru) {
1047+
if (nocma && is_migrate_cma_page(page))
1048+
continue;
10431049

1044-
list_for_each_entry(page, &h->hugepage_freelists[nid], lru)
10451050
if (!PageHWPoison(page))
10461051
break;
1052+
}
1053+
10471054
/*
10481055
* if 'non-isolated free hugepage' not found on the list,
10491056
* the allocation fails.
@@ -1935,7 +1942,7 @@ static struct page *alloc_surplus_huge_page(struct hstate *h, gfp_t gfp_mask,
19351942
return page;
19361943
}
19371944

1938-
struct page *alloc_migrate_huge_page(struct hstate *h, gfp_t gfp_mask,
1945+
static struct page *alloc_migrate_huge_page(struct hstate *h, gfp_t gfp_mask,
19391946
int nid, nodemask_t *nmask)
19401947
{
19411948
struct page *page;

0 commit comments

Comments
 (0)