Repository navigation
Integrate jemalloc with je_ prefix and remove usage of linker's --wrap - #99342
Merged
Merged
Conversation
Contributor
|
Workflow [PR], commit [c6e3ef6] Summary: ✅ AI ReviewSummaryThis PR migrates allocator integration from linker Missing context
ClickHouse Rules
Final Verdict
|
azat
force-pushed
the
jemalloc-je-prefix
branch
from
March 12, 2026 18:38
0e04c5d to
7715a30
Compare
azat
force-pushed
the
jemalloc-je-prefix
branch
from
March 12, 2026 18:43
7715a30 to
a56aec5
Compare
azat
force-pushed
the
jemalloc-je-prefix
branch
2 times, most recently
from
March 12, 2026 23:58
50f1f21 to
96bc08b
Compare
azat
force-pushed
the
jemalloc-je-prefix
branch
from
March 13, 2026 09:38
96bc08b to
60aa4a2
Compare
Simplify jemalloc integration by replacing the three-mechanism approach (`JEMALLOC_IS_MALLOC` + `JEMALLOC_OVERRIDE___LIBC_*` + linker `--wrap`) with a cleaner two-step design: 1. Compile jemalloc with `je_` prefix so it only exports `je_malloc`, `je_free`, etc. (matching what Darwin already does). 2. Define our own `malloc`/`free` in `malloc.cpp` that perform memory tracking and delegate to `je_malloc`/`je_free`. Provide `__libc_*` aliases on glibc to intercept internal calls. Changes: - Enable `JEMALLOC_PREFIX "je_"` in all non-Darwin `jemalloc_internal_defs.h.in` - Undef `JEMALLOC_IS_MALLOC` and all `JEMALLOC_OVERRIDE___LIBC_*` defines - Remove `JEMALLOC_OVERRIDE_MEMALIGN`/`VALLOC`/`PVALLOC` from `jemalloc_defs.h` - Add `JEMALLOC_NO_RENAME` interface define so consumer code sees `je_*` names - Prefix all jemalloc API calls (`mallctl` -> `je_mallctl`, etc.) in ClickHouse - Rewrite `memory.h` to call `je_malloc`/`je_free` directly instead of `__real_*` - Rewrite `malloc.cpp` with tracking wrappers calling `je_*` underneath - Rewrite `AllocationInterceptors.h` to map `__real_*` -> `je_*` or `::*` - Remove `__wrap_*` functions from `AllocationInterceptors.cpp` - Remove `--wrap` linker flags from `CMakeLists.txt` - Add jemalloc + clickhouse_common_io deps to `clickhouse_malloc` OBJECT library - And also fix JEMALLOC_CPREFIX for Darwin, that was the only platform that uses JE_MALLOC_CONF (over MALLOC_CONF) Co-Authored-By: Claude <[email protected]>
azat
force-pushed
the
jemalloc-je-prefix
branch
from
March 13, 2026 09:51
60aa4a2 to
c6e3ef6
Compare
Contributor
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 57.81% (174/301, 0 noise lines excluded) |
antonio2368
approved these changes
Mar 16, 2026
azat
enabled auto-merge
March 16, 2026 13:28
azat
added a commit
to azat/ClickHouse
that referenced
this pull request
Apr 9, 2026
…emalloc-submodule-url" This reverts commit 4bb7431, reversing changes made to aef8cc3. New version likely has some issues, I have a test that reproduce a crashes, but with this patch it happens in jemalloc, before (but after ClickHouse#99342) in random places. Next step will be to try jemalloc debug mode, since likely when the crash happens inside jemalloc, it is less likely will help.
This was referenced Apr 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Integrate jemalloc with
je_prefix and remove usage of linker's --wrapSimplify jemalloc integration by replacing the three-mechanism approach (
JEMALLOC_IS_MALLOC+JEMALLOC_OVERRIDE___LIBC_*+ linker--wrap) with a cleaner two-step design:Compile jemalloc with
je_prefix so it only exportsje_malloc,je_free, etc. (matching what Darwin already does).Define our own
malloc/freeinmalloc.cppthat perform memory tracking and delegate toje_malloc/je_free. Provide__libc_*aliases on glibc to intercept internal calls.Changes:
JEMALLOC_PREFIX "je_"in all non-Darwinjemalloc_internal_defs.h.inJEMALLOC_IS_MALLOCand allJEMALLOC_OVERRIDE___LIBC_*definesJEMALLOC_OVERRIDE_MEMALIGN/VALLOC/PVALLOCfromjemalloc_defs.hJEMALLOC_NO_RENAMEinterface define so consumer code seesje_*namesmallctl->je_mallctl, etc.) in ClickHousememory.hto callje_malloc/je_freedirectly instead of__real_*malloc.cppwith tracking wrappers callingje_*underneathAllocationInterceptors.hto map__real_*->je_*or::*__wrap_*functions fromAllocationInterceptors.cpp--wraplinker flags fromCMakeLists.txtclickhouse_mallocOBJECT libraryAlternative to #98915 (but not complete, it does not touches memory tracker)
Note
High Risk
High risk because it changes the process-wide allocator interposition and memory tracking path (
malloc/free,realloc, alignment allocators), which can impact correctness, performance, and platform-specific linking behavior (glibc/musl/FreeBSD/Darwin).Overview
Reworks allocator interposition to use
je_-prefixed jemalloc symbols everywhere. jemalloc is now built/consumed withJEMALLOC_PREFIX="je_"andJEMALLOC_NO_RENAME, and ClickHouse call sites are updated frommallctl/mallocx/malloc_stats_print/malloc_messageto the correspondingje_*APIs.Removes linker
--wrapallocation hooks and moves C allocation tracking into code. The--wrap=malloc/free/etc. link options and__wrap_*implementations are deleted;Common/malloc.cppnow defines interposedmalloc/free/calloc/realloc/posix_memalign/aligned_alloc/valloc/memalign/pvalloc/reallocarray/malloc_usable_sizethat track memory and delegate toje_*, plus__libc_*aliases on glibc.Build/link wiring is adjusted so
clickhouse_malloclinks jemalloc when available, and the parser memory-profiler scripts/docs are updated to useMALLOC_CONFconsistently.Written by Cursor Bugbot for commit c6e3ef6. This will update automatically on new commits. Configure here.
Version info
26.3.1.716