<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">On Oct 6, 2014, at 10:59 PM, Marcin Zalewski <<a href="mailto:marcin.zalewski@gmail.com">marcin.zalewski@gmail.com</a>> wrote:<div><blockquote type="cite"><div dir="ltr"><div><div><div><div>I am using the jemalloc from 4dcf04bfc03b9e9eb50015a8fc8735de28c23090 on a Cray system. We use jemalloc for all allocations, and I get a strange issue with Crays hugepages implementation. When I do not use the Cray hugepages module, my code runs fine. However, when I load hugepages64M, I get the following segmentation fault:<br><br>Program received signal SIGSEGV, Segmentation fault.<br>je_chunk_alloc_default (size=2048, alignment=0, zero=0x7fffffffa96f, <br>    arena_ind=0) at chunk.c:254<br>254             return (chunk_alloc_core(size, alignment, false, zero,<br>(gdb) bt<br>#0  je_chunk_alloc_default (size=2048, alignment=0, zero=0x7fffffffa96f, <br>    arena_ind=0) at chunk.c:254<br>#1  0x000000002001586f in je_huge_palloc (tsd=0x2aaab02092d0, <br>    arena=<optimized out>, size=size@entry=2048, alignment=0, <br>    zero=zero@entry=true) at huge.c:50<br>#2  0x0000000020015908 in je_huge_malloc (tsd=<optimized out>, <br>    arena=<optimized out>, size=size@entry=2048, zero=zero@entry=true)<br>    at huge.c:19<br>#3  0x0000000020018c90 in je_icalloct (arena=<optimized out>, <br>    try_tcache=<optimized out>, size=2048, tsd=<optimized out>)<br>    at ../../../contrib/jemalloc/include/jemalloc/internal/jemalloc_internal.h:662<br>#4  imallocx_flags (arena=<optimized out>, try_tcache=<optimized out>, <br>    zero=true, alignment=0, usize=2048, tsd=<optimized out>) at jemalloc.c:1450<br>#5  imallocx_no_prof (usize=<synthetic pointer>, flags=<optimized out>, <br>    size=<optimized out>, tsd=<optimized out>) at jemalloc.c:1531<br>#6  libxxx_mallocx (size=<optimized out>, flags=<optimized out>)<br>    at jemalloc.c:1550<br>#7  0x00002aaaaf6b9445 in register_printf_type () from /lib64/libc.so.6<br>#8  0x00002aaaabf019c0 in register_printf_flt128 ()<br>    at ../../../cray-gcc-4.9.0/libquadmath/printf/quadmath-printf.c:390<br>#9  0x00002aaaabf09de6 in __do_global_ctors_aux ()<br>   from /opt/gcc/4.9.0/snos/lib64/libquadmath.so.0<br>#10 0x00002aaaabee51fb in _init ()<br>   from /opt/gcc/4.9.0/snos/lib64/libquadmath.so.0<br>#11 0x00007fffffffaaf8 in ?? ()<br>#12 0x00002aaaaaab91b8 in call_init () from /lib64/ld-linux-x86-64.so.2<br>#13 0x00002aaaaaab92e7 in _dl_init_internal () from /lib64/ld-linux-x86-64.so.2<br>#14 0x00002aaaaaaabb3a in _dl_start_user () from /lib64/ld-linux-x86-64.so.2<br>#15 0x0000000000000001 in ?? ()<br>#16 0x00007fffffffb209 in ?? ()<br>#17 0x0000000000000000 in ?? ()<br><br></div>I know that this is not very much info to go on, but I wonder if it rings a bell for someone immediately. As far as I can understand, the Cray hugepages module silently changes all the pages to hugepages of a chosen size:<br><br><a href="http://www.nersc.gov/users/computational-systems/hopper/programming/tuning-options/">http://www.nersc.gov/users/computational-systems/hopper/programming/tuning-options/</a><br><br></div>What could be an obvious reason to cause the segmentation fault on that line? The line in question is this:<br><br>        return (chunk_alloc_core(size, alignment, false, zero,<br>            arenas[arena_ind]->dss_prec));<br><br></div>It seems that "arenas" is not properly initialized, but only with hugepages.<br></div></div></blockquote></div><br><div>I've been staring at this for a while, but can't come up with any conclusive picture of what's going on.  Part of the problem is that there are two frames missing from the backtrace, and the reported function arguments are clearly fictional.  Here's what the first several frames of the backtrace should look like:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">     </span>je_chunk_alloc_default(...)</div><div>>>><span class="Apple-tab-span" style="white-space:pre">      </span>je_chunk_alloc_arena(...)</div><div>>>><span class="Apple-tab-span" style="white-space:pre">        </span>je_arena_chunk_alloc_huge(...)</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>je_huge_palloc(...)</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>je_huge_malloc(...)</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>je_icalloct(...)</div><div><br></div><div>The calls are being made through function pointers, so I don't think it's possible for inlining to explain the omissions.</div><div><br></div><div>The mystery is how arenas[arena_ind] could possibly be NULL, given that arena_chunk_alloc_huge() is reading arena->ind in order to pass the arena index to chunk_alloc_arena().  In fact it's unsafe to read arenas[arena_ind] because the arenas.extend mallctl can write to the arenas pointer, but in order for that to be causing this crash, there would need to be another thread creating a new arena, and it would be a small race window.  (I'll fix the bug though!)</div><div><br></div><div>One random observation is that this crash is happening very early during execution, due to a library initializer running before entry into main().  It appears though that jemalloc has successfully bootstrapped itself by the time of the crash; otherwise malloc_init() would have failed in mallocx().</div><div><br></div><div>Is register_printf_type() really calling mallocx()?  I'd expect it to call malloc() or calloc(), unless jemalloc is pretty deeply integrated.</div><div><br></div><div>Are you able to reproduce this crash with a debug build of jemalloc (hopefully with more accurate backtrace)?  I'm concerned that this could be a bug in jemalloc, but I can't find a code path that could cause this.  In the absence of additional evidence, my first guess is that huge pages are somehow causing a different initialization order that avoids a bug in jemalloc, but it's possible that huge pages are erroneously causing the arenas array to be erroneously zeroed after initialization, perhaps due to treating an madvise() on any sub-range as a request to discard the entire huge page.</div><div><br></div><div>Thanks,</div><div>Jason</div></body></html>