* [PATCH 1/3] staging: ion: shrink page-pool by page unit
2014-10-28 0:36 [PATCH 0/3] enable pool shrinking in page unit Gioh Kim
@ 2014-10-28 0:36 ` Gioh Kim
2014-10-29 0:51 ` Gioh Kim
2014-10-28 0:36 ` [PATCH 2/3] staging: ion: debugfs to shrink pool Gioh Kim
2014-10-28 0:36 ` [PATCH 3/3] staging: ion: limit pool size Gioh Kim
2 siblings, 1 reply; 5+ messages in thread
From: Gioh Kim @ 2014-10-28 0:36 UTC (permalink / raw)
To: gregkh, john.stultz, rebecca, lauraa, dan.carpenter
Cc: devel, linux-kernel, gunho.lee, gioh.kim
This patch shrink page-pool by page unit.
Shrinker usually get the pool size with the pool-scanner
and pass the size to the pool-counter to shrink entire pool.
But the pool-scanner is working in block unit.
and pool-counter page unit.
So it is confused.
Signed-off-by: Gioh Kim <gioh.kim@lge.com>
---
drivers/staging/android/ion/ion_page_pool.c | 5 +++--
drivers/staging/android/ion/ion_system_heap.c | 7 +++++--
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/android/ion/ion_page_pool.c b/drivers/staging/android/ion/ion_page_pool.c
index 5864f3d..165152f 100644
--- a/drivers/staging/android/ion/ion_page_pool.c
+++ b/drivers/staging/android/ion/ion_page_pool.c
@@ -116,7 +116,7 @@ static int ion_page_pool_total(struct ion_page_pool *pool, bool high)
int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask,
int nr_to_scan)
{
- int freed;
+ int freed = 0;
bool high;
if (current_is_kswapd())
@@ -127,7 +127,7 @@ int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask,
if (nr_to_scan == 0)
return ion_page_pool_total(pool, high);
- for (freed = 0; freed < nr_to_scan; freed++) {
+ while (freed <= nr_to_scan) {
struct page *page;
mutex_lock(&pool->mutex);
@@ -141,6 +141,7 @@ int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask,
}
mutex_unlock(&pool->mutex);
ion_page_pool_free_pages(pool, page);
+ freed += (1 << pool->order);
}
return freed;
diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
index da2a63c..91d862f 100644
--- a/drivers/staging/android/ion/ion_system_heap.c
+++ b/drivers/staging/android/ion/ion_system_heap.c
@@ -211,7 +211,7 @@ static int ion_system_heap_shrink(struct ion_heap *heap, gfp_t gfp_mask,
int nr_to_scan)
{
struct ion_system_heap *sys_heap;
- int nr_total = 0;
+ int nr_total = 0, nr_freed;
int i;
sys_heap = container_of(heap, struct ion_system_heap, heap);
@@ -219,7 +219,10 @@ static int ion_system_heap_shrink(struct ion_heap *heap, gfp_t gfp_mask,
for (i = 0; i < num_orders; i++) {
struct ion_page_pool *pool = sys_heap->pools[i];
- nr_total += ion_page_pool_shrink(pool, gfp_mask, nr_to_scan);
+ nr_freed = ion_page_pool_shrink(pool, gfp_mask, nr_to_scan);
+ nr_total += nr_freed;
+ /* nr_to_scan can be negative */
+ nr_to_scan -= nr_freed;
}
return nr_total;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 1/3] staging: ion: shrink page-pool by page unit
2014-10-28 0:36 ` [PATCH 1/3] staging: ion: shrink page-pool by " Gioh Kim
@ 2014-10-29 0:51 ` Gioh Kim
0 siblings, 0 replies; 5+ messages in thread
From: Gioh Kim @ 2014-10-29 0:51 UTC (permalink / raw)
To: gregkh, john.stultz, rebecca, lauraa, dan.carpenter
Cc: devel, linux-kernel, gunho.lee
2014-10-28 오전 9:36에 Gioh Kim 이(가) 쓴 글:
> This patch shrink page-pool by page unit.
>
> Shrinker usually get the pool size with the pool-scanner
> and pass the size to the pool-counter to shrink entire pool.
> But the pool-scanner is working in block unit.
> and pool-counter page unit.
> So it is confused.
>
> Signed-off-by: Gioh Kim <gioh.kim@lge.com>
> ---
> drivers/staging/android/ion/ion_page_pool.c | 5 +++--
> drivers/staging/android/ion/ion_system_heap.c | 7 +++++--
> 2 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/staging/android/ion/ion_page_pool.c b/drivers/staging/android/ion/ion_page_pool.c
> index 5864f3d..165152f 100644
> --- a/drivers/staging/android/ion/ion_page_pool.c
> +++ b/drivers/staging/android/ion/ion_page_pool.c
> @@ -116,7 +116,7 @@ static int ion_page_pool_total(struct ion_page_pool *pool, bool high)
> int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask,
> int nr_to_scan)
> {
> - int freed;
> + int freed = 0;
> bool high;
>
> if (current_is_kswapd())
> @@ -127,7 +127,7 @@ int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask,
> if (nr_to_scan == 0)
> return ion_page_pool_total(pool, high);
>
> - for (freed = 0; freed < nr_to_scan; freed++) {
> + while (freed <= nr_to_scan) {
> struct page *page;
>
> mutex_lock(&pool->mutex);
> @@ -141,6 +141,7 @@ int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask,
> }
> mutex_unlock(&pool->mutex);
> ion_page_pool_free_pages(pool, page);
> + freed += (1 << pool->order);
> }
>
> return freed;
> diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
> index da2a63c..91d862f 100644
> --- a/drivers/staging/android/ion/ion_system_heap.c
> +++ b/drivers/staging/android/ion/ion_system_heap.c
> @@ -211,7 +211,7 @@ static int ion_system_heap_shrink(struct ion_heap *heap, gfp_t gfp_mask,
> int nr_to_scan)
> {
> struct ion_system_heap *sys_heap;
> - int nr_total = 0;
> + int nr_total = 0, nr_freed;
> int i;
>
> sys_heap = container_of(heap, struct ion_system_heap, heap);
> @@ -219,7 +219,10 @@ static int ion_system_heap_shrink(struct ion_heap *heap, gfp_t gfp_mask,
> for (i = 0; i < num_orders; i++) {
> struct ion_page_pool *pool = sys_heap->pools[i];
>
> - nr_total += ion_page_pool_shrink(pool, gfp_mask, nr_to_scan);
> + nr_freed = ion_page_pool_shrink(pool, gfp_mask, nr_to_scan);
I found a mistake that if nr_to_scan is 0, this works wrong.
Please ignore this patch and I'm going to send v2.
> + nr_total += nr_freed;
> + /* nr_to_scan can be negative */
> + nr_to_scan -= nr_freed;
> }
>
> return nr_total;
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/3] staging: ion: debugfs to shrink pool
2014-10-28 0:36 [PATCH 0/3] enable pool shrinking in page unit Gioh Kim
2014-10-28 0:36 ` [PATCH 1/3] staging: ion: shrink page-pool by " Gioh Kim
@ 2014-10-28 0:36 ` Gioh Kim
2014-10-28 0:36 ` [PATCH 3/3] staging: ion: limit pool size Gioh Kim
2 siblings, 0 replies; 5+ messages in thread
From: Gioh Kim @ 2014-10-28 0:36 UTC (permalink / raw)
To: gregkh, john.stultz, rebecca, lauraa, dan.carpenter
Cc: devel, linux-kernel, gunho.lee, gioh.kim
This patch enables debugfs files /sys/kernel/debug/ion/heaps/system_shrink
,which was commented out, to shrink pool or get pool size
Reading the file returns pool size and writing occurs to shrink pool.
Signed-off-by: Gioh Kim <gioh.kim@lge.com>
---
drivers/staging/android/ion/ion.c | 31 ++++++++-----------------------
1 file changed, 8 insertions(+), 23 deletions(-)
diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
index 290d4d2..ecc1121 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -1463,43 +1463,29 @@ static const struct file_operations debug_heap_fops = {
.release = single_release,
};
-#ifdef DEBUG_HEAP_SHRINKER
static int debug_shrink_set(void *data, u64 val)
{
struct ion_heap *heap = data;
- struct shrink_control sc;
int objs;
- sc.gfp_mask = -1;
- sc.nr_to_scan = 0;
-
- if (!val)
- return 0;
-
- objs = heap->shrinker.shrink(&heap->shrinker, &sc);
- sc.nr_to_scan = objs;
+ if (val)
+ objs = val;
+ else
+ objs = heap->ops->shrink(heap, __GFP_HIGHMEM, 0);
- heap->shrinker.shrink(&heap->shrinker, &sc);
+ (void)heap->ops->shrink(heap, __GFP_HIGHMEM, objs);
return 0;
}
static int debug_shrink_get(void *data, u64 *val)
{
struct ion_heap *heap = data;
- struct shrink_control sc;
- int objs;
-
- sc.gfp_mask = -1;
- sc.nr_to_scan = 0;
-
- objs = heap->shrinker.shrink(&heap->shrinker, &sc);
- *val = objs;
+ *val = heap->ops->shrink(heap, __GFP_HIGHMEM, 0);
return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(debug_shrink_fops, debug_shrink_get,
debug_shrink_set, "%llu\n");
-#endif
void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap)
{
@@ -1534,8 +1520,7 @@ void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap)
path, heap->name);
}
-#ifdef DEBUG_HEAP_SHRINKER
- if (heap->shrinker.shrink) {
+ if (heap->ops->shrink) {
char debug_name[64];
snprintf(debug_name, 64, "%s_shrink", heap->name);
@@ -1550,7 +1535,7 @@ void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap)
path, debug_name);
}
}
-#endif
+
up_write(&dev->lock);
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 3/3] staging: ion: limit pool size
2014-10-28 0:36 [PATCH 0/3] enable pool shrinking in page unit Gioh Kim
2014-10-28 0:36 ` [PATCH 1/3] staging: ion: shrink page-pool by " Gioh Kim
2014-10-28 0:36 ` [PATCH 2/3] staging: ion: debugfs to shrink pool Gioh Kim
@ 2014-10-28 0:36 ` Gioh Kim
2 siblings, 0 replies; 5+ messages in thread
From: Gioh Kim @ 2014-10-28 0:36 UTC (permalink / raw)
To: gregkh, john.stultz, rebecca, lauraa, dan.carpenter
Cc: devel, linux-kernel, gunho.lee, gioh.kim
This patch limits pool size by page unit.
Signed-off-by: Gioh Kim <gioh.kim@lge.com>
---
drivers/staging/android/ion/Kconfig | 8 ++++++++
drivers/staging/android/ion/ion_page_pool.c | 24 ++++++++++++++----------
2 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/drivers/staging/android/ion/Kconfig b/drivers/staging/android/ion/Kconfig
index 3452346..06b4466 100644
--- a/drivers/staging/android/ion/Kconfig
+++ b/drivers/staging/android/ion/Kconfig
@@ -33,3 +33,11 @@ config ION_TEGRA
help
Choose this option if you wish to use ion on an nVidia Tegra.
+config ION_POOL_LIMIT
+ int "Limit count of pages in pool"
+ depends on ION
+ default "0"
+ help
+ Set the maximum number of pages the individual pool can have.
+ This doesn't care the total pages of all pools.
+ 0 means no limit.
diff --git a/drivers/staging/android/ion/ion_page_pool.c b/drivers/staging/android/ion/ion_page_pool.c
index 165152f..15d1ac8 100644
--- a/drivers/staging/android/ion/ion_page_pool.c
+++ b/drivers/staging/android/ion/ion_page_pool.c
@@ -22,6 +22,7 @@
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/swap.h>
+#include <linux/kconfig.h>
#include "ion_priv.h"
static void *ion_page_pool_alloc_pages(struct ion_page_pool *pool)
@@ -41,8 +42,21 @@ static void ion_page_pool_free_pages(struct ion_page_pool *pool,
__free_pages(page, pool->order);
}
+static int ion_page_pool_total(struct ion_page_pool *pool, bool high)
+{
+ int count = pool->low_count;
+
+ if (high)
+ count += pool->high_count;
+
+ return count << pool->order;
+}
+
static int ion_page_pool_add(struct ion_page_pool *pool, struct page *page)
{
+ if (CONFIG_ION_POOL_LIMIT && ion_page_pool_total(pool, 1) > POOL_LIMIT)
+ return 1;
+
mutex_lock(&pool->mutex);
if (PageHighMem(page)) {
list_add_tail(&page->lru, &pool->high_items);
@@ -103,16 +117,6 @@ 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 count = pool->low_count;
-
- if (high)
- count += pool->high_count;
-
- return count << pool->order;
-}
-
int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask,
int nr_to_scan)
{
--
1.7.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread