Repository navigation
Conversation
lld runs the ThinLTO backends (optimization and code generation of every module) inside the linker process, one thread per core, and those threads contend in glibc malloc. When the build host has `libjemalloc.so.2`, ThinLTO links now run with it preloaded: a linker launcher `cmake -E env LD_PRELOAD=<lib>` wraps only the link command (never PRE_LINK or POST_BUILD, so the official builds' `clickhouse hash-binary` check runs without it). The allocator of the linker does not change what lld computes, so the linked output is the same. `clickhouse/binary-builder` installs `libjemalloc2`. The option `ENABLE_THINLTO_LINK_JEMALLOC` (default ON) turns it off; a linker launcher set by the user (C or C++) is kept and disables the preload; a host without the library is unaffected. Measured on x86 (Xeon 6975P), PR amd_release configuration, the clickhouse link pinned to the 32 physical cores of one NUMA node, 3 concurrent pairs: apt ld.lld-22 median 303.5 s -> 276.4 s (-8.9%), peak RSS 20.7 -> 14.8 GiB; CI toolchain lld 283.7 s -> 252.9 s (-10.9%), peak RSS 21.1 -> 15.1 GiB. The outputs are byte-identical with and without the preload. Patch and ARM numbers by @ snelheidai (-25% / -20% on Graviton3), ClickHouse#130064 (comment) Related: ClickHouse#130064 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; 1 finding) plus my own review (3 nits).
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-41:20261111-053900 |
|
Workflow [PR], commit [855229b] Summary: ✅
AI ReviewSummaryPR #130705 preloads the host's Missing context / blind spots
Final VerdictStatus: ✅ Approve. No required code changes. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline. |
|
@groeneai, can we instead build our toolchain with jemalloc? See the toolchain build GitHub Actions job. If we can, send another PR. |
|
@groeneai, data for @alexey-milovidov's question above: jemalloc in the toolchain's I built Wall time of
On each host every jemalloc build was faster than every glibc build, and the CommandsJE=/usr/lib/aarch64-linux-gnu/libjemalloc.so.2 # x86_64: /usr/lib/x86_64-linux-gnu/libjemalloc.so.2
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCOMPILER_CACHE=disabled \
-DCMAKE_C_COMPILER=<toolchain>/bin/clang -DCMAKE_CXX_COMPILER=<toolchain>/bin/clang++ \
-DCMAKE_C_COMPILER_LAUNCHER="env;LD_PRELOAD=$JE" -DCMAKE_CXX_COMPILER_LAUNCHER="env;LD_PRELOAD=$JE" \
-DCMAKE_ASM_COMPILER_LAUNCHER="env;LD_PRELOAD=$JE" \
-DCMAKE_C_LINKER_LAUNCHER="env;LD_PRELOAD=$JE" -DCMAKE_CXX_LINKER_LAUNCHER="env;LD_PRELOAD=$JE"
/usr/bin/time ninja -C build clickhouseThe glibc builds use the same commands without the five launcher options. The Graviton3 builds ran with |
|
@groeneai, that's really great, let's do it. |
|
Acknowledged. I'm investigating linking the toolchain's |
|
The toolchain PR is #131183: |
|
Closing in favor of #131183 |
Related: #130064
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
ThinLTO builds link faster and with less memory when the build host has jemalloc: the linker runs with
libjemalloc.so.2preloaded, and theclickhouse/binary-builderimage now installslibjemalloc2. The linked binary is unchanged.-DENABLE_THINLTO_LINK_JEMALLOC=0turns it off.Description
lld runs the ThinLTO backends (optimization and code generation of every module) inside the linker process, one thread per core, and those threads contend in glibc
malloc.In the ThinLTO + lld block of
CMakeLists.txt, when a Linux host haslibjemalloc.so.2and no linker launcher is set,CMAKE_C_LINKER_LAUNCHER/CMAKE_CXX_LINKER_LAUNCHERbecomecmake -E env LD_PRELOAD=<lib>. The launcher wraps only the link command, never PRE_LINK or POST_BUILD, so the official builds'./clickhouse hash-binarystep runs without it.clickhouse/binary-builderinstallslibjemalloc2. A host without the library, a user-set launcher, or-DENABLE_THINLTO_LINK_JEMALLOC=0leaves the build as it was. Affected CI builds:amd_release,arm_release(and their performance-reference builds),amd_cfi, and the BOLT build ofOptimizeClickHouse.Validation on x86 (Xeon 6975P), PR
amd_releaseconfiguration, theclickhouselink pinned to the 32 physical cores of one NUMA node, 3 pairs run concurrently on two nodes, nodes swapped:ld.lld-22(what CI links with today): median 303.5 s -> 276.4 s (-8.9%), peak RSS 20.7 -> 14.8 GiB (-29%).ld.lld(Use the linker and LLVM tools from the compiler's own toolchain #130659): 283.7 s -> 252.9 s (-10.9%), peak RSS 21.1 -> 15.1 GiB.Configured both on the host (cmake 3.28) and inside the CI image (cmake 4.4.5): only ThinLTO link rules carry the preload.
On Graviton3, where the contention is larger, the reporter measured -25% with the toolchain lld (peak memory 29.4 -> 17.0 GB) and -20% with apt lld for an
arm_release-like link: #130064 (comment).Workflow [PR]
Sync PR [sync-upstream/pr/130705]