mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-10-28 16:55:15 +08:00
Under LTO `&tsd_tls` is hoisted out of the inlined malloc/free and survives swapcontext in a callee-saved register: a fiber resumed on another OS thread races on the old thread's tcache. Fix it by taking the address in a noinline volatile-asm barrier accessor. It is done under option (--enable-experimental-fiber-safe-tls), because it make the fastpath slower, on a microbench (that is very heavy depends on the most optimal case) the overhead is 35%, but this is unlikely the real world scenario. Anyway here are some numbers for microbench.c compiled with LTO: type |vanilla (ns)|`--enable-experimental-fiber-safe-tls` (ns)|optimized (ns) [1] --------|------------|-------------------------------------------|------------------ malloc |6.51 |8.77 **(+34%)** |6.79 (4%) mallocx |8.48 |10.62 **(25%)** |8.76 (3%) free |6.46 |8.68 **(34%)** |6.76 (5%) dallocx |8.190 |10.97 **(33%)** |8.74 (7%) [1]: https://github.com/jemalloc/jemalloc/pull/2944 This patch also adds a separate lane for CI with LTO