Hacker News new | ask | show | jobs
by Conscat 4 days ago
Musl does lock on alloc and free paths, yes. It is not a lockless allocator. It doesn't claim to be the very fastest allocator, but it is a reasonably fast modern (slab) allocator with relatively aggressive security mitigations. I assume the lock makes it easier to guarantee these mitigations.
2 comments

jemalloc and tcmalloc are not lockless allocators, but they take care not to lock in the fast path of malloc and free.

BTW mimalloc (a lockless allocator) has a secure mode, not sure how it compares to musl's mitigations.

But it shouldn't take locks in your private arena?
In typical modern allocators like jemalloc or tcmalloc[*], sharded arenas are protected by locks, but the assumption is that with enough sharding there won't be significant lock contention, and also that you can mostly avoid the locks with thread-local caches. (mimalloc uses thread-local arenas instead, so no locks are required for allocations, and atomic RMW ops for cross-thread frees.)

* I'm ignoring rseq here for simplicity.