mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-13 12:17:18 +03:00
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> |
||
|---|---|---|
| .. | ||
| jemalloc | ||
| msvc_compat | ||