Commit ca96b625 authored by Lucas Stach's avatar Lucas Stach Committed by Linus Torvalds

mm: alloc_contig_range: allow to specify GFP mask

Currently alloc_contig_range assumes that the compaction should be done
with the default GFP_KERNEL flags.  This is probably right for all
current uses of this interface, but may change as CMA is used in more
use-cases (including being the default DMA memory allocator on some

Change the function prototype, to allow for passing through the GFP mask
set by upper layers.

Also respect global restrictions by applying memalloc_noio_flags to the
passed in flags.

Link: default avatarLucas Stach <>
Acked-by: default avatarMichal Hocko <>
Acked-by: default avatarVlastimil Babka <>
Cc: Radim Krcmar <>
Cc: Catalin Marinas <>
Cc: Will Deacon <>
Cc: Chris Zankel <>
Cc: Ralf Baechle <>
Cc: Paolo Bonzini <>
Cc: Alexander Graf <>
Cc: Joonsoo Kim <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 5a02026d
......@@ -541,7 +541,7 @@ static inline bool pm_suspended_storage(void)
/* The below functions must be run on a range from a single zone. */
extern int alloc_contig_range(unsigned long start, unsigned long end,
unsigned migratetype);
unsigned migratetype, gfp_t gfp_mask);
extern void free_contig_range(unsigned long pfn, unsigned nr_pages);
......@@ -402,7 +402,8 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align)
pfn = cma->base_pfn + (bitmap_no << cma->order_per_bit);
ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA);
ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA,
if (ret == 0) {
page = pfn_to_page(pfn);
......@@ -1052,7 +1052,8 @@ static int __alloc_gigantic_page(unsigned long start_pfn,
unsigned long nr_pages)
unsigned long end_pfn = start_pfn + nr_pages;
return alloc_contig_range(start_pfn, end_pfn, MIGRATE_MOVABLE);
return alloc_contig_range(start_pfn, end_pfn, MIGRATE_MOVABLE,
static bool pfn_range_valid_gigantic(struct zone *z,
......@@ -7399,6 +7399,7 @@ static int __alloc_contig_migrate_range(struct compact_control *cc,
* #MIGRATE_MOVABLE or #MIGRATE_CMA). All pageblocks
* in range must have the same migratetype and it must
* be either of the two.
* @gfp_mask: GFP mask to use during compaction
* The PFN range does not have to be pageblock or MAX_ORDER_NR_PAGES
* aligned, however it's the caller's responsibility to guarantee that
......@@ -7412,7 +7413,7 @@ static int __alloc_contig_migrate_range(struct compact_control *cc,
* need to be freed with free_contig_range().
int alloc_contig_range(unsigned long start, unsigned long end,
unsigned migratetype)
unsigned migratetype, gfp_t gfp_mask)
unsigned long outer_start, outer_end;
unsigned int order;
......@@ -7424,7 +7425,7 @@ int alloc_contig_range(unsigned long start, unsigned long end,
.zone = page_zone(pfn_to_page(start)),
.ignore_skip_hint = true,
.gfp_mask = GFP_KERNEL,
.gfp_mask = memalloc_noio_flags(gfp_mask),
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment