Repository navigation
Do not charge per-thread accounting state to a Storage memory check scenario - #121364
Conversation
…cenario `Storage memory check` fails unrelated PRs with a byte-constant `change=+1,056`. Since ClickHouse#120487 removed the one-time initialization offset, 9 heads had `+1,056` as their only failing scenario, on `03_add_secondary_indexes.sql` and `04_add_projection.sql`. A pooled thread that runs a mutation step attaches to the task's `ThreadGroup` through `ThreadGroupSwitcher`, and that attach constructs thread-local performance-counter state: `TasksStatsCounters`, a `ProcfsMetricsProvider`, and two `__cxa_thread_atexit_impl` registrations which by construction live until the thread exits. `GlobalThreadPool` keeps its threads, so those bytes stay live once a thread has participated, and the quantity the checkpoint diff measures is how many distinct pool threads have ever served the scenario. Which window a thread's first participation lands in is a scheduling draw. It is one cluster of 7 stacks costing exactly 528 bytes per participating thread: +384 `TasksStatsCounters::create`, -64 `ThreadGroup::SharedData::SharedData`, +64 `detachFromGroup`, +48 `make_shared<ProcfsMetricsProvider>`, +32 and +32 for the two `__cxa_thread_atexit_impl` registrations, +32 for the query-id string copy in `applyQuerySettings`. The gate is `absolute_change > 1024 AND percent_change > 1.0`, so one unit passes and two clear it by 32 bytes: the threshold sits inside the noise quantum. PR ClickHouse#120702 at `b48703670359` has rows for `04_add_projection.sql` at both 528 and 1,056, the same commit measured twice with different answers, so no threshold value could measure this quantity. Raising the threshold is the move that already failed: `150d1f2d0290b` raised this lane from the parser lane's 100 to 1,024 for this exact mechanism, and two units cleared it three days later. Waiting for background tasks to quiesce cannot work either, because this state is registered with `__cxa_thread_atexit_impl` and is not a teardown tail. Pinning the pools to one thread would be C++-side, and the master arm binary is downloaded from the merge base, so such a fix is asymmetric until it reaches master. Instead add the three thread attach/detach frames to the analyzer's existing `EXCLUDED_STACK_FRAME_PREFIXES`, which `compute_diff` already consults before a stack reaches the gated total. Both arms of a run are analysed by the same script from the same checkout, so the change applies symmetrically from the first run, and keying on the allocation site covers every pool at once rather than enumerating pools or settings. On the production reports for ClickHouse#118967, ClickHouse#120960, ClickHouse#121251 and ClickHouse#120702, removing this cluster takes every failing scenario's change to exactly 0, with the largest residual anywhere 64 bytes against the 1,024-byte threshold. Locally, 20 repeated two-pass runs of one binary reproduce the 528-byte unit with the same 7-row composition and a multiplicity that varies run to run; an injected 64 KiB-per-table allocation is still reported at full size; and reverting only these three prefixes restores the pre-fix numbers byte-for-byte. Two consequences are deliberate. The cluster rows also leave the HTML report, exactly as `dumpProfile` overhead already does, because a row the check must not gate on should not be presented as a finding. And thread-accounting regressions are no longer measured here, which the same-commit pair above shows was never possible anyway. `STORAGE_CHANGE_THRESHOLD_BYTES` is left at 1,024. Removing this noise is what would make lowering it toward the parser lane's 100 possible, but that is a calibration decision with its own data. Related: ClickHouse#120487 Related: ClickHouse#119480 Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex, 0 gate findings, plus 3 from my own cold I re-derived the premise from the four production
Two consequences accepted and stated rather than left to be discovered:
Controls verified rather than read off their summaries: the negative-control sweep is md5-identical to the Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260921-105900 |
|
Workflow [PR], commit [e3acd7f] Summary: ✅ AI ReviewSummaryThis PR narrows the shared heap-profile exclusion logic used by the Final VerdictStatus: ✅ Approve |
482d2dd
…scenario Every MergeTree table's BackgroundJobsAssignee keeps running StorageMergeTree::scheduleDataProcessingJob on the schedule pool, and a pass with nothing to merge still builds a merge predicate, a parts collector and ranges (~1.3 KB in the release profiler binary) that it frees on return. The storage profiler dumps the heap as soon as a scenario file returns, so a pass running at that dump on one arm is charged to that scenario and credited back at the next one: a conserved adjacent pair. `06_dictionary.sql` has an 80 KB baseline, so one pass clears both the 1,024-byte and the 1 % bar. Production reports on trees that already contain ClickHouse#120487 and ClickHouse#121364: ClickHouse#122127 `06` +1,296 and ClickHouse#120444 `06` +1,184, each exactly the rows of one selection pass, with `07` the same rows negated. Stop merges on each scenario table once nothing merges or mutates it any more, as ClickHouse#119706 did for `test_many_parts`: on `test_mt` after its last mutation at the end of `04`, and on `test_mt_2` / `test_mt_3` right after their CREATE in `05`. With the blocker set, scheduleDataProcessingJob returns before selectPartsToMerge. After `mutations_sync = 2` returns, the mutation task is in NEED_FINISH, which has no cancellation check, so the STOP in `04` aborts nothing. Both arms of a run read this checkout's scenario files, so the change is symmetric from the first run. `test_mt` stays exposed in `01`..`03`, where it must merge and mutate. Validated locally with one Debug build (no C++ in the diff): a clickhouse local probe of `01`..`05` counts 26-30 selection ranges in a 6 s idle window without the change, 0 with it, and 9-10 with any one STOP removed; with a 1,000-partition probe table, profiler dumps catch a selection pass in flight in 10 of 20 dumps without its STOP and 0 of 20 with it; a real +64 KiB allocation in `06` still FAILs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Exclude allocations made while a pool thread starts, joins or leaves a thread group from the
Storage memory checkcomparison, so a scenario is not charged for the per-thread accounting state of whichever background threads served it.Description
Storage memory checkstill fails unrelated PRs with a byte-constantchange=+1,056. Since #120487 merged, 9 heads had+1,056as their onlyfailing scenario, on
03_add_secondary_indexes.sqland04_add_projection.sql.A pooled thread that runs a mutation step attaches to the task's
ThreadGroup,and that attach constructs thread-local counter state (
TasksStatsCounters, aProcfsMetricsProvider, two__cxa_thread_atexit_implregistrations) that livesuntil the thread exits.
GlobalThreadPoolkeeps its threads, so what getsmeasured is how many pool threads have ever served the scenario, which is a
scheduling draw. It is one cluster of 7 stacks costing exactly 528 bytes per
participating thread: one unit is under the 1,024-byte threshold, two clear it
by 32. #120702 at
b48703670359has rows for04_add_projection.sqlat both528 and 1,056, the same commit measured twice with different answers.
Add the three
ThreadStatusattach, detach and constructor frames to theanalyzer's existing
EXCLUDED_STACK_FRAME_PREFIXES. Job-side, so it applies toboth arms of one run
(the master arm binary comes from the merge base, so a C++ fix would be
asymmetric until it reached master); keyed on the allocation site, so it is
pool-agnostic.
On the production reports for #118967, #120960, #121251 and #120702, removing
this cluster takes every failing scenario's
changeto exactly 0, largestresidual 64 B. Locally, 20 repeated runs reproduce the 528-byte unit with its
multiplicity varying, an injected 64 KiB-per-table allocation is still reported
in full, and reverting only these prefixes restores the old numbers exactly.
Those rows also leave the HTML report, as
dumpProfileoverhead already does.STORAGE_CHANGE_THRESHOLD_BYTESis untouched: removing this noise is what wouldallow lowering it toward the parser lane's 100, but that calibration deserves its
own change.
Workflow [PR]
Sync PR [sync-upstream/pr/121364]
Version info
26.10.1.539-master(included in26.10and later)