[RAMEN9610-9924] android: ion: add limit to page pool of systemheap
authorCho KyongHo <pullip.cho@samsung.com>
Wed, 26 Dec 2018 06:17:13 +0000 (15:17 +0900)
committerhskang <hs1218.kang@samsung.com>
Wed, 26 Dec 2018 07:12:11 +0000 (16:12 +0900)
Users may want to restrict the number of free pages in the page pool
because it causes memory profiling and tuning hard.

Change-Id: I154ffa5eb176b0dc2bad0b3eb5c5747cde3a0bd5
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
drivers/staging/android/ion/ion.h
drivers/staging/android/ion/ion_page_pool.c
drivers/staging/android/ion/ion_system_heap.c

index cd34c9cecc6cb99c51777a24f95de7fbeccdf76f..f439413a80ec5d7e9ffbc67ed0c1b48139afea8d 100644 (file)
@@ -348,6 +348,7 @@ struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order,
 void ion_page_pool_destroy(struct ion_page_pool *pool);
 struct page *ion_page_pool_alloc(struct ion_page_pool *pool, bool nozero);
 void ion_page_pool_free(struct ion_page_pool *pool, struct page *page);
+int ion_page_pool_total(struct ion_page_pool *pool, bool high);
 
 /** ion_page_pool_shrink - shrinks the size of the memory cached in the pool
  * @pool:              the pool
index 75997d653fab196d7221c4d24e16ee2fa853d31e..68e7efd3717d0bceba7edb6eda4e48741d015bec 100644 (file)
@@ -117,7 +117,7 @@ void ion_page_pool_free(struct ion_page_pool *pool, struct page *page)
                ion_page_pool_free_pages(pool, page);
 }
 
-static int ion_page_pool_total(struct ion_page_pool *pool, bool high)
+int ion_page_pool_total(struct ion_page_pool *pool, bool high)
 {
        int count = pool->low_count;
 
index 7caad6ee5fc6d6c8d143bd62fe18c1be928f3ec5..097648b634c8ceb54d58fbaa881cfa46b0df14c0 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
+#include <linux/module.h>
 #include "ion.h"
 
 #define NUM_ORDERS ARRAY_SIZE(orders)
@@ -183,6 +184,9 @@ free_pages:
        return -ENOMEM;
 }
 
+static int max_page_pool_size = INT_MAX;
+module_param(max_page_pool_size, int, 0600);
+
 static void ion_system_heap_free(struct ion_buffer *buffer)
 {
        struct ion_system_heap *sys_heap = container_of(buffer->heap,
@@ -190,8 +194,17 @@ static void ion_system_heap_free(struct ion_buffer *buffer)
                                                        heap);
        struct sg_table *table = buffer->sg_table;
        struct scatterlist *sg;
+       unsigned int count = 0;
        int i;
 
+       for (i = 0; i < NUM_ORDERS; i++) {
+               count += ion_page_pool_total(sys_heap->cached_pools[i], true);
+               count += ion_page_pool_total(sys_heap->uncached_pools[i], true);
+       }
+
+       if (count > max_page_pool_size)
+               buffer->private_flags |= ION_PRIV_FLAG_SHRINKER_FREE;
+
        /* zero the buffer before goto page pool */
        if (!(buffer->private_flags & ION_PRIV_FLAG_SHRINKER_FREE))
                ion_heap_buffer_zero(buffer);