From c8c45c29b5e2b14e7583944fc26824e913237987 Mon Sep 17 00:00:00 2001 From: Cho KyongHo Date: Wed, 21 Feb 2018 18:28:52 +0900 Subject: [PATCH] android: ion: add show all buffers of contig heaps ION heaps of physically contiguous memory pool is vulnerable to memory external fragmentations. If an allocation from such heaps has failed, ION just returns 'out of memory' error. But users need to know if the error is caused by insufficient free space or fragmentations. Their actions to the error should be different according to the reason. Therefore ION ought to tell the users the list of allocated buffers from the physically contiguous heaps. Change-Id: I0ea0dd81cfac8f8b019a763480f5c7af22b8eac0 Signed-off-by: Cho KyongHo --- drivers/staging/android/ion/ion.h | 3 ++ .../staging/android/ion/ion_carveout_heap.c | 2 ++ drivers/staging/android/ion/ion_cma_heap.c | 3 ++ drivers/staging/android/ion/ion_heap.c | 30 +++++++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index d962dd3d1afe..114a6efccb56 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -362,4 +362,7 @@ long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); int ion_query_heaps(struct ion_heap_query *query); +void ion_contig_heap_show_buffers(struct ion_heap *heap, + phys_addr_t base, size_t pool_size); + #endif /* _ION_H */ diff --git a/drivers/staging/android/ion/ion_carveout_heap.c b/drivers/staging/android/ion/ion_carveout_heap.c index 8182f037ceb2..60384f8974e9 100644 --- a/drivers/staging/android/ion/ion_carveout_heap.c +++ b/drivers/staging/android/ion/ion_carveout_heap.c @@ -116,6 +116,8 @@ err_free_table: sg_free_table(table); err_free: kfree(table); + ion_contig_heap_show_buffers(&carveout_heap->heap, + carveout_heap->base, carveout_heap->size); return ret; } diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c index 82361db6fe66..12a02455b99d 100644 --- a/drivers/staging/android/ion/ion_cma_heap.c +++ b/drivers/staging/android/ion/ion_cma_heap.c @@ -113,6 +113,9 @@ free_mem: kfree(table); err: cma_release(cma_heap->cma, pages, nr_pages); + ion_contig_heap_show_buffers(&cma_heap->heap, + cma_get_base(cma_heap->cma), + cma_get_size(cma_heap->cma)); return ret; } diff --git a/drivers/staging/android/ion/ion_heap.c b/drivers/staging/android/ion/ion_heap.c index 1f73ad7bef1a..8515670ad10f 100644 --- a/drivers/staging/android/ion/ion_heap.c +++ b/drivers/staging/android/ion/ion_heap.c @@ -316,3 +316,33 @@ void ion_heap_init_shrinker(struct ion_heap *heap) heap->shrinker.batch = 0; register_shrinker(&heap->shrinker); } + +void ion_contig_heap_show_buffers(struct ion_heap *heap, + phys_addr_t base, size_t pool_size) +{ + size_t total_size = 0; + struct rb_node *n; + + if (heap->type != ION_HEAP_TYPE_CARVEOUT && + heap->type != ION_HEAP_TYPE_DMA) + return; + + pr_info("ION heap '%s' of type %u and id %u, size %zu bytes\n", + heap->name, heap->type, heap->id, pool_size); + pr_info("List of buffers --------------------------------\n"); + mutex_lock(&heap->dev->buffer_lock); + for (n = rb_first(&heap->dev->buffers); n; n = rb_next(n)) { + struct ion_buffer *buffer = rb_entry(n, struct ion_buffer, + node); + unsigned long offset; + + if (buffer->heap != heap) + continue; + + offset = (unsigned long)(sg_phys(buffer->sg_table->sgl) - base); + pr_info(" OFFSET %#010lx SIZE %zu\n", offset, buffer->size); + total_size += buffer->size; + } + mutex_unlock(&heap->dev->buffer_lock); + pr_info("Total allocated size: %zu bytes --------------\n", total_size); +} -- 2.20.1