jemalloc/include/jemalloc
Raúl Marín 5aabbc87bf Fix malloc_getcpu on macOS to read the current CPU number correctly
The Apple branch read the CPU number from the low 3 bits of `tpidrro_el0`.
That layout no longer holds on Apple Silicon: those bits read back as 0, so
`malloc_getcpu` returned 0 for every thread. `percpu_arena` then funneled all
allocations into arena 0, or was disabled outright at init.

Read the CPU number the same way as libplatform's `_os_cpu_number`: the low 12
bits of `tpidr_el0` on arm64, or of the IDT base (via `sidt`) on x86. Also move
the Apple branch ahead of the `rdtscp` one so Apple x86 uses `sidt` rather than
`rdtscp`, whose `ecx` is not the CPU id under XNU.
https://github.com/apple-oss-distributions/xnu/blob/main/libsyscall/os/tsd.h

Verified on a 12-CPU M2 Pro: with `percpu_arena:percpu`, `opt.percpu_arena` now
stays `percpu` and `thread.arena` spreads across all 12 arenas {0..11}; the old
code collapsed every thread onto arena 0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-08 13:21:17 -07:00
..
internal Fix malloc_getcpu on macOS to read the current CPU number correctly 2026-07-08 13:21:17 -07:00
jemalloc.sh Move `extern "C" specifications for C++ to where they are needed 2025-03-31 10:41:51 -07:00
jemalloc_defs.h.in Disable config from file or envvar with build flag 2025-02-05 15:01:50 -08:00
jemalloc_macros.h.in Make JEMALLOC_CXX_THROW definition compatible with newer C++ versions 2024-06-13 11:03:05 -07:00
jemalloc_mangle.sh jemalloc_mangle.sh: set sh in strict mode 2017-12-11 23:35:20 -08:00
jemalloc_protos.h.in Move `extern "C" specifications for C++ to where they are needed 2025-03-31 10:41:51 -07:00
jemalloc_rename.sh Fix name mangling for stress tests. 2014-01-16 17:38:01 -08:00
jemalloc_typedefs.h.in Introduce pinned extents to contain unpurgeable pages 2026-05-05 10:44:28 -07:00