Re-work cma_range_alloc() so that two passes are performed; once with the new ACR_FLAGS_LAZY to try to get a successful allocation as quickly as possible, and if no free block is found a second pass without the flag to try the more likely to succeed but slower path. Signed-off-by: Daniel Scally --- mm/cma.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/mm/cma.c b/mm/cma.c index 0c97aadcfea4029411171dce3760d68de66047e0..22a9c203cafb9dab38ef4f1441442f99e4e7ba36 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -706,9 +706,10 @@ static void cma_debug_show_areas(struct cma *cma) spin_unlock_irq(&cma->lock); } -static int cma_range_alloc(struct cma *cma, struct cma_memrange *cmr, - unsigned long count, unsigned int align, - struct page **pagep, gfp_t gfp) +static int __cma_range_alloc(struct cma *cma, struct cma_memrange *cmr, + unsigned long count, unsigned int align, + struct page **pagep, gfp_t gfp, + acr_flags_t alloc_flags) { unsigned long bitmap_maxno, bitmap_no, bitmap_count; unsigned long start, pfn, mask, offset; @@ -766,7 +767,7 @@ static int cma_range_alloc(struct cma *cma, struct cma_memrange *cmr, spin_unlock_irq(&cma->lock); mutex_lock(&cma->alloc_mutex); - ret = alloc_contig_frozen_range(pfn, pfn + count, ACR_FLAGS_CMA, gfp); + ret = alloc_contig_frozen_range(pfn, pfn + count, alloc_flags, gfp); mutex_unlock(&cma->alloc_mutex); if (!ret) break; @@ -786,6 +787,21 @@ static int cma_range_alloc(struct cma *cma, struct cma_memrange *cmr, return ret; } +static int cma_range_alloc(struct cma *cma, struct cma_memrange *cmr, + unsigned long count, unsigned int align, + struct page **pagep, gfp_t gfp) +{ + int ret; + + ret = __cma_range_alloc(cma, cmr, count, align, pagep, gfp, + ACR_FLAGS_CMA | ACR_FLAGS_LAZY); + if (ret == -EBUSY) + ret = __cma_range_alloc(cma, cmr, count, align, pagep, gfp, + ACR_FLAGS_CMA); + + return ret; +} + static struct page *__cma_alloc_frozen(struct cma *cma, unsigned long count, unsigned int align, gfp_t gfp) { -- 2.43.0