linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] driver : staging : ion: optimization for decreasing memory fragmentaion
@ 2019-03-14 11:12 Zhaoyang Huang
  2019-03-15  1:18 ` Zhaoyang Huang
  0 siblings, 1 reply; 7+ messages in thread
From: Zhaoyang Huang @ 2019-03-14 11:12 UTC (permalink / raw)
  To: open list:ANDROID ION DRIVER, open list:ANDROID ION DRIVER,
	moderated list:ANDROID ION DRIVER, linux-kernel

From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>

Two action for this patch:
1. set a batch size for system heap's shrinker, which can have it buffer
reasonable page blocks in pool for future allocation.
2. reverse the order sequence when free page blocks, the purpose is also
to have system heap keep as more big blocks as it can.

By testing on an android system with 2G RAM, the changes with setting
batch = 48MB can help reduce the fragmentation obviously and improve
big block allocation speed for 15%.

Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
---
 drivers/staging/android/ion/ion_heap.c        | 12 +++++++++++-
 drivers/staging/android/ion/ion_system_heap.c |  2 +-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/android/ion/ion_heap.c b/drivers/staging/android/ion/ion_heap.c
index 31db510..68aa970 100644
--- a/drivers/staging/android/ion/ion_heap.c
+++ b/drivers/staging/android/ion/ion_heap.c
@@ -16,6 +16,8 @@
 #include <linux/vmalloc.h>
 #include "ion.h"
 
+unsigned long ion_heap_batch;
+
 void *ion_heap_map_kernel(struct ion_heap *heap,
 			  struct ion_buffer *buffer)
 {
@@ -303,7 +305,15 @@ int ion_heap_init_shrinker(struct ion_heap *heap)
 	heap->shrinker.count_objects = ion_heap_shrink_count;
 	heap->shrinker.scan_objects = ion_heap_shrink_scan;
 	heap->shrinker.seeks = DEFAULT_SEEKS;
-	heap->shrinker.batch = 0;
+	heap->shrinker.batch = ion_heap_batch;
 
 	return register_shrinker(&heap->shrinker);
 }
+
+static int __init ion_system_heap_batch_init(char *arg)
+{
+	 ion_heap_batch = memparse(arg, NULL);
+
+	return 0;
+}
+early_param("ion_batch", ion_system_heap_batch_init);
diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
index 701eb9f..d249f8d 100644
--- a/drivers/staging/android/ion/ion_system_heap.c
+++ b/drivers/staging/android/ion/ion_system_heap.c
@@ -182,7 +182,7 @@ static int ion_system_heap_shrink(struct ion_heap *heap, gfp_t gfp_mask,
 	if (!nr_to_scan)
 		only_scan = 1;
 
-	for (i = 0; i < NUM_ORDERS; i++) {
+	for (i = NUM_ORDERS - 1; i >= 0; i--) {
 		pool = sys_heap->pools[i];
 
 		if (only_scan) {
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] driver : staging : ion: optimization for decreasing memory fragmentaion
  2019-03-14 11:12 [PATCH] driver : staging : ion: optimization for decreasing memory fragmentaion Zhaoyang Huang
@ 2019-03-15  1:18 ` Zhaoyang Huang
  0 siblings, 0 replies; 7+ messages in thread
From: Zhaoyang Huang @ 2019-03-15  1:18 UTC (permalink / raw)
  To: open list:ANDROID ION DRIVER, open list:ANDROID ION DRIVER,
	moderated list:ANDROID ION DRIVER, LKML

Hi All,
I would like to explain more for the purpose of this patch. During our
daily test on android system, we found that there is always showing
the memory fragmentation after some test cases(etc camera snapshot),
which lead to huge amount of order0 pages which other page blocks
remain none(200M order0 page blocks in a 1G RAM system). By analysing
the DDR dump file, we can find that it is the ION SYSTEM HEAP which
cut the whole memory into pieces. That is to say, Burst huge order0
allocation is alike a knife that cut higher order blocks into small
one and can not back to original buddy somehow.


On Thu, Mar 14, 2019 at 7:12 PM Zhaoyang Huang <huangzhaoyang@gmail.com> wrote:
>
> From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
>
> Two action for this patch:
> 1. set a batch size for system heap's shrinker, which can have it buffer
> reasonable page blocks in pool for future allocation.
> 2. reverse the order sequence when free page blocks, the purpose is also
> to have system heap keep as more big blocks as it can.
>
> By testing on an android system with 2G RAM, the changes with setting
> batch = 48MB can help reduce the fragmentation obviously and improve
> big block allocation speed for 15%.
>
> Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> ---
>  drivers/staging/android/ion/ion_heap.c        | 12 +++++++++++-
>  drivers/staging/android/ion/ion_system_heap.c |  2 +-
>  2 files changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/android/ion/ion_heap.c b/drivers/staging/android/ion/ion_heap.c
> index 31db510..68aa970 100644
> --- a/drivers/staging/android/ion/ion_heap.c
> +++ b/drivers/staging/android/ion/ion_heap.c
> @@ -16,6 +16,8 @@
>  #include <linux/vmalloc.h>
>  #include "ion.h"
>
> +unsigned long ion_heap_batch;
> +
>  void *ion_heap_map_kernel(struct ion_heap *heap,
>                           struct ion_buffer *buffer)
>  {
> @@ -303,7 +305,15 @@ int ion_heap_init_shrinker(struct ion_heap *heap)
>         heap->shrinker.count_objects = ion_heap_shrink_count;
>         heap->shrinker.scan_objects = ion_heap_shrink_scan;
>         heap->shrinker.seeks = DEFAULT_SEEKS;
> -       heap->shrinker.batch = 0;
> +       heap->shrinker.batch = ion_heap_batch;
>
>         return register_shrinker(&heap->shrinker);
>  }
> +
> +static int __init ion_system_heap_batch_init(char *arg)
> +{
> +        ion_heap_batch = memparse(arg, NULL);
> +
> +       return 0;
> +}
> +early_param("ion_batch", ion_system_heap_batch_init);
> diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
> index 701eb9f..d249f8d 100644
> --- a/drivers/staging/android/ion/ion_system_heap.c
> +++ b/drivers/staging/android/ion/ion_system_heap.c
> @@ -182,7 +182,7 @@ static int ion_system_heap_shrink(struct ion_heap *heap, gfp_t gfp_mask,
>         if (!nr_to_scan)
>                 only_scan = 1;
>
> -       for (i = 0; i < NUM_ORDERS; i++) {
> +       for (i = NUM_ORDERS - 1; i >= 0; i--) {
>                 pool = sys_heap->pools[i];
>
>                 if (only_scan) {
> --
> 1.9.1
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] driver : staging : ion: optimization for decreasing memory fragmentaion
  2019-03-20 14:23 ` Vlastimil Babka
@ 2019-03-20 14:28   ` Laura Abbott
  0 siblings, 0 replies; 7+ messages in thread
From: Laura Abbott @ 2019-03-20 14:28 UTC (permalink / raw)
  To: Vlastimil Babka, Zhaoyang Huang, Chintan Pandya, David Rientjes,
	Joe Perches, Andrew Morton, Michal Hocko, linux-mm, linux-kernel,
	Sumit Semwal, devel, dri-devel

On 3/20/19 7:23 AM, Vlastimil Babka wrote:
> You should have CC'd the ION maintainers/lists per
> ./scripts/get_maintainer.pl - CCing now.
> 
> On 3/14/19 12:06 PM, Zhaoyang Huang wrote:
>> From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
>>
>> Two action for this patch:
>> 1. set a batch size for system heap's shrinker, which can have it buffer
>> reasonable page blocks in pool for future allocation.
>> 2. reverse the order sequence when free page blocks, the purpose is also
>> to have system heap keep as more big blocks as it can.
>>
>> By testing on an android system with 2G RAM, the changes with setting
>> batch = 48MB can help reduce the fragmentation obviously and improve
>> big block allocation speed for 15%.
>>
>> Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
>> ---
>>   drivers/staging/android/ion/ion_heap.c        | 12 +++++++++++-
>>   drivers/staging/android/ion/ion_system_heap.c |  2 +-
>>   2 files changed, 12 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/staging/android/ion/ion_heap.c b/drivers/staging/android/ion/ion_heap.c
>> index 31db510..9e9caf2 100644
>> --- a/drivers/staging/android/ion/ion_heap.c
>> +++ b/drivers/staging/android/ion/ion_heap.c
>> @@ -16,6 +16,8 @@
>>   #include <linux/vmalloc.h>
>>   #include "ion.h"
>>   
>> +unsigned long ion_heap_batch = 0;
>> +
>>   void *ion_heap_map_kernel(struct ion_heap *heap,
>>   			  struct ion_buffer *buffer)
>>   {
>> @@ -303,7 +305,15 @@ int ion_heap_init_shrinker(struct ion_heap *heap)
>>   	heap->shrinker.count_objects = ion_heap_shrink_count;
>>   	heap->shrinker.scan_objects = ion_heap_shrink_scan;
>>   	heap->shrinker.seeks = DEFAULT_SEEKS;
>> -	heap->shrinker.batch = 0;
>> +	heap->shrinker.batch = ion_heap_batch;
>>   
>>   	return register_shrinker(&heap->shrinker);
>>   }
>> +
>> +static int __init ion_system_heap_batch_init(char *arg)
>> +{
>> +	 ion_heap_batch = memparse(arg, NULL);
>> +
>> +	return 0;
>> +}
>> +early_param("ion_batch", ion_system_heap_batch_init);
>> diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
>> index 701eb9f..d249f8d 100644
>> --- a/drivers/staging/android/ion/ion_system_heap.c
>> +++ b/drivers/staging/android/ion/ion_system_heap.c
>> @@ -182,7 +182,7 @@ static int ion_system_heap_shrink(struct ion_heap *heap, gfp_t gfp_mask,
>>   	if (!nr_to_scan)
>>   		only_scan = 1;
>>   
>> -	for (i = 0; i < NUM_ORDERS; i++) {
>> +	for (i = NUM_ORDERS - 1; i >= 0; i--) {
>>   		pool = sys_heap->pools[i];
>>   
>>   		if (only_scan) {
>>
> 

We're in the process of significantly reworking Ion so I
don't think it makes sense to take these as we work to
get things out of staging. You can resubmit this later,
but when you do please split this into two separate
patches since it's actually two independent changes.

Thanks,
Laura


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] driver : staging : ion: optimization for decreasing memory fragmentaion
  2019-03-14 11:06 Zhaoyang Huang
  2019-03-20  1:10 ` David Rientjes
@ 2019-03-20 14:23 ` Vlastimil Babka
  2019-03-20 14:28   ` Laura Abbott
  1 sibling, 1 reply; 7+ messages in thread
From: Vlastimil Babka @ 2019-03-20 14:23 UTC (permalink / raw)
  To: Zhaoyang Huang, Chintan Pandya, David Rientjes, Joe Perches,
	Andrew Morton, Michal Hocko, linux-mm, linux-kernel,
	Laura Abbott, Sumit Semwal, devel, dri-devel

You should have CC'd the ION maintainers/lists per
./scripts/get_maintainer.pl - CCing now.

On 3/14/19 12:06 PM, Zhaoyang Huang wrote:
> From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> 
> Two action for this patch:
> 1. set a batch size for system heap's shrinker, which can have it buffer
> reasonable page blocks in pool for future allocation.
> 2. reverse the order sequence when free page blocks, the purpose is also
> to have system heap keep as more big blocks as it can.
> 
> By testing on an android system with 2G RAM, the changes with setting
> batch = 48MB can help reduce the fragmentation obviously and improve
> big block allocation speed for 15%.
> 
> Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> ---
>  drivers/staging/android/ion/ion_heap.c        | 12 +++++++++++-
>  drivers/staging/android/ion/ion_system_heap.c |  2 +-
>  2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/android/ion/ion_heap.c b/drivers/staging/android/ion/ion_heap.c
> index 31db510..9e9caf2 100644
> --- a/drivers/staging/android/ion/ion_heap.c
> +++ b/drivers/staging/android/ion/ion_heap.c
> @@ -16,6 +16,8 @@
>  #include <linux/vmalloc.h>
>  #include "ion.h"
>  
> +unsigned long ion_heap_batch = 0;
> +
>  void *ion_heap_map_kernel(struct ion_heap *heap,
>  			  struct ion_buffer *buffer)
>  {
> @@ -303,7 +305,15 @@ int ion_heap_init_shrinker(struct ion_heap *heap)
>  	heap->shrinker.count_objects = ion_heap_shrink_count;
>  	heap->shrinker.scan_objects = ion_heap_shrink_scan;
>  	heap->shrinker.seeks = DEFAULT_SEEKS;
> -	heap->shrinker.batch = 0;
> +	heap->shrinker.batch = ion_heap_batch;
>  
>  	return register_shrinker(&heap->shrinker);
>  }
> +
> +static int __init ion_system_heap_batch_init(char *arg)
> +{
> +	 ion_heap_batch = memparse(arg, NULL);
> +
> +	return 0;
> +}
> +early_param("ion_batch", ion_system_heap_batch_init);
> diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
> index 701eb9f..d249f8d 100644
> --- a/drivers/staging/android/ion/ion_system_heap.c
> +++ b/drivers/staging/android/ion/ion_system_heap.c
> @@ -182,7 +182,7 @@ static int ion_system_heap_shrink(struct ion_heap *heap, gfp_t gfp_mask,
>  	if (!nr_to_scan)
>  		only_scan = 1;
>  
> -	for (i = 0; i < NUM_ORDERS; i++) {
> +	for (i = NUM_ORDERS - 1; i >= 0; i--) {
>  		pool = sys_heap->pools[i];
>  
>  		if (only_scan) {
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] driver : staging : ion: optimization for decreasing memory fragmentaion
  2019-03-20  1:10 ` David Rientjes
@ 2019-03-20  6:11   ` Zhaoyang Huang
  0 siblings, 0 replies; 7+ messages in thread
From: Zhaoyang Huang @ 2019-03-20  6:11 UTC (permalink / raw)
  To: David Rientjes
  Cc: Chintan Pandya, Joe Perches, Andrew Morton, Michal Hocko,
	open list:MEMORY MANAGEMENT, LKML

On Wed, Mar 20, 2019 at 9:10 AM David Rientjes <rientjes@google.com> wrote:
>
> On Thu, 14 Mar 2019, Zhaoyang Huang wrote:
>
> > From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> >
> > Two action for this patch:
> > 1. set a batch size for system heap's shrinker, which can have it buffer
> > reasonable page blocks in pool for future allocation.
> > 2. reverse the order sequence when free page blocks, the purpose is also
> > to have system heap keep as more big blocks as it can.
> >
> > By testing on an android system with 2G RAM, the changes with setting
> > batch = 48MB can help reduce the fragmentation obviously and improve
> > big block allocation speed for 15%.
> >
> > Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> > ---
> >  drivers/staging/android/ion/ion_heap.c        | 12 +++++++++++-
> >  drivers/staging/android/ion/ion_system_heap.c |  2 +-
> >  2 files changed, 12 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/staging/android/ion/ion_heap.c b/drivers/staging/android/ion/ion_heap.c
> > index 31db510..9e9caf2 100644
> > --- a/drivers/staging/android/ion/ion_heap.c
> > +++ b/drivers/staging/android/ion/ion_heap.c
> > @@ -16,6 +16,8 @@
> >  #include <linux/vmalloc.h>
> >  #include "ion.h"
> >
> > +unsigned long ion_heap_batch = 0;
>
> static?
ok
>
> > +
> >  void *ion_heap_map_kernel(struct ion_heap *heap,
> >                         struct ion_buffer *buffer)
> >  {
> > @@ -303,7 +305,15 @@ int ion_heap_init_shrinker(struct ion_heap *heap)
> >       heap->shrinker.count_objects = ion_heap_shrink_count;
> >       heap->shrinker.scan_objects = ion_heap_shrink_scan;
> >       heap->shrinker.seeks = DEFAULT_SEEKS;
> > -     heap->shrinker.batch = 0;
> > +     heap->shrinker.batch = ion_heap_batch;
> >
> >       return register_shrinker(&heap->shrinker);
> >  }
> > +
> > +static int __init ion_system_heap_batch_init(char *arg)
> > +{
> > +      ion_heap_batch = memparse(arg, NULL);
> > +
>
> No bounds checking?  What are the legitimate upper and lower bounds here?
Actruly, ion_heap_batch will work during shrink_slab, which shown bellow.
We can find that it is hard that to set batch_size as a constant value
as total ram size is different to each system. Furthermore, it is also
no need to set a percentage thing, "total_scan >= freeable" will work
as another threshold of slab size.
...
while (total_scan >= batch_size ||
       total_scan >= freeable) {
    unsigned long nr_to_scan = min(batch_size, total_scan);
    ret = shrinker->scan_objects(shrinker, shrinkctl);
...
shrinkctl->nr_to_scan = nr_to_scan;
shrinkctl->nr_scanned = nr_to_scan;
ret = shrinker->scan_objects(shrinker, shrinkctl);
>
> > +     return 0;
> > +}
> > +early_param("ion_batch", ion_system_heap_batch_init);
> > diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
> > index 701eb9f..d249f8d 100644
> > --- a/drivers/staging/android/ion/ion_system_heap.c
> > +++ b/drivers/staging/android/ion/ion_system_heap.c
> > @@ -182,7 +182,7 @@ static int ion_system_heap_shrink(struct ion_heap *heap, gfp_t gfp_mask,
> >       if (!nr_to_scan)
> >               only_scan = 1;
> >
> > -     for (i = 0; i < NUM_ORDERS; i++) {
> > +     for (i = NUM_ORDERS - 1; i >= 0; i--) {
> >               pool = sys_heap->pools[i];
> >
> >               if (only_scan) {
>
> Can we get a Documentation update on how we can use ion_batch and what the
> appropriate settings are (and in what circumstances)?
ok, I will explain it here firstly.
ion_heap_batch will work as the batch_size during shink_slab, which
help the heap buffer some of the page blocks for further allocation.
My test is based on a android system with 2G RAM. We find that
multimedia related cases is the chief consumer of the ion system heap
and cause memory fragmentation after a period of running. By
configuring ion_heap_batch as 48M(3 x camera peak consuming value) and
revert the shrink order, we can almost eliminate such scenario during
the test and improve the allocating speed up to 15%.
For common policy, the batch size should depend on the practical
scenario. The peak value can be got via sysfs or kernel log.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] driver : staging : ion: optimization for decreasing memory fragmentaion
  2019-03-14 11:06 Zhaoyang Huang
@ 2019-03-20  1:10 ` David Rientjes
  2019-03-20  6:11   ` Zhaoyang Huang
  2019-03-20 14:23 ` Vlastimil Babka
  1 sibling, 1 reply; 7+ messages in thread
From: David Rientjes @ 2019-03-20  1:10 UTC (permalink / raw)
  To: Zhaoyang Huang
  Cc: Chintan Pandya, Joe Perches, Andrew Morton, Michal Hocko,
	linux-mm, linux-kernel

On Thu, 14 Mar 2019, Zhaoyang Huang wrote:

> From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> 
> Two action for this patch:
> 1. set a batch size for system heap's shrinker, which can have it buffer
> reasonable page blocks in pool for future allocation.
> 2. reverse the order sequence when free page blocks, the purpose is also
> to have system heap keep as more big blocks as it can.
> 
> By testing on an android system with 2G RAM, the changes with setting
> batch = 48MB can help reduce the fragmentation obviously and improve
> big block allocation speed for 15%.
> 
> Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> ---
>  drivers/staging/android/ion/ion_heap.c        | 12 +++++++++++-
>  drivers/staging/android/ion/ion_system_heap.c |  2 +-
>  2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/android/ion/ion_heap.c b/drivers/staging/android/ion/ion_heap.c
> index 31db510..9e9caf2 100644
> --- a/drivers/staging/android/ion/ion_heap.c
> +++ b/drivers/staging/android/ion/ion_heap.c
> @@ -16,6 +16,8 @@
>  #include <linux/vmalloc.h>
>  #include "ion.h"
>  
> +unsigned long ion_heap_batch = 0;

static?

> +
>  void *ion_heap_map_kernel(struct ion_heap *heap,
>  			  struct ion_buffer *buffer)
>  {
> @@ -303,7 +305,15 @@ int ion_heap_init_shrinker(struct ion_heap *heap)
>  	heap->shrinker.count_objects = ion_heap_shrink_count;
>  	heap->shrinker.scan_objects = ion_heap_shrink_scan;
>  	heap->shrinker.seeks = DEFAULT_SEEKS;
> -	heap->shrinker.batch = 0;
> +	heap->shrinker.batch = ion_heap_batch;
>  
>  	return register_shrinker(&heap->shrinker);
>  }
> +
> +static int __init ion_system_heap_batch_init(char *arg)
> +{
> +	 ion_heap_batch = memparse(arg, NULL);
> +

No bounds checking?  What are the legitimate upper and lower bounds here?

> +	return 0;
> +}
> +early_param("ion_batch", ion_system_heap_batch_init);
> diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
> index 701eb9f..d249f8d 100644
> --- a/drivers/staging/android/ion/ion_system_heap.c
> +++ b/drivers/staging/android/ion/ion_system_heap.c
> @@ -182,7 +182,7 @@ static int ion_system_heap_shrink(struct ion_heap *heap, gfp_t gfp_mask,
>  	if (!nr_to_scan)
>  		only_scan = 1;
>  
> -	for (i = 0; i < NUM_ORDERS; i++) {
> +	for (i = NUM_ORDERS - 1; i >= 0; i--) {
>  		pool = sys_heap->pools[i];
>  
>  		if (only_scan) {

Can we get a Documentation update on how we can use ion_batch and what the 
appropriate settings are (and in what circumstances)?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] driver : staging : ion: optimization for decreasing memory fragmentaion
@ 2019-03-14 11:06 Zhaoyang Huang
  2019-03-20  1:10 ` David Rientjes
  2019-03-20 14:23 ` Vlastimil Babka
  0 siblings, 2 replies; 7+ messages in thread
From: Zhaoyang Huang @ 2019-03-14 11:06 UTC (permalink / raw)
  To: Chintan Pandya, David Rientjes, Joe Perches, Andrew Morton,
	Michal Hocko, linux-mm, linux-kernel

From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>

Two action for this patch:
1. set a batch size for system heap's shrinker, which can have it buffer
reasonable page blocks in pool for future allocation.
2. reverse the order sequence when free page blocks, the purpose is also
to have system heap keep as more big blocks as it can.

By testing on an android system with 2G RAM, the changes with setting
batch = 48MB can help reduce the fragmentation obviously and improve
big block allocation speed for 15%.

Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
---
 drivers/staging/android/ion/ion_heap.c        | 12 +++++++++++-
 drivers/staging/android/ion/ion_system_heap.c |  2 +-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/android/ion/ion_heap.c b/drivers/staging/android/ion/ion_heap.c
index 31db510..9e9caf2 100644
--- a/drivers/staging/android/ion/ion_heap.c
+++ b/drivers/staging/android/ion/ion_heap.c
@@ -16,6 +16,8 @@
 #include <linux/vmalloc.h>
 #include "ion.h"
 
+unsigned long ion_heap_batch = 0;
+
 void *ion_heap_map_kernel(struct ion_heap *heap,
 			  struct ion_buffer *buffer)
 {
@@ -303,7 +305,15 @@ int ion_heap_init_shrinker(struct ion_heap *heap)
 	heap->shrinker.count_objects = ion_heap_shrink_count;
 	heap->shrinker.scan_objects = ion_heap_shrink_scan;
 	heap->shrinker.seeks = DEFAULT_SEEKS;
-	heap->shrinker.batch = 0;
+	heap->shrinker.batch = ion_heap_batch;
 
 	return register_shrinker(&heap->shrinker);
 }
+
+static int __init ion_system_heap_batch_init(char *arg)
+{
+	 ion_heap_batch = memparse(arg, NULL);
+
+	return 0;
+}
+early_param("ion_batch", ion_system_heap_batch_init);
diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
index 701eb9f..d249f8d 100644
--- a/drivers/staging/android/ion/ion_system_heap.c
+++ b/drivers/staging/android/ion/ion_system_heap.c
@@ -182,7 +182,7 @@ static int ion_system_heap_shrink(struct ion_heap *heap, gfp_t gfp_mask,
 	if (!nr_to_scan)
 		only_scan = 1;
 
-	for (i = 0; i < NUM_ORDERS; i++) {
+	for (i = NUM_ORDERS - 1; i >= 0; i--) {
 		pool = sys_heap->pools[i];
 
 		if (only_scan) {
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-03-20 14:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-14 11:12 [PATCH] driver : staging : ion: optimization for decreasing memory fragmentaion Zhaoyang Huang
2019-03-15  1:18 ` Zhaoyang Huang
  -- strict thread matches above, loose matches on Subject: below --
2019-03-14 11:06 Zhaoyang Huang
2019-03-20  1:10 ` David Rientjes
2019-03-20  6:11   ` Zhaoyang Huang
2019-03-20 14:23 ` Vlastimil Babka
2019-03-20 14:28   ` Laura Abbott

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).