Cherry pick #98232 to 26.2: Make jemalloc profiling cover all threads when enabled#98468
Merged
robot-clickhouse merged 6 commits intobackport/26.2/98232from Mar 2, 2026
Merged
Conversation
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>
…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>
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>
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.
Original pull-request #98232
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job