Make jemalloc profiling cover all threads when enabled#98232
Merged
alexey-milovidov merged 5 commits intomasterfrom Mar 2, 2026
Merged
Make jemalloc profiling cover all threads when enabled#98232alexey-milovidov merged 5 commits intomasterfrom
alexey-milovidov merged 5 commits intomasterfrom
Conversation
Contributor
When `jemalloc_enable_global_profiler` is set, the profiler must be activated before any threads are created — otherwise those threads won't be sampled. Move the `Jemalloc::setup` call to early in `BaseDaemon::initialize` (right after `loadConfiguration`) so that profiling is enabled before thread pools and background threads start. Guard `setup` with `std::call_once` so the later call from server settings is a safe no-op (with warnings if settings diverge). Extract default constants to `Jemalloc.h` and reuse them in `ServerSettings.cpp` and `BaseDaemon.cpp` to keep them in sync. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
d6c0b70 to
cb62786
Compare
antonio2368
commented
Feb 27, 2026
…USE_JEMALLOC guard The default constants (`default_enable_global_profiler`, etc.) are referenced by `ServerSettings.cpp` unconditionally, but were defined inside `#if USE_JEMALLOC`. Sanitizer builds don't use jemalloc, so the `Jemalloc` namespace was undefined, causing compilation failures. Move the constants before the guard so they are always available. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
azat
approved these changes
Feb 28, 2026
Add assertion before the warning in `Jemalloc::setup` to catch mismatches between server settings defaults and the manually defined config names in `BaseDaemon` early in debug builds. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The previous implementation used `std::call_once` which fired in the parent process during `BaseDaemon::initialize`. After the watchdog `fork`, jemalloc state (e.g. `background_thread`) resets in the child but the `once_flag` remains set, so the verification check saw a mismatch and fired `chassert`. Split `setup` and `verifySetup` into separate functions: - `setup` always applies settings (idempotent), called in `BaseDaemon::initialize` and re-applied after watchdog fork - `verifySetup` checks jemalloc state matches server settings, called from `Server::main` and `Keeper::main` Also extract config key names into constants in `Jemalloc.h` to keep them in sync between `BaseDaemon` and `ServerSettings`. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98232&sha=b69293471789706abde22ec86f33104dbfaf0382&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
robot-clickhouse
added a commit
that referenced
this pull request
Mar 2, 2026
Cherry pick #98232 to 26.2: Make jemalloc profiling cover all threads when enabled
robot-clickhouse
added a commit
that referenced
this pull request
Mar 2, 2026
clickhouse-gh bot
added a commit
that referenced
this pull request
Mar 2, 2026
Backport #98232 to 26.2: Make jemalloc profiling cover all threads when enabled
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.
When
jemalloc_enable_global_profileris set, the profiler must be activated before any threads are created — otherwise those threads won't be sampled. Move theJemalloc::setupcall to early inBaseDaemon::initialize(right afterloadConfiguration) so that profiling is enabled before thread pools and background threads start.Guard
setupwithstd::call_onceso the later call from server settings is a safe no-op (with warnings if settings diverge).Extract default constants to
Jemalloc.hand reuse them inServerSettings.cppandBaseDaemon.cppto keep them in sync.Changelog category (leave one):
It seems we do miss some of the threads, most problematic the async logger thread.
Documentation entry for user-facing changes