Skip to content

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
cherrypick/26.2/98232
Mar 2, 2026
Merged

Cherry pick #98232 to 26.2: Make jemalloc profiling cover all threads when enabled#98468
robot-clickhouse merged 6 commits intobackport/26.2/98232from
cherrypick/26.2/98232

Conversation

@robot-ch-test-poll3
Copy link
Copy Markdown
Contributor

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

antonio2368 and others added 6 commits February 27, 2026 16:34
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
@robot-ch-test-poll3 robot-ch-test-poll3 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels Mar 2, 2026
@robot-clickhouse robot-clickhouse merged commit 93b0993 into backport/26.2/98232 Mar 2, 2026
11 checks passed
@robot-clickhouse robot-clickhouse deleted the cherrypick/26.2/98232 branch March 2, 2026 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants