Skip to content

Commit d92bbc2

Browse files
JoonsooKimtorvalds
authored andcommitted
mm/hugetlb: unify migration callbacks
There is no difference between two migration callback functions, alloc_huge_page_node() and alloc_huge_page_nodemask(), except __GFP_THISNODE handling. It's redundant to have two almost similar functions in order to handle this flag. So, this patch tries to remove one by introducing a new argument, gfp_mask, to alloc_huge_page_nodemask(). After introducing gfp_mask argument, it's caller's job to provide correct gfp_mask. So, every callsites for alloc_huge_page_nodemask() are changed to provide gfp_mask. Note that it's safe to remove a node id check in alloc_huge_page_node() since there is no caller passing NUMA_NO_NODE as a node id. Signed-off-by: Joonsoo Kim <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Reviewed-by: Mike Kravetz <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Acked-by: Michal Hocko <[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 b4b3822 commit d92bbc2

File tree

4 files changed

+33
-49
lines changed

4 files changed

+33
-49
lines changed

include/linux/hugetlb.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/list.h>
1111
#include <linux/kref.h>
1212
#include <linux/pgtable.h>
13+
#include <linux/gfp.h>
1314

1415
struct ctl_table;
1516
struct user_struct;
@@ -506,9 +507,8 @@ struct huge_bootmem_page {
506507

507508
struct page *alloc_huge_page(struct vm_area_struct *vma,
508509
unsigned long addr, int avoid_reserve);
509-
struct page *alloc_huge_page_node(struct hstate *h, int nid);
510510
struct page *alloc_huge_page_nodemask(struct hstate *h, int preferred_nid,
511-
nodemask_t *nmask);
511+
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);
514514
struct page *alloc_migrate_huge_page(struct hstate *h, gfp_t gfp_mask,
@@ -694,6 +694,15 @@ static inline bool hugepage_movable_supported(struct hstate *h)
694694
return true;
695695
}
696696

697+
/* Movability of hugepages depends on migration support. */
698+
static inline gfp_t htlb_alloc_mask(struct hstate *h)
699+
{
700+
if (hugepage_movable_supported(h))
701+
return GFP_HIGHUSER_MOVABLE;
702+
else
703+
return GFP_HIGHUSER;
704+
}
705+
697706
static inline spinlock_t *huge_pte_lockptr(struct hstate *h,
698707
struct mm_struct *mm, pte_t *pte)
699708
{
@@ -761,13 +770,9 @@ static inline struct page *alloc_huge_page(struct vm_area_struct *vma,
761770
return NULL;
762771
}
763772

764-
static inline struct page *alloc_huge_page_node(struct hstate *h, int nid)
765-
{
766-
return NULL;
767-
}
768-
769773
static inline struct page *
770-
alloc_huge_page_nodemask(struct hstate *h, int preferred_nid, nodemask_t *nmask)
774+
alloc_huge_page_nodemask(struct hstate *h, int preferred_nid,
775+
nodemask_t *nmask, gfp_t gfp_mask)
771776
{
772777
return NULL;
773778
}
@@ -880,6 +885,11 @@ static inline bool hugepage_movable_supported(struct hstate *h)
880885
return false;
881886
}
882887

888+
static inline gfp_t htlb_alloc_mask(struct hstate *h)
889+
{
890+
return 0;
891+
}
892+
883893
static inline spinlock_t *huge_pte_lockptr(struct hstate *h,
884894
struct mm_struct *mm, pte_t *pte)
885895
{

mm/hugetlb.c

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,15 +1093,6 @@ static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask,
10931093
return NULL;
10941094
}
10951095

1096-
/* Movability of hugepages depends on migration support. */
1097-
static inline gfp_t htlb_alloc_mask(struct hstate *h)
1098-
{
1099-
if (hugepage_movable_supported(h))
1100-
return GFP_HIGHUSER_MOVABLE;
1101-
else
1102-
return GFP_HIGHUSER;
1103-
}
1104-
11051096
static struct page *dequeue_huge_page_vma(struct hstate *h,
11061097
struct vm_area_struct *vma,
11071098
unsigned long address, int avoid_reserve,
@@ -1985,32 +1976,10 @@ struct page *alloc_buddy_huge_page_with_mpol(struct hstate *h,
19851976
return page;
19861977
}
19871978

1988-
/* page migration callback function */
1989-
struct page *alloc_huge_page_node(struct hstate *h, int nid)
1990-
{
1991-
gfp_t gfp_mask = htlb_alloc_mask(h);
1992-
struct page *page = NULL;
1993-
1994-
if (nid != NUMA_NO_NODE)
1995-
gfp_mask |= __GFP_THISNODE;
1996-
1997-
spin_lock(&hugetlb_lock);
1998-
if (h->free_huge_pages - h->resv_huge_pages > 0)
1999-
page = dequeue_huge_page_nodemask(h, gfp_mask, nid, NULL);
2000-
spin_unlock(&hugetlb_lock);
2001-
2002-
if (!page)
2003-
page = alloc_migrate_huge_page(h, gfp_mask, nid, NULL);
2004-
2005-
return page;
2006-
}
2007-
20081979
/* page migration callback function */
20091980
struct page *alloc_huge_page_nodemask(struct hstate *h, int preferred_nid,
2010-
nodemask_t *nmask)
1981+
nodemask_t *nmask, gfp_t gfp_mask)
20111982
{
2012-
gfp_t gfp_mask = htlb_alloc_mask(h);
2013-
20141983
spin_lock(&hugetlb_lock);
20151984
if (h->free_huge_pages - h->resv_huge_pages > 0) {
20161985
struct page *page;
@@ -2038,7 +2007,7 @@ struct page *alloc_huge_page_vma(struct hstate *h, struct vm_area_struct *vma,
20382007

20392008
gfp_mask = htlb_alloc_mask(h);
20402009
node = huge_node(vma, address, gfp_mask, &mpol, &nodemask);
2041-
page = alloc_huge_page_nodemask(h, node, nodemask);
2010+
page = alloc_huge_page_nodemask(h, node, nodemask, gfp_mask);
20422011
mpol_cond_put(mpol);
20432012

20442013
return page;

mm/mempolicy.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,10 +1068,12 @@ static int migrate_page_add(struct page *page, struct list_head *pagelist,
10681068
/* page allocation callback for NUMA node migration */
10691069
struct page *alloc_new_node_page(struct page *page, unsigned long node)
10701070
{
1071-
if (PageHuge(page))
1072-
return alloc_huge_page_node(page_hstate(compound_head(page)),
1073-
node);
1074-
else if (PageTransHuge(page)) {
1071+
if (PageHuge(page)) {
1072+
struct hstate *h = page_hstate(compound_head(page));
1073+
gfp_t gfp_mask = htlb_alloc_mask(h) | __GFP_THISNODE;
1074+
1075+
return alloc_huge_page_nodemask(h, node, NULL, gfp_mask);
1076+
} else if (PageTransHuge(page)) {
10751077
struct page *thp;
10761078

10771079
thp = alloc_pages_node(node,

mm/migrate.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,10 +1545,13 @@ struct page *new_page_nodemask(struct page *page,
15451545
unsigned int order = 0;
15461546
struct page *new_page = NULL;
15471547

1548-
if (PageHuge(page))
1549-
return alloc_huge_page_nodemask(
1550-
page_hstate(compound_head(page)),
1551-
preferred_nid, nodemask);
1548+
if (PageHuge(page)) {
1549+
struct hstate *h = page_hstate(compound_head(page));
1550+
1551+
gfp_mask = htlb_alloc_mask(h);
1552+
return alloc_huge_page_nodemask(h, preferred_nid,
1553+
nodemask, gfp_mask);
1554+
}
15521555

15531556
if (PageTransHuge(page)) {
15541557
gfp_mask |= GFP_TRANSHUGE;

0 commit comments

Comments
 (0)