@@ -74,6 +74,7 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
INIT_LIST_HEAD(&buffer->attachments);
mutex_init(&buffer->lock);
+ atomic_long_add(len, &heap->total_allocated);
return buffer;
err1:
@@ -95,6 +96,7 @@ void ion_buffer_destroy(struct ion_buffer *buffer)
buffer->heap->num_of_buffers--;
buffer->heap->num_of_alloc_bytes -= buffer->size;
spin_unlock(&buffer->heap->stat_lock);
+ atomic_long_sub(buffer->size, &buffer->heap->total_allocated);
kfree(buffer);
}
@@ -157,6 +157,7 @@ struct ion_heap {
u64 num_of_buffers;
u64 num_of_alloc_bytes;
u64 alloc_bytes_wm;
+ atomic_long_t total_allocated;
/* protect heap statistics */
spinlock_t stat_lock;
@@ -259,6 +259,8 @@ static struct ion_heap *__ion_system_heap_create(void)
if (ion_system_heap_create_pools(heap->pools))
goto free_heap;
+ register_extra_meminfo(&heap->heap.total_allocated, PAGE_SHIFT,
+ "IonSystemHeap");
return &heap->heap;
free_heap:
In Android system ion system heap size is huge like hundreds of MB. To know overal system memory usage, include ion system heap size in proc/meminfo. To include heap size, use register_extra_meminfo introduced in previous patch. Prior to register we need to add stats to show the ion heap usage. Add total_allocated into ion heap and count it on allocation and freeing. In a ion heap using ION_HEAP_FLAG_DEFER_FREE, a buffer can be freed from user but still live on deferred free list. Keep stats until the buffer is finally freed so that we can cover situation of deferred free thread stuck problem. i.e) cat /proc/meminfo | grep IonSystemHeap IonSystemHeap: 242620 kB i.e.) show_mem on oom <6>[ 420.856428] Mem-Info: <6>[ 420.856433] IonSystemHeap:32813kB Signed-off-by: Jaewon Kim <jaewon31.kim@samsung.com> --- drivers/staging/android/ion/ion.c | 2 ++ drivers/staging/android/ion/ion.h | 1 + drivers/staging/android/ion/ion_system_heap.c | 2 ++ 3 files changed, 5 insertions(+)