Skip to content

Commit 4c54d94

Browse files
ftang1torvalds
authored andcommitted
mm/memplicy: add page allocation function for MPOL_PREFERRED_MANY policy
The semantics of MPOL_PREFERRED_MANY is similar to MPOL_PREFERRED, that it will first try to allocate memory from the preferred node(s), and fallback to all nodes in system when first try fails. Add a dedicated function alloc_pages_preferred_many() for it just like for 'interleave' policy, which will be used by 2 general memoory allocation APIs: alloc_pages() and alloc_pages_vma() Link: https://lore.kernel.org/r/20200630212517.308045-9-ben.widawsky@intel.com Link: https://lkml.kernel.org/r/1627970362-61305-3-git-send-email-feng.tang@intel.com Suggested-by: Michal Hocko <mhocko@suse.com> Originally-by: Ben Widawsky <ben.widawsky@intel.com> Co-developed-by: Ben Widawsky <ben.widawsky@intel.com> Signed-off-by: Ben Widawsky <ben.widawsky@intel.com> Signed-off-by: Feng Tang <feng.tang@intel.com> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: David Rientjes <rientjes@google.com> Cc: Huang Ying <ying.huang@intel.com> Cc: Mel Gorman <mgorman@techsingularity.net> Cc: Michal Hocko <mhocko@kernel.org> Cc: Mike Kravetz <mike.kravetz@oracle.com> Cc: Randy Dunlap <rdunlap@infradead.org> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b27abac commit 4c54d94

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

mm/mempolicy.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,6 +2166,27 @@ static struct page *alloc_page_interleave(gfp_t gfp, unsigned order,
21662166
return page;
21672167
}
21682168

2169+
static struct page *alloc_pages_preferred_many(gfp_t gfp, unsigned int order,
2170+
int nid, struct mempolicy *pol)
2171+
{
2172+
struct page *page;
2173+
gfp_t preferred_gfp;
2174+
2175+
/*
2176+
* This is a two pass approach. The first pass will only try the
2177+
* preferred nodes but skip the direct reclaim and allow the
2178+
* allocation to fail, while the second pass will try all the
2179+
* nodes in system.
2180+
*/
2181+
preferred_gfp = gfp | __GFP_NOWARN;
2182+
preferred_gfp &= ~(__GFP_DIRECT_RECLAIM | __GFP_NOFAIL);
2183+
page = __alloc_pages(preferred_gfp, order, nid, &pol->nodes);
2184+
if (!page)
2185+
page = __alloc_pages(gfp, order, numa_node_id(), NULL);
2186+
2187+
return page;
2188+
}
2189+
21692190
/**
21702191
* alloc_pages_vma - Allocate a page for a VMA.
21712192
* @gfp: GFP flags.
@@ -2201,6 +2222,12 @@ struct page *alloc_pages_vma(gfp_t gfp, int order, struct vm_area_struct *vma,
22012222
goto out;
22022223
}
22032224

2225+
if (pol->mode == MPOL_PREFERRED_MANY) {
2226+
page = alloc_pages_preferred_many(gfp, order, node, pol);
2227+
mpol_cond_put(pol);
2228+
goto out;
2229+
}
2230+
22042231
if (unlikely(IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && hugepage)) {
22052232
int hpage_node = node;
22062233

@@ -2278,6 +2305,9 @@ struct page *alloc_pages(gfp_t gfp, unsigned order)
22782305
*/
22792306
if (pol->mode == MPOL_INTERLEAVE)
22802307
page = alloc_page_interleave(gfp, order, interleave_nodes(pol));
2308+
else if (pol->mode == MPOL_PREFERRED_MANY)
2309+
page = alloc_pages_preferred_many(gfp, order,
2310+
numa_node_id(), pol);
22812311
else
22822312
page = __alloc_pages(gfp, order,
22832313
policy_node(gfp, pol, numa_node_id()),

0 commit comments

Comments
 (0)