Repository navigation
Conversation
`Dwarf::getSection` returned an empty view for every SHF_COMPRESSED section, so a debug file written by `objcopy --compress-debug-sections` (zlib or zstd) disabled `Dwarf` and stack traces, `addressToLine` and `addressToLineWithInlines` lost file names, line numbers and inlined frames. ClickHouse#126943 compresses the packaged `clickhouse.debug` with zstd, so this has to work first. The decompressed bytes live in `Elf`, not in `Dwarf`: `StackTrace::forEachFrame` builds a fresh `Dwarf` for every trace, which is why the per-`Dwarf` decompression of ClickHouse#109306 (c8de703) was reverted (2c5f535). `SymbolIndex` keeps its `Elf` objects for the whole process, so the sections are decompressed once. `Elf::getSectionsData(names)` handles the whole set in one call: - the headers are scanned by name; a named section that runs past the end of the file fails the call (`findSectionByName` would skip it, and a later unguarded `substr` on a DWARF 5 side table would throw); - with no compressed section among the names it returns the raw views without locking or allocating, as before; - otherwise, under the `Elf`'s mutex, it checks every pending header (type ZLIB or ZSTD, size at most 1024 times the payload, the same bound as `decompressGNUDebugData`), checks the summed size against the hard limit of `total_memory_tracker` explicitly (the tracker does not throw while an exception is being formatted, `getExceptionStackTraceString`), decompresses into local `Memory<>` buffers (`ZSTD_decompress`; chunked `inflate`, because the one-shot `uncompress` fails above 2 GiB) and publishes them with a noexcept swap only if all succeed. Any failure erases the placeholders and marks the sections unreadable for good: the symbolization results are cached anyway (`StackTraceCache`, `AddressToLineCache`), so a retry could not reach them. Nothing throws out of it. The `Dwarf` ELF constructor makes that one call under a `User`-level `MemoryTrackerBlockerInThread`, so the memory is charged to the server and not to the query that happens to symbolize first; on nullopt `Dwarf` is disabled (fail closed). Fuzzer builds keep skipping compressed sections: libFuzzer's RSS limit (2-8 GiB) would turn every finding into an out-of-memory report, and the fuzzer binaries are linked with `--compress-debug-sections=zlib`. `.debug_loclists` (380 MiB decompressed in the 26.11 amd64 file) is no longer read: `DW_FORM_loclistx` was resolved into a `DW_AT_location` value that nothing reads. Measured on the 26.11 amd64 `clickhouse.debug`: the needed sections decompress to 3.48 GiB in about 4 s; on a debug build 4.86 GiB. Related: ClickHouse#126943 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; 2 findings), plus my own review (4 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261115-015200 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261115-005700 |
|
Workflow [PR], commit [308984d] Summary: ❌
AI Review
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes11 object files changed (+48.23 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units27 translation units recompiled, 97 s compile time in total, 27 of them have a recent master baseline. |
The memory-limit case set the global hard limit to `total_memory_tracker.get() + 1024`. `unit_tests_dbms` runs every suite in one process, and by the time this test runs in `Unit tests (amd_debug)` the tracked amount is negative (measured in gdb with the suites registered before it: amount -1460216, RSS 310010171), so the limit became negative, which `getSectionsData` treats as "no limit", and the section decompressed. The asan, msan and tsan unit-test jobs passed on the same head. Set the limit just above `max(get(), getRSS())`, which is what `decompressSections` compares against (as `gtest_memory_tracker.cpp` does). Disabling that check still fails the test, both alone and after the preceding suites. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`decompressSections` checked the server limit once, then allocated each buffer just before decompressing it, so other threads could use the headroom during the codec work (seconds for a real `clickhouse.debug`). The memory tracker does not throw while an exception is formatted, so the later buffers were charged past `max_server_memory_usage`. Allocate every buffer first and check the limit again with them charged; if other allocations got there first, free them and refuse. Measured with a two-thread experiment (zstd sections of 256 and 64 MiB, hard limit = both + 32 MiB, a competing 64 MiB allocation once the first buffer is charged): before, 10/10 runs had both allocations succeed and ended 32 MiB over the limit; after, 30/30 runs refused the decompression and stayed under it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The sections were allocated by the thread that symbolizes, under a `MemoryTrackerBlockerInThread(VariableContext::User)` in the `Dwarf` constructor. Buffers smaller than `max_untracked_memory` stayed in the untracked memory of that thread and were flushed when the blocker ended, and since 8de7e8b every such flush counts toward `untracked_memory_flushed_unchecked`. Once that passes `untracked_memory_limit`, each enforced allocation of the thread checks the limit of its query, until one check passes. So the first stack trace through a frame whose separate debug file is compressed (libc's from libc6-dbg here: about 2 MB of sections) made an `INSERT ... SETTINGS max_memory_usage = 1000` and the next ones on the same pooled TCP thread fail with `MEMORY_LIMIT_EXCEEDED`; `test_failed_async_inserts` counted 1 failed async insert instead of 4. A thread without a `ThreadStatus` charges its allocations to the server tracker directly, and with no `LockMemoryExceptionInThread` there, the tracker checks every buffer against the server limit as it is allocated. So the `Dwarf` constructor needs no blocker, and the second explicit check, made after allocating every buffer, is dropped. Measured with the four `INSERT`s of the test against a debug server: 1 of 4 counted and 7 `MEMORY_LIMIT_EXCEEDED` log lines on the previous head, 4 of 4 and none on master and with this change; libc frames keep their file:line. With a zstd or zlib compressed binary, a query capped at 1 GB still resolves `addressToLine` while `MemoryTracking` grows by 4.9 GiB, and with `max_server_memory_usage = 4G` the decompression is refused. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A thread with its own `ThreadStatus` reads a 1 MiB zstd section and measures what its tracker was charged. Decompressing on the calling thread, as before the previous commit, charges it 1,048,719 bytes and fails the test; on a thread of its own it is charged a few small vectors. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 308984dEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261115-153013 |
Related: #126943
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Stack traces,
addressToLineandaddressToLineWithInlinesnow show file names, line numbers and inlined frames when the debug sections are compressed with zstd or zlib (objcopy --compress-debug-sections). The sections are decompressed once per process, on the first symbolization.Description
Asked in #126943 (comment).
Dwarf::getSectiontreated everySHF_COMPRESSEDsection as absent, so a compressed debug file gave no file:line. The companion PR that compresses the packagedclickhouse.debugwith zstd should merge after this one or together with it; otherwise installed packages lose file:line in between.Elf::getSectionsDatareturns the named sections together. It decompresses zlib and zstd sections once and keeps them for the lifetime of theElf, whichSymbolIndexholds for the whole process. TheDwarfELF constructor makes one such call. A set is kept only if every section decompresses. A broken header, an unknown type, a size over 1024 times the payload, a truncated section or a decompression error disablesDwarf(no file:line, as today) instead of throwing during symbolization. The memory is charged to the server, not to the query that symbolizes first, and the decompression is refused, for the rest of the process, when it would exceedmax_server_memory_usage..debug_loclistsis no longer read: its index was resolved into a value nothing reads. Fuzzer builds keep skipping compressed sections because of libFuzzer's RSS limit.Cost: on the first symbolization, the sections needed from the 26.11 amd64
clickhouse.debugdecompress to 3.48 GiB in about 4 s; that memory stays allocated for the life of the process and counts towardmax_server_memory_usage.Validation: a new gtest builds ELF images with a DWARF 4 unit (uncompressed, zlib, zstd) and fails on master for the compressed ones; it also covers the rejection and caching cases. A debug build compressed with
llvm-objcopy --compress-debug-sections=zstdorzlib, and the package layout with a separate compressed.debug, show the same file:line inaddressToLineand exception stack traces as the uncompressed binary; a master binary compressed the same way shows none.Workflow [PR]
Sync PR [sync-upstream/pr/131722]