diff mbox

[6/6] coroutine: reduce stack size to 64kB

Message ID 1467272240-32123-7-git-send-email-pl@kamp.de
State New
Headers show

Commit Message

Peter Lieven June 30, 2016, 7:37 a.m. UTC
evaluation with the recently introduced maximum stack usage monitoring revealed
that the actual used stack size was never above 4kB so allocating 1MB stack
for each coroutine is a lot of wasted memory. So reduce the stack size to
64kB which should still give enough head room.

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 include/qemu/coroutine_int.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Richard Henderson July 1, 2016, 9:13 p.m. UTC | #1
On 06/30/2016 12:37 AM, Peter Lieven wrote:
> evaluation with the recently introduced maximum stack usage monitoring revealed
> that the actual used stack size was never above 4kB so allocating 1MB stack
> for each coroutine is a lot of wasted memory. So reduce the stack size to
> 64kB which should still give enough head room.
>
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
>  include/qemu/coroutine_int.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/qemu/coroutine_int.h b/include/qemu/coroutine_int.h
> index eac323a..f84d777 100644
> --- a/include/qemu/coroutine_int.h
> +++ b/include/qemu/coroutine_int.h
> @@ -28,7 +28,7 @@
>  #include "qemu/queue.h"
>  #include "qemu/coroutine.h"
>
> -#define COROUTINE_STACK_SIZE (1 << 20)
> +#define COROUTINE_STACK_SIZE (1 << 16)
>
>  typedef enum {
>      COROUTINE_YIELD = 1,
>

Ought we check that this is not smaller than

     sysconf(_SC_THREAD_STACK_MIN)

which (for glibc at least), is 192k for ia64, 128k for aarch64, mips and tile 
(though why it is quite so high in those later cases I don't know).


r~
Peter Lieven July 4, 2016, 6:22 a.m. UTC | #2
Am 01.07.2016 um 23:13 schrieb Richard Henderson:
> On 06/30/2016 12:37 AM, Peter Lieven wrote:
>> evaluation with the recently introduced maximum stack usage monitoring revealed
>> that the actual used stack size was never above 4kB so allocating 1MB stack
>> for each coroutine is a lot of wasted memory. So reduce the stack size to
>> 64kB which should still give enough head room.
>>
>> Signed-off-by: Peter Lieven <pl@kamp.de>
>> ---
>>  include/qemu/coroutine_int.h | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/qemu/coroutine_int.h b/include/qemu/coroutine_int.h
>> index eac323a..f84d777 100644
>> --- a/include/qemu/coroutine_int.h
>> +++ b/include/qemu/coroutine_int.h
>> @@ -28,7 +28,7 @@
>>  #include "qemu/queue.h"
>>  #include "qemu/coroutine.h"
>>
>> -#define COROUTINE_STACK_SIZE (1 << 20)
>> +#define COROUTINE_STACK_SIZE (1 << 16)
>>
>>  typedef enum {
>>      COROUTINE_YIELD = 1,
>>
>
> Ought we check that this is not smaller than
>
>     sysconf(_SC_THREAD_STACK_MIN)
>
> which (for glibc at least), is 192k for ia64, 128k for aarch64, mips and tile (though why it is quite so high in those later cases I don't know).

for x86_64 it seems to be 16k. I would not mind to adjust the stack size either in qemu_alloc_stack or change the macro for the coroutine stack
size into a function returning MAX(1 << 16, sysconf(_SC_THREAD_STACK_MIN)).

Peter
Paolo Bonzini July 4, 2016, 10:20 a.m. UTC | #3
On 04/07/2016 08:22, Peter Lieven wrote:
>>>
>>
>> Ought we check that this is not smaller than
>>
>>     sysconf(_SC_THREAD_STACK_MIN)
>>
>> which (for glibc at least), is 192k for ia64, 128k for aarch64, mips
>> and tile (though why it is quite so high in those later cases I don't
>> know).
> 
> for x86_64 it seems to be 16k. I would not mind to adjust the stack size
> either in qemu_alloc_stack or change the macro for the coroutine stack
> size into a function returning MAX(1 << 16, sysconf(_SC_THREAD_STACK_MIN)).

Yes, either of this is a good idea.

Paolo
diff mbox

Patch

diff --git a/include/qemu/coroutine_int.h b/include/qemu/coroutine_int.h
index eac323a..f84d777 100644
--- a/include/qemu/coroutine_int.h
+++ b/include/qemu/coroutine_int.h
@@ -28,7 +28,7 @@ 
 #include "qemu/queue.h"
 #include "qemu/coroutine.h"
 
-#define COROUTINE_STACK_SIZE (1 << 20)
+#define COROUTINE_STACK_SIZE (1 << 16)
 
 typedef enum {
     COROUTINE_YIELD = 1,