No description
Find a file
LD-RW 65a7d19928 bin: enforce bin->lock ownership in bin_slab_reg_alloc()
bitmap_set() performs a plain (non-atomic) read-modify-write on every
level of the bitmap tree:

    g  = *gp;            /* READ                              */
    g ^= ZU(1) << bit;  /* MODIFY — thread-local copy        */
    *gp = g;             /* WRITE BACK — no barrier, no CAS  */

Two threads that reach bitmap_sfu() -> bitmap_set() concurrently on the
same slab bitmap — even for different bits that share a group word —
will clobber each other's write.  The clobbered bit still looks free on
the next allocation; bitmap_sfu() selects it again; the second call to
bitmap_set() aborts on:

    assert(!bitmap_get(bitmap, binfo, bit));   /* bitmap.h:220 */

or, once tree propagation begins for a newly-full group:

    assert(g & (ZU(1) << (bit & BITMAP_GROUP_NBITS_MASK)));  /* bitmap.h:237 */

Either assert calls abort() and produces the coredump reported in
issues #2875 and #2772.

The immediate callers (bin_malloc_with_fresh_slab,
bin_malloc_no_fresh_slab) already assert lock ownership, but
bin_slab_reg_alloc() itself had no such check, making it easy for new
call sites to silently bypass the requirement.

Fix:
- Thread tsdn_t *tsdn and bin_t *bin through bin_slab_reg_alloc() and
  call malloc_mutex_assert_owner() as the first statement.
- Update both internal callers (bin_malloc_with_fresh_slab,
  bin_malloc_no_fresh_slab) to pass the context they already hold.
- Document the locking contract in bin.h and the thread-safety
  constraint in bitmap.h directly above bitmap_set().

Note: bin_slab_reg_alloc_batch() is left unchanged because it has one
legitimate unlocked caller (arena_fill_small_fresh) which operates on
freshly allocated slabs that are not yet visible to any other thread.
Its locking contract is now documented in bin.h.

Fixes #2875
2026-04-10 20:45:51 +03:00
.github/workflows Add a script to generate github actions instead of Travis CI and Cirrus 2026-03-10 18:14:33 -07:00
bin Updated jeprof with more symbols to filter. 2024-10-14 10:31:58 -07:00
build-aux Update config.guess and config.sub to the latest versions 2026-03-10 18:14:33 -07:00
doc Documentation updates (#2869) 2026-04-07 10:41:44 -07:00
doc_internal update PROFILING_INTERNALS.md 2022-10-03 10:48:29 -07:00
include bin: enforce bin->lock ownership in bin_slab_reg_alloc() 2026-04-10 20:45:51 +03:00
m4 Support C++17 over-aligned allocation 2019-11-22 10:14:16 -08:00
msvc Remove prof_threshold built-in event. It is trivial to implement it as user event if needed 2026-03-10 18:14:33 -07:00
scripts Add a script to generate github actions instead of Travis CI and Cirrus 2026-03-10 18:14:33 -07:00
src bin: enforce bin->lock ownership in bin_slab_reg_alloc() 2026-04-10 20:45:51 +03:00
test Emit retained HPA slab stats in JSON 2026-04-01 23:15:19 -04:00
.appveyor.yml Update appveyor settings. 2026-03-10 18:14:33 -07:00
.autom4te.cfg Disable autom4te cache. 2014-09-02 17:49:29 -07:00
.clang-format Modify .clang-format to have declarations aligned 2025-05-28 19:22:21 -07:00
.git-blame-ignore-revs Ignore the clang-format changes in the git blame. 2026-03-10 18:14:33 -07:00
.gitattributes fix git handling of newlines on windows 2014-05-07 18:48:39 -04:00
.gitignore Adding trace analysis in preparation for page allocator microbenchmark. 2026-03-10 18:14:33 -07:00
.travis.yml Remove Travis Windows CI for now since it has infra failures. 2026-03-10 18:14:33 -07:00
autogen.sh build: Make autogen.sh accept quoted extra options 2024-01-03 14:20:34 -08:00
ChangeLog Update ChangeLog for 5.3.0. 2022-05-06 11:24:21 -07:00
config.stamp.in Move repo contents in jemalloc/ to top level. 2011-03-31 20:36:17 -07:00
configure.ac configure: add --with-cxx-stdlib option 2026-03-10 18:14:33 -07:00
COPYING Update copyright dates. 2019-01-25 13:25:20 -08:00
INSTALL.md Update the configure cache file example in INSTALL.md 2024-10-10 16:41:48 -07:00
jemalloc.pc.in Expose jemalloc_prefix via pkg-config 2023-09-05 14:30:21 -07:00
Makefile.in Fix missing negation in large_ralloc_no_move usize_min fallback 2026-04-01 23:15:19 -04:00
README switch to https 2023-03-09 11:44:02 -08:00
run_tests.sh Introduce scripts to run all possible tests 2017-01-30 17:51:57 -08:00
TUNING.md switch to https 2023-03-09 11:44:02 -08:00

jemalloc is a general purpose malloc(3) implementation that emphasizes
fragmentation avoidance and scalable concurrency support.  jemalloc first came
into use as the FreeBSD libc allocator in 2005, and since then it has found its
way into numerous applications that rely on its predictable behavior.  In 2010
jemalloc development efforts broadened to include developer support features
such as heap profiling and extensive monitoring/tuning hooks.  Modern jemalloc
releases continue to be integrated back into FreeBSD, and therefore versatility
remains critical.  Ongoing development efforts trend toward making jemalloc
among the best allocators for a broad range of demanding applications, and
eliminating/mitigating weaknesses that have practical repercussions for real
world applications.

The COPYING file contains copyright and licensing information.

The INSTALL file contains information on how to configure, build, and install
jemalloc.

The ChangeLog file contains a brief summary of changes for each release.

URL: https://jemalloc.net/