Repository navigation
Conversation
…tic TLS size glibc allocates the static TLS block at the top of every thread's stack, so the executable's PT_TLS size decides where each thread's stack starts, and with it the placement of every frame the query threads run. A PR that adds or grows a thread_local therefore runs the reference and the patched server at different stack placements, and a loop that is sensitive to placement shows up as a regression of code the PR does not touch. That is the set_in_clustered_keys ClickHouse#2/ClickHouse#3 false red on arm, e.g. PR ClickHouse#116800, https://github.com/ClickHouse/ClickHouse/actions/runs/36285090202/job/108594291203 (confirmed_regression ClickHouse#2 0.0611 -> 0.0799 s, +30.7%; ClickHouse#3 marked slower too). Since master 2026-09-25 18:36 UTC, 7 arm builds of 6 unrelated PRs ran the keys256 `(k, u) IN (SELECT DISTINCT k, u ...)` queries 20-32% slower, the extra time all in Set::executeImplCase<SetMethodKeysFixed<keys256>, true>, whose machine code is identical in all 47 arm builds examined. All 7 grew the static TLS (+64 to +61504 bytes; in ClickHouse#116800 the thread_local instance of ResourceGuard::Request::local(), 232 -> 320 bytes). Builds of the same bases that kept master's size were fast, and the same TLS growth was fast on older bases whose call chain was 16 or 256 bytes shallower. In the red run the two compared binaries have the same call-chain frame sizes, so the static TLS size is the only difference in where their threads' frames land. Start the server with the smaller static TLS with a larger static TLS surplus, GLIBC_TUNABLES=glibc.rtld.optional_static_tls=512+pad (512 is the default), so the threads of both servers start at the same placement. pad follows the glibc 2.39 layout: the difference of the two sizes rounded to the executable's TLS alignment on x86_64 (TLS variant II), rounded to 16 on aarch64 (variant I, libc's block follows the executable's). The new ci/jobs/scripts/perf/static_tls.py reads both PT_TLS headers and serves both server start sites: CHServer (the measured runs) and compare.sh restart (the confirm_changes rerun, the profile retry and the standalone flow). It fails closed: when the two binaries cannot be compared (not ELF, still compressed, different machine or TLS alignment, unsupported arch), neither server is started. Nothing changes when the sizes are equal, which is every PR that does not touch a thread_local and every master run. Validation: - Toys with the same PT_TLS shape, on glibc 2.39 (the ubuntu:24.04 perf image; aarch64 under qemu-aarch64-static): with the helper's padding the two toys of each pair of 33 sizes start their threads at the same page offset, 528 of 528 pairs on each arch, in both argument orders. - The CI binaries of the red run: arm reference 0xbb38 vs ClickHouse#116800 0xbb88 bytes gives 80 bytes of surplus to the reference, amd 0xb970 vs 0xb9d0 gives 128, ClickHouse#122492 on the same base gives none. - Running the amd binaries: with the 128 bytes the reference's pool threads block at exactly the stack offsets of ClickHouse#116800's threads, unpadded they are 128 bytes apart. The x86 timing of ClickHouse#2/ClickHouse#3 does not depend on this placement (same for all three); the slow mode is arm-only in CI. Not covered: placement shifts from frame-size changes along the call chain, and the code placement of a hot function. This removes the TLS-size confound only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings), plus my own review (4 nits, none blocking).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260927-170300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20260927-161900 |
|
Workflow [PR], commit [cc9b1ab] Summary: ✅
AI ReviewSummaryThe PR equalizes thread stack placement by adjusting static TLS surplus before both performance-comparison server starts. One existing correctness concern remains: Linux alone does not establish that the servers honor the glibc tunable. No additional inline findings were identified. Findings
Tests
Final VerdictStatus: |
CI finish ledger - ba96fe2Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260927-210023 |
…-tls-size Co-Authored-By: Claude Opus 5.5 <[email protected]>
GLIBC_TUNABLES only means something to glibc. Since a668c33 both perf entry points start their servers on a local macOS run (no taskset there), but the static TLS helper rejected the Mach-O binaries, so `compare.sh` restart and the Start step of `performance_tests.py` refused to launch either server. The helper now returns no tunables when the host is not Linux; on Linux it still fails closed when the two binaries cannot be compared. A `glibc.rtld.optional_static_tls` already set in the environment is now refused only when padding is needed: with equal sizes both servers inherit the same value, so their layouts still match. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
|
||
| def static_tls_tunables(left, right): | ||
| """Return the GLIBC_TUNABLES values for the (left, right) servers, "" where none is needed.""" | ||
| if os.uname().sysname != "Linux": |
There was a problem hiding this comment.
On Linux/musl this branch still tries to equalize the two servers with GLIBC_TUNABLES, but musl ignores glibc.rtld.optional_static_tls. That means both perf entry points keep running on a non-glibc Linux host even though the smaller binary was not actually padded, so the new invariant here (same static TLS layout, or do not start either server) no longer holds there. Can we detect glibc explicitly here, for example with os.confstr('CS_GNU_LIBC_VERSION') or platform.libc_ver(), and send non-glibc Linux through the current unsupported-host path instead?
|
Already done via #128022 and now we use musl |
Related: #116800
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not required: CI-only change.
Description
On #116800 the dashboard scored
set_in_clustered_keys #2as a confirmed regression and failed arm 1/6: 0.0611 s on the old server, 0.0799 s on the new one (+30.7%); the shard's report also flags #3. Since master 2026-09-25 18:36 UTC, 7 arm builds of 6 unrelated PRs ran both queries 20-32% slower. The extra time is inSet::executeImplCaseforkeys256, whose machine code is identical in all 47 arm builds examined.glibc puts the static TLS block at the top of every thread's stack, so the executable's
PT_TLSsize decides where every frame of the query threads lands. All 7 slow builds grew their static TLS (in #116800, thethread_localinResourceGuard::Request::local(), 232 -> 320 bytes). The two binaries of the red run have the same call-chain frame sizes, so the TLS size is the only placement difference.A new helper reads both binaries'
PT_TLSand starts the smaller one withGLIBC_TUNABLES=glibc.rtld.optional_static_tls=<512 + difference>(rounded as glibc lays the blocks out), so both servers' threads start at the same placement. Both server start paths use it:CHServerfor the measured runs, andcompare.shrestartfor the confirmation rerun. On Linux it fails closed: if the two binaries cannot be compared, neither server starts. Nothing changes when the sizes are equal.Validation:
PT_TLSshape on glibc 2.39: equal thread placement for 528 of 528 size pairs, on x86_64 and on aarch64 (qemu);It removes the TLS-size confound only, not placement shifts from call-chain frame sizes or code placement, nor the
clickhouse localprocesses of shell-script queries.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122550]