* [PATCH] binder_alloc: replace kcalloc with kvcalloc to mitigate OOM issues
@ 2024-06-11 8:56 Lei Liu
2024-06-12 9:58 ` Greg Kroah-Hartman
0 siblings, 1 reply; 4+ messages in thread
From: Lei Liu @ 2024-06-11 8:56 UTC (permalink / raw)
To: Greg Kroah-Hartman, Arve Hjønnevåg, Todd Kjos,
Martijn Coenen, Joel Fernandes, Christian Brauner, Carlos Llamas,
Suren Baghdasaryan, linux-kernel
Cc: opensource.kernel, Lei Liu
In binder_alloc, there is a frequent need for order3 memory allocation,
especially on small-memory mobile devices, which can lead to OOM and
cause foreground applications to be killed, resulting in flashbacks.
We use kvcalloc to allocate memory, which can reduce system OOM
occurrences, as well as decrease the time and probability of failure for
order3 memory allocations. Additionally, it can also improve the
throughput of binder (as verified by Google's binder_benchmark testing
tool).
We have conducted multiple tests on an 8GB memory phone, and the
performance of kvcalloc is better. Below is a partial excerpt of the
test data.
throughput = (size * Iterations)/Time
Benchmark-kvcalloc Time CPU Iterations throughput(Gb/s)
----------------------------------------------------------------
BM_sendVec_binder-4096 30926 ns 20481 ns 34457 4563.66↑
BM_sendVec_binder-8192 42667 ns 30837 ns 22631 4345.11↑
BM_sendVec_binder-16384 67586 ns 52381 ns 13318 3228.51↑
BM_sendVec_binder-32768 116496 ns 94893 ns 7416 2085.97↑
BM_sendVec_binder-65536 265482 ns 209214 ns 3530 871.40↑
Benchmark-kvcalloc Time CPU Iterations throughput(Gb/s)
----------------------------------------------------------------
BM_sendVec_binder-4096 39070 ns 24207 ns 31063 3256.56
BM_sendVec_binder-8192 49476 ns 35099 ns 18817 3115.62
BM_sendVec_binder-16384 76866 ns 58924 ns 11883 2532.86
BM_sendVec_binder-32768 134022 ns 102788 ns 6535 1597.78
BM_sendVec_binder-65536 281004 ns 220028 ns 3135 731.14
Signed-off-by: Lei Liu <liulei.rjpt@vivo.com>
---
drivers/android/binder_alloc.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index 2e1f261ec5c8..5dcab4a5e341 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -836,7 +836,7 @@ int binder_alloc_mmap_handler(struct binder_alloc *alloc,
alloc->buffer = vma->vm_start;
- alloc->pages = kcalloc(alloc->buffer_size / PAGE_SIZE,
+ alloc->pages = kvcalloc(alloc->buffer_size / PAGE_SIZE,
sizeof(alloc->pages[0]),
GFP_KERNEL);
if (alloc->pages == NULL) {
@@ -869,7 +869,7 @@ int binder_alloc_mmap_handler(struct binder_alloc *alloc,
return 0;
err_alloc_buf_struct_failed:
- kfree(alloc->pages);
+ kvfree(alloc->pages);
alloc->pages = NULL;
err_alloc_pages_failed:
alloc->buffer = 0;
@@ -939,7 +939,7 @@ void binder_alloc_deferred_release(struct binder_alloc *alloc)
__free_page(alloc->pages[i].page_ptr);
page_count++;
}
- kfree(alloc->pages);
+ kvfree(alloc->pages);
}
spin_unlock(&alloc->lock);
if (alloc->mm)
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] binder_alloc: replace kcalloc with kvcalloc to mitigate OOM issues
2024-06-11 8:56 [PATCH] binder_alloc: replace kcalloc with kvcalloc to mitigate OOM issues Lei Liu
@ 2024-06-12 9:58 ` Greg Kroah-Hartman
2024-06-13 12:01 ` Lei Liu
0 siblings, 1 reply; 4+ messages in thread
From: Greg Kroah-Hartman @ 2024-06-12 9:58 UTC (permalink / raw)
To: Lei Liu
Cc: Arve Hjønnevåg, Todd Kjos, Martijn Coenen,
Joel Fernandes, Christian Brauner, Carlos Llamas,
Suren Baghdasaryan, linux-kernel, opensource.kernel
On Tue, Jun 11, 2024 at 04:56:28PM +0800, Lei Liu wrote:
> In binder_alloc, there is a frequent need for order3 memory allocation,
> especially on small-memory mobile devices, which can lead to OOM and
> cause foreground applications to be killed, resulting in flashbacks.
>
> We use kvcalloc to allocate memory, which can reduce system OOM
> occurrences, as well as decrease the time and probability of failure for
> order3 memory allocations. Additionally, it can also improve the
> throughput of binder (as verified by Google's binder_benchmark testing
> tool).
>
> We have conducted multiple tests on an 8GB memory phone, and the
> performance of kvcalloc is better. Below is a partial excerpt of the
> test data.
>
> throughput = (size * Iterations)/Time
> Benchmark-kvcalloc Time CPU Iterations throughput(Gb/s)
> ----------------------------------------------------------------
> BM_sendVec_binder-4096 30926 ns 20481 ns 34457 4563.66↑
> BM_sendVec_binder-8192 42667 ns 30837 ns 22631 4345.11↑
> BM_sendVec_binder-16384 67586 ns 52381 ns 13318 3228.51↑
> BM_sendVec_binder-32768 116496 ns 94893 ns 7416 2085.97↑
> BM_sendVec_binder-65536 265482 ns 209214 ns 3530 871.40↑
>
> Benchmark-kvcalloc Time CPU Iterations throughput(Gb/s)
Both benchmarks are the same? Or is this labeled incorrectly?
> ----------------------------------------------------------------
> BM_sendVec_binder-4096 39070 ns 24207 ns 31063 3256.56
> BM_sendVec_binder-8192 49476 ns 35099 ns 18817 3115.62
> BM_sendVec_binder-16384 76866 ns 58924 ns 11883 2532.86
> BM_sendVec_binder-32768 134022 ns 102788 ns 6535 1597.78
> BM_sendVec_binder-65536 281004 ns 220028 ns 3135 731.14
>
> Signed-off-by: Lei Liu <liulei.rjpt@vivo.com>
> ---
> drivers/android/binder_alloc.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
> index 2e1f261ec5c8..5dcab4a5e341 100644
> --- a/drivers/android/binder_alloc.c
> +++ b/drivers/android/binder_alloc.c
> @@ -836,7 +836,7 @@ int binder_alloc_mmap_handler(struct binder_alloc *alloc,
>
> alloc->buffer = vma->vm_start;
>
> - alloc->pages = kcalloc(alloc->buffer_size / PAGE_SIZE,
> + alloc->pages = kvcalloc(alloc->buffer_size / PAGE_SIZE,
> sizeof(alloc->pages[0]),
> GFP_KERNEL);
Nit, update the indentation please.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] binder_alloc: replace kcalloc with kvcalloc to mitigate OOM issues
2024-06-12 9:58 ` Greg Kroah-Hartman
@ 2024-06-13 12:01 ` Lei Liu
2024-06-13 13:42 ` Greg Kroah-Hartman
0 siblings, 1 reply; 4+ messages in thread
From: Lei Liu @ 2024-06-13 12:01 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Arve Hjønnevåg, Todd Kjos, Martijn Coenen,
Joel Fernandes, Christian Brauner, Carlos Llamas,
Suren Baghdasaryan, linux-kernel, opensource.kernel
On 2024/6/12 17:58, Greg Kroah-Hartman wrote:
> On Tue, Jun 11, 2024 at 04:56:28PM +0800, Lei Liu wrote:
>
>> In binder_alloc, there is a frequent need for order3 memory
>> allocation, especially on small-memory mobile devices, which can lead
>> to OOM and cause foreground applications to be killed, resulting in
>> flashbacks. We use kvcalloc to allocate memory, which can reduce
>> system OOM occurrences, as well as decrease the time and probability
>> of failure for order3 memory allocations. Additionally, it can also
>> improve the throughput of binder (as verified by Google's
>> binder_benchmark testing tool). We have conducted multiple tests on
>> an 8GB memory phone, and the performance of kvcalloc is better. Below
>> is a partial excerpt of the test data. throughput = (size *
>> Iterations)/Time Benchmark-kvcalloc Time CPU Iterations
>> throughput(Gb/s)
>> ----------------------------------------------------------------
>> BM_sendVec_binder-4096 30926 ns 20481 ns 34457 4563.66↑
>> BM_sendVec_binder-8192 42667 ns 30837 ns 22631 4345.11↑
>> BM_sendVec_binder-16384 67586 ns 52381 ns 13318 3228.51↑
>> BM_sendVec_binder-32768 116496 ns 94893 ns 7416 2085.97↑
>> BM_sendVec_binder-65536 265482 ns 209214 ns 3530 871.40↑
>> Benchmark-kvcalloc Time CPU Iterations throughput(Gb/s)
> Both benchmarks are the same? Or is this labeled incorrectly?
I'm really sorry, I got the title of the table wrong, here are the
updated data:
throughput = (size * Iterations)/Time
kvcalloc->kvmalloc:
Benchmark-kvcalloc Time CPU Iterations throughput(Gb/s)
----------------------------------------------------------------
BM_sendVec_binder-4096 30926 ns 20481 ns 34457 4563.66↑
BM_sendVec_binder-8192 42667 ns 30837 ns 22631 4345.11↑
BM_sendVec_binder-16384 67586 ns 52381 ns 13318 3228.51↑
BM_sendVec_binder-32768 116496 ns 94893 ns 7416 2085.97↑
BM_sendVec_binder-65536 265482 ns 209214 ns 3530 871.40↑
kcalloc->kmalloc
Benchmark-kcalloc Time CPU Iterations throughput(Gb/s)
----------------------------------------------------------------
BM_sendVec_binder-4096 39070 ns 24207 ns 31063 3256.56
BM_sendVec_binder-8192 49476 ns 35099 ns 18817 3115.62
BM_sendVec_binder-16384 76866 ns 58924 ns 11883 2532.86
BM_sendVec_binder-32768 134022 ns 102788 ns 6535 1597.78
BM_sendVec_binder-65536 281004 ns 220028 ns 3135 731.14
>> ----------------------------------------------------------------
>> BM_sendVec_binder-4096 39070 ns 24207 ns 31063 3256.56
>> BM_sendVec_binder-8192 49476 ns 35099 ns 18817 3115.62
>> BM_sendVec_binder-16384 76866 ns 58924 ns 11883 2532.86
>> BM_sendVec_binder-32768 134022 ns 102788 ns 6535 1597.78
>> BM_sendVec_binder-65536 281004 ns 220028 ns 3135 731.14
>> Signed-off-by: Lei Liu <liulei.rjpt@vivo.com> ---
>> drivers/android/binder_alloc.c | 6 +++--- 1 file changed, 3
>> insertions(+), 3 deletions(-) diff --git
>> a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
>> index 2e1f261ec5c8..5dcab4a5e341 100644 ---
>> a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c
>> @@ -836,7 +836,7 @@ int binder_alloc_mmap_handler(struct binder_alloc
>> *alloc, alloc->buffer = vma->vm_start; - alloc->pages =
>> kcalloc(alloc->buffer_size / PAGE_SIZE, + alloc->pages =
>> kvcalloc(alloc->buffer_size / PAGE_SIZE, sizeof(alloc->pages[0]),
>> GFP_KERNEL);
> Nit, update the indentation please.
> thanks, greg k-h
The previous incorrect table title has been updated. Please help review
it again.
Thank you!
Lei Liu
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] binder_alloc: replace kcalloc with kvcalloc to mitigate OOM issues
2024-06-13 12:01 ` Lei Liu
@ 2024-06-13 13:42 ` Greg Kroah-Hartman
0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2024-06-13 13:42 UTC (permalink / raw)
To: Lei Liu
Cc: Arve Hjønnevåg, Todd Kjos, Martijn Coenen,
Joel Fernandes, Christian Brauner, Carlos Llamas,
Suren Baghdasaryan, linux-kernel, opensource.kernel
On Thu, Jun 13, 2024 at 08:01:39PM +0800, Lei Liu wrote:
> On 2024/6/12 17:58, Greg Kroah-Hartman wrote:
> > On Tue, Jun 11, 2024 at 04:56:28PM +0800, Lei Liu wrote:
> >
> > > In binder_alloc, there is a frequent need for order3 memory
> > > allocation, especially on small-memory mobile devices, which can
> > > lead to OOM and cause foreground applications to be killed,
> > > resulting in flashbacks. We use kvcalloc to allocate memory, which
> > > can reduce system OOM occurrences, as well as decrease the time and
> > > probability of failure for order3 memory allocations. Additionally,
> > > it can also improve the throughput of binder (as verified by
> > > Google's binder_benchmark testing tool). We have conducted multiple
> > > tests on an 8GB memory phone, and the performance of kvcalloc is
> > > better. Below is a partial excerpt of the test data. throughput =
> > > (size * Iterations)/Time Benchmark-kvcalloc Time CPU Iterations
> > > throughput(Gb/s)
> > > ----------------------------------------------------------------
> > > BM_sendVec_binder-4096 30926 ns 20481 ns 34457 4563.66↑
> > > BM_sendVec_binder-8192 42667 ns 30837 ns 22631 4345.11↑
> > > BM_sendVec_binder-16384 67586 ns 52381 ns 13318 3228.51↑
> > > BM_sendVec_binder-32768 116496 ns 94893 ns 7416 2085.97↑
> > > BM_sendVec_binder-65536 265482 ns 209214 ns 3530 871.40↑
> > > Benchmark-kvcalloc Time CPU Iterations throughput(Gb/s)
> > Both benchmarks are the same? Or is this labeled incorrectly?
> I'm really sorry, I got the title of the table wrong, here are the updated
> data:
> throughput = (size * Iterations)/Time
> kvcalloc->kvmalloc:
> Benchmark-kvcalloc Time CPU Iterations throughput(Gb/s)
> ----------------------------------------------------------------
> BM_sendVec_binder-4096 30926 ns 20481 ns 34457 4563.66↑
> BM_sendVec_binder-8192 42667 ns 30837 ns 22631 4345.11↑
> BM_sendVec_binder-16384 67586 ns 52381 ns 13318 3228.51↑
> BM_sendVec_binder-32768 116496 ns 94893 ns 7416 2085.97↑
> BM_sendVec_binder-65536 265482 ns 209214 ns 3530 871.40↑
>
> kcalloc->kmalloc
> Benchmark-kcalloc Time CPU Iterations throughput(Gb/s)
> ----------------------------------------------------------------
> BM_sendVec_binder-4096 39070 ns 24207 ns 31063 3256.56
> BM_sendVec_binder-8192 49476 ns 35099 ns 18817 3115.62
> BM_sendVec_binder-16384 76866 ns 58924 ns 11883 2532.86
> BM_sendVec_binder-32768 134022 ns 102788 ns 6535 1597.78
> BM_sendVec_binder-65536 281004 ns 220028 ns 3135 731.14
Great, can you please resend this as a new version?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-06-13 13:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-11 8:56 [PATCH] binder_alloc: replace kcalloc with kvcalloc to mitigate OOM issues Lei Liu
2024-06-12 9:58 ` Greg Kroah-Hartman
2024-06-13 12:01 ` Lei Liu
2024-06-13 13:42 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox