android: ion: add show all buffers of contig heaps
authorCho KyongHo <pullip.cho@samsung.com>
Wed, 21 Feb 2018 09:28:52 +0000 (18:28 +0900)
committerSangwook Ju <sw.ju@samsung.com>
Mon, 14 May 2018 10:45:24 +0000 (19:45 +0900)
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 <pullip.cho@samsung.com>
drivers/staging/android/ion/ion.h
drivers/staging/android/ion/ion_carveout_heap.c
drivers/staging/android/ion/ion_cma_heap.c
drivers/staging/android/ion/ion_heap.c

index d962dd3d1afeaea5351db1d14eae886421969cb2..114a6efccb56a2bd79326e5bf57727c3ef282f07 100644 (file)
@@ -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 */
index 8182f037ceb242a561403bbe46c79f00755d59cc..60384f8974e9318c99d5c0893f4577a875b3f876 100644 (file)
@@ -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;
 }
 
index 82361db6fe669603adf45a7ff62edb992ab70c07..12a02455b99d0cd8f34cdd88f15ab1d2dc2b469a 100644 (file)
@@ -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;
 }
 
index 1f73ad7bef1a57b829bead7c75f7a5e069d8864b..8515670ad10f99ee53681cf1aa7c56f01440c8c8 100644 (file)
@@ -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);
+}