realloc stack use under O0 for x86_64
D'Alessandro, Luke K
ldalessa at indiana.edu
Wed Mar 25 11:48:34 PDT 2015
We have a lightweight threading system where we are using very small stacks, on the order of 8-32k. We depend on jemalloc for scalable allocation.
When we compile jemalloc for debugging purposes, we see realloc using a large amount of stack space:
70e48: 55 push %rbp
70e49: 48 89 e5 mov %rsp,%rbp
70e4c: 53 push %rbx
70e4d: 48 81 ec 68 62 00 00 sub $0x6268,%rsp
Compiling with just O1 results in a much more reasonable:
6ade: 41 57 push %r15
6ae0: 41 56 push %r14
6ae2: 41 55 push %r13
6ae4: 41 54 push %r12
6ae6: 55 push %rbp
6ae7: 53 push %rbx
6ae8: 48 81 ec 88 00 00 00 sub $0x88,%rsp
6aef: 48 89 fb mov %rdi,%rbx
6af2: 49 89 f4 mov %rsi,%r12
6af5: 48 85 f6 test %rsi,%rsi
I’ve tried to look through the source code for realloc, but I got a little lost. Can someone point me to what’s getting stack allocated that could possible need so much space? Is this a bug?
I can probably force our internal jemalloc to build in at least O1, but that means a bunch of configure.ac spaghetti mess that I’d prefer to avoid...
More information about the jemalloc-discuss