Skip to content

Commit 41b4dc1

Browse files
JoonsooKimtorvalds
authored andcommitted
mm/gup: restrict CMA region by using allocation scope API
We have well defined scope API to exclude CMA region. Use it rather than manipulating gfp_mask manually. With this change, we can now restore __GFP_MOVABLE for gfp_mask like as usual migration target allocation. It would result in that the ZONE_MOVABLE is also searched by page allocator. For hugetlb, gfp_mask is redefined since it has a regular allocation mask filter for migration target. __GPF_NOWARN is added to hugetlb gfp_mask filter since a new user for gfp_mask filter, gup, want to be silent when allocation fails. Note that this can be considered as a fix for the commit 9a4e9f3 ("mm: update get_user_pages_longterm to migrate pages allocated from CMA region"). However, "Fixes" tag isn't added here since it is just suboptimal but it doesn't cause any problem. Suggested-by: Michal Hocko <[email protected]> Signed-off-by: Joonsoo Kim <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Roman Gushchin <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: Naoya Horiguchi <[email protected]> Cc: "Aneesh Kumar K . V" <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 8b94e0b commit 41b4dc1

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

include/linux/hugetlb.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,8 @@ static inline gfp_t htlb_modify_alloc_mask(struct hstate *h, gfp_t gfp_mask)
710710
/* Some callers might want to enforce node */
711711
modified_mask |= (gfp_mask & __GFP_THISNODE);
712712

713+
modified_mask |= (gfp_mask & __GFP_NOWARN);
714+
713715
return modified_mask;
714716
}
715717

mm/gup.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,17 +1620,21 @@ static struct page *new_non_cma_page(struct page *page, unsigned long private)
16201620
* Trying to allocate a page for migration. Ignore allocation
16211621
* failure warnings. We don't force __GFP_THISNODE here because
16221622
* this node here is the node where we have CMA reservation and
1623-
* in some case these nodes will have really less non movable
1623+
* in some case these nodes will have really less non CMA
16241624
* allocation memory.
1625+
*
1626+
* Note that CMA region is prohibited by allocation scope.
16251627
*/
1626-
gfp_t gfp_mask = GFP_USER | __GFP_NOWARN;
1628+
gfp_t gfp_mask = GFP_USER | __GFP_MOVABLE | __GFP_NOWARN;
16271629

16281630
if (PageHighMem(page))
16291631
gfp_mask |= __GFP_HIGHMEM;
16301632

16311633
#ifdef CONFIG_HUGETLB_PAGE
16321634
if (PageHuge(page)) {
16331635
struct hstate *h = page_hstate(page);
1636+
1637+
gfp_mask = htlb_modify_alloc_mask(h, gfp_mask);
16341638
/*
16351639
* We don't want to dequeue from the pool because pool pages will
16361640
* mostly be from the CMA region.
@@ -1645,11 +1649,6 @@ static struct page *new_non_cma_page(struct page *page, unsigned long private)
16451649
*/
16461650
gfp_t thp_gfpmask = GFP_TRANSHUGE | __GFP_NOWARN;
16471651

1648-
/*
1649-
* Remove the movable mask so that we don't allocate from
1650-
* CMA area again.
1651-
*/
1652-
thp_gfpmask &= ~__GFP_MOVABLE;
16531652
thp = __alloc_pages_node(nid, thp_gfpmask, HPAGE_PMD_ORDER);
16541653
if (!thp)
16551654
return NULL;
@@ -1795,7 +1794,6 @@ static long __gup_longterm_locked(struct task_struct *tsk,
17951794
vmas_tmp, NULL, gup_flags);
17961795

17971796
if (gup_flags & FOLL_LONGTERM) {
1798-
memalloc_nocma_restore(flags);
17991797
if (rc < 0)
18001798
goto out;
18011799

@@ -1808,9 +1806,10 @@ static long __gup_longterm_locked(struct task_struct *tsk,
18081806

18091807
rc = check_and_migrate_cma_pages(tsk, mm, start, rc, pages,
18101808
vmas_tmp, gup_flags);
1809+
out:
1810+
memalloc_nocma_restore(flags);
18111811
}
18121812

1813-
out:
18141813
if (vmas_tmp != vmas)
18151814
kfree(vmas_tmp);
18161815
return rc;

0 commit comments

Comments
 (0)