Skip to content

Commit dbe43d4

Browse files
Jaewon31Kimtorvalds
authored andcommitted
mm: cma: print allocation failure reason and bitmap status
There are many reasons of CMA allocation failure such as EBUSY, ENOMEM, EINTR. But we did not know error reason so far. This patch prints the error value. Additionally if CONFIG_CMA_DEBUG is enabled, this patch shows bitmap status to know available pages. Actually CMA internally tries on all available regions because some regions can be failed because of EBUSY. Bitmap status is useful to know in detail on both ENONEM and EBUSY; ENOMEM: not tried at all because of no available region it could be too small total region or could be fragmentation issue EBUSY: tried some region but all failed This is an ENOMEM example with this patch. [2: Binder:714_1: 744] cma: cma_alloc: alloc failed, req-size: 256 pages, ret: -12 If CONFIG_CMA_DEBUG is enabled, avabile pages also will be shown as concatenated size@position format. So 4@572 means that there are 4 available pages at 572 position starting from 0 position. [2: Binder:714_1: 744] cma: number of available pages: 4@572+7@585+7@601+8@632+38@730+166@1114+127@1921=> 357 free of 2048 total pages Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Jaewon Kim <[email protected]> Acked-by: Michal Nazarewicz <[email protected]> Cc: Laura Abbott <[email protected]> Cc: Joonsoo Kim <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent def5efe commit dbe43d4

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

mm/cma.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,32 @@ int __init cma_declare_contiguous(phys_addr_t base,
348348
return ret;
349349
}
350350

351+
#ifdef CONFIG_CMA_DEBUG
352+
static void cma_debug_show_areas(struct cma *cma)
353+
{
354+
unsigned long next_zero_bit, next_set_bit;
355+
unsigned long start = 0;
356+
unsigned int nr_zero, nr_total = 0;
357+
358+
mutex_lock(&cma->lock);
359+
pr_info("number of available pages: ");
360+
for (;;) {
361+
next_zero_bit = find_next_zero_bit(cma->bitmap, cma->count, start);
362+
if (next_zero_bit >= cma->count)
363+
break;
364+
next_set_bit = find_next_bit(cma->bitmap, cma->count, next_zero_bit);
365+
nr_zero = next_set_bit - next_zero_bit;
366+
pr_cont("%s%u@%lu", nr_total ? "+" : "", nr_zero, next_zero_bit);
367+
nr_total += nr_zero;
368+
start = next_zero_bit + nr_zero;
369+
}
370+
pr_cont("=> %u free of %lu total pages\n", nr_total, cma->count);
371+
mutex_unlock(&cma->lock);
372+
}
373+
#else
374+
static inline void cma_debug_show_areas(struct cma *cma) { }
375+
#endif
376+
351377
/**
352378
* cma_alloc() - allocate pages from contiguous area
353379
* @cma: Contiguous memory region for which the allocation is performed.
@@ -365,7 +391,7 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align,
365391
unsigned long start = 0;
366392
unsigned long bitmap_maxno, bitmap_no, bitmap_count;
367393
struct page *page = NULL;
368-
int ret;
394+
int ret = -ENOMEM;
369395

370396
if (!cma || !cma->count)
371397
return NULL;
@@ -423,6 +449,12 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align,
423449

424450
trace_cma_alloc(pfn, page, count, align);
425451

452+
if (ret) {
453+
pr_info("%s: alloc failed, req-size: %zu pages, ret: %d\n",
454+
__func__, count, ret);
455+
cma_debug_show_areas(cma);
456+
}
457+
426458
pr_debug("%s(): returned %p\n", __func__, page);
427459
return page;
428460
}

0 commit comments

Comments
 (0)