lkml.org 
[lkml]   [2020]   [Mar]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[RFC PATCH 3/3] android: ion: include system heap size in proc/meminfo
    Date
    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(+)

    diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
    index 38b51eace4f9..76db91a9f26a 100644
    --- a/drivers/staging/android/ion/ion.c
    +++ b/drivers/staging/android/ion/ion.c
    @@ -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);
    }
    diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h
    index 74914a266e25..10867a2e5728 100644
    --- a/drivers/staging/android/ion/ion.h
    +++ b/drivers/staging/android/ion/ion.h
    @@ -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;
    diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
    index b83a1d16bd89..2cc568e2bc9c 100644
    --- a/drivers/staging/android/ion/ion_system_heap.c
    +++ b/drivers/staging/android/ion/ion_system_heap.c
    @@ -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:
    --
    2.13.7
    \
     
     \ /
      Last update: 2020-03-11 04:45    [W:3.597 / U:0.004 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site