Skip to content

Build the CI toolchain with jemalloc 5.4.0 using transparent huge pages - #131745

Merged
alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
groeneai:ci-toolchain-jemalloc-5.4.0
Nov 17, 2026
Merged

alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
groeneai:ci-toolchain-jemalloc-5.4.0

Conversation

@groeneai

@groeneai groeneai commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #131183
Related: #130064

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

The CI toolchain's clang and lld use jemalloc 5.4.0 built from source, with transparent huge pages for the heap and its metadata.

Description

Follow-up to #131183, with the option chosen in #131183 (comment). The toolchain job now builds jemalloc 5.4.0 from the release tarball (pinned by sha256) and links its libjemalloc_pic.a into the stage 2 executables instead of Ubuntu's 5.3.0, configured with --with-malloc-conf=thp:always,metadata_thp:always: jemalloc asks for transparent huge pages for its extents and metadata (madvise, Ubuntu's default THP mode). With the same jemalloc configuration preloaded into the toolchain on Graviton3, page faults fell by about 90%, a clean ninja clickhouse was 13.2% faster and the ThinLTO link of clickhouse 4.7% faster, with lld's peak RSS at 15.7 GB instead of 15.2 GB: #131183 (comment).

--with-lg-page=16 on aarch64 keeps it working on 64 KiB-page kernels, and --with-lg-hugepage=21 makes the value independent of the build runner. -lm is dropped (jemalloc uses libm only for profiling, which is off), the license now comes from the tarball, and libjemalloc-dev is removed from clickhouse/binary-builder.

On a host with little free contiguous memory, huge-page faults stall in compaction: on a long-running shared x86 server the ThinLTO link of clang took 58.1 s instead of 54.1 s (median of 5, peak RSS 1.07x) and a compile sample 3:40-4:24 instead of 2:43. MALLOC_CONF=thp:default,metadata_thp:disabled turns the huge pages off. A clean x86 host was not measured.

It takes effect once OptimizeToolchain runs on master and the toolchain pin in ci/docker/binary-builder/Dockerfile moves; with the ci-toolchain label this PR's CI also builds both toolchains.

Validation, run locally (x86, and aarch64 under qemu): the modified job ran end to end in the image without libjemalloc-dev, BOLT applied; stage 2's configure results equal master's; clang, lld, llvm-tblgen and llvm-bolt report jemalloc 5.4.0 with the options; tablegen outputs, ClickHouse objects and links are byte-identical to those of the same LLVM tree linked with master's flags.


Workflow [PR]
Sync PR [sync-upstream/pr/131745]

Version info

  • Merged into: 26.11.1.2651-master (included in 26.11 and later)

The toolchain job now builds jemalloc 5.4.0 from the sha256-pinned release
tarball in a new stage and links its libjemalloc_pic.a into the stage 2
executables instead of Ubuntu noble's 5.3.0 from libjemalloc-dev, which is
removed from the binary-builder image (nothing else used it).

The archive is configured with
--with-malloc-conf=thp:always,metadata_thp:always, so clang and lld ask for
transparent huge pages for the heap and jemalloc's metadata (madvise on
hosts in THP mode `madvise`); MALLOC_CONF still overrides it at run time.
On Graviton3 the same jemalloc preloaded into the toolchain made a clean
`ninja clickhouse` 13.2% faster and the ThinLTO link 4.7% faster
(ClickHouse#131183 (comment)).

--with-lg-page=16 on aarch64 because jemalloc refuses to start when the
kernel page is larger than its own; --with-lg-hugepage=21 so the value does
not depend on the build runner's /proc/meminfo; -g0 because configure adds
-g3 by default. -lm is no longer needed: jemalloc only calls libm from its
profiling code, which this build does not enable. The license now comes
from the tarball's COPYING.

Related: ClickHouse#131183
Related: ClickHouse#130064

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings), plus my own review (1 nit worth noting).

# Sev Finding Verdict Evidence / action
1 💡 jemalloc's objects are compiled with jemalloc's default flags, so they lack the stack protector and _FORTIFY_SOURCE that Ubuntu's libjemalloc_pic.a had (ci/jobs/build_toolchain.py, "Build jemalloc") AGREE, not blocking The rest of stage 2 is built by the same clang without them; clang and lld keep PIE, RELRO and BIND_NOW (checked with readelf).

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-9:20261115-043300

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? N/A as a bug repro (owner-requested build-time change). The mechanism is shown directly: the new clang maps its heap MADV_HUGEPAGE (9-10 mappings, up to 889 MB AnonHugePages), the old one does not.
b Root cause explained? Default jemalloc never asks for huge pages, so the compiler's heap faults in 4 KiB at a time. Built with thp:always,metadata_thp:always, it madvises its extents and metadata, which removes most page faults (Graviton3: clean build -13.2%, ThinLTO link -4.7%).
c Fix matches root cause? Yes: the allocator's configuration is built in, as the owner chose, instead of a runtime MALLOC_CONF in CI jobs.
d Test intent preserved / new tests added? No test of the CI infrastructure itself; validated locally: the modified job ran end to end (BOLT applied), plus negative controls for the checksum and the license step.
e Both directions demonstrated? Master's flags vs the new ones on one LLVM tree: 5.3.0 / opt.thp: "default" vs 5.4.0 / "always", huge-page mappings 0 vs 9-10, override back to 0; configure results and all outputs identical.
f Fix is general across code paths? One flag covers every stage 2 executable (clang, lld, llvm-tblgen, llvm-bolt checked); shared libraries and stage 1 unchanged; the stage runs on x86 and aarch64.
g Fix generalizes across inputs (params/datatypes/wrappers)? bfd (CMake's checks) and lld links, C and C++; 4 KiB pages on x86, LG_PAGE 16 on aarch64 (64 KiB-page kernels); MALLOC_CONF override; host jemalloc preloaded on top.
h Backward compatible? (maintainer-approved exception only) Yes: no setting or product change; the current toolchain stays pinned until a toolchain update; ClickHouse's configure is identical in the image without libjemalloc-dev.
i Invariants and contracts preserved? -znow, --emit-relocs, PIE and RELRO kept; no new NEEDED entry, no runtime dependency on libjemalloc.so.2; the archive ships jemalloc's COPYING; tablegen outputs, ClickHouse objects and links byte-identical.

Session id: cron:clickhouse-impl-slot-6:20261115-030200

@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7074ad5]

Summary: ✅


AI Review

Summary

Builds SHA-256-pinned jemalloc 5.4.0 for the stage 2 toolchain, enables transparent huge pages, includes the upstream license, and removes the distro dependency. No actionable findings. The supplied comparative benchmarks and local validation support the change; the fragmented-host performance tradeoff is explicitly documented.

Missing context / blind spots
  • ⚠️ Both toolchain CI jobs were skipped because ci-toolchain is absent. Validation relies on the reported local x86 and emulated aarch64 runs; native runs of both opt-in jobs would provide independent end-to-end confirmation. Full toolchain builds were not rerun during this review.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-build Pull request with build/testing/packaging improvement can be tested Allows running workflows for external contributors manual approve Manual approve required to run CI comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). labels Nov 15, 2026
The broken_links style check reads the URL in the added line up to the
first `{`, so the f-string left it the prefix
https://github.com/jemalloc/jemalloc/releases/download/, which is 404.
Keep the full asset URL in a JEMALLOC_URL constant next to its sha256, so
the check sees the real download link.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 7074ad5fa with master 5ea78e24c (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

15996 translation units recompiled, 42705 s compile time in total, 15967 of them have a recent master baseline.

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - ae5e272

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Performance Comparison (amd_release, master_head, 3/6) infra, not from this PR (it changes only the opt-in toolchain job and the binary-builder image): killed at the 7200 s job timeout, because every test of the shard ran in full (--max-queries 0 on all 142 tests, no coverage-based reduction), so the benchmarks did not fit. Performance Comparison shards errored on 11 other PRs since 05:00Z (15 shards) a fix task is created (investigating at full effort, fixing-PR link to follow here)
Performance Comparison (amd_release, master_head, 4/6) same: 7200 s job timeout, --max-queries 0 on all 142 tests a fix task is created (investigating at full effort, fixing-PR link to follow here)
Performance Comparison (amd_release, master_head, 6/6) same: 7200 s job timeout, --max-queries 0 on all 141 tests a fix task is created (investigating at full effort, fixing-PR link to follow here)

Session id: cron:our-pr-ci-monitor:20261115-090012

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the Performance Comparison (amd_release, master_head, 3/6, 4/6 and 6/6) timeout rows in my CI finish ledger above: #131772. A NightlyCoverage run that collected no test was accepted as the coverage cohort, so every performance test became mandatory with all queries and the shards hit the 7200 s limit.

alexey-milovidov added a commit that referenced this pull request Nov 15, 2026
#119685 was reverted in #131765 because the `arm_release` binary died with
SIGILL on cores without `FEAT_PAuth` (Graviton2, Ampere Altra) on the first
SimSIMD call: SimSIMD compiles its CPU probe `_simsimd_capabilities_arm` and
five bf16 NEON kernels for ARMv8.3+, where clang folds `autiasp; ret` into
`retaa`, which is not in the `NOP` space.

Build `_simsimd` with `-mbranch-protection=none` (the same fix as #131762).
Compiled with the `arm_release` flags, `c/lib.c` goes from 7 `retaa` to 0.

Add a check to the `arm_release` compatibility check that scans the code
sections of the packaged binary for `retaa` and `retab` and names the
functions through `system.symbols`. A test run on Graviton3 would never notice
the next such case. On the `arm_release` package of #131745 (pac-ret on) it
reports exactly the 6 SimSIMD functions; on that of d88a8f1 (the master
commit before #119685) it passes.

Closes: #131748
Related: #131762
Related: #131765

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, update the branch.

@alexey-milovidov alexey-milovidov self-assigned this Nov 15, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Done: merged master (d7452003e812) into the branch in 98e2705, no conflicts; the PR diff is unchanged (ci/jobs/build_toolchain.py, ci/docker/binary-builder/Dockerfile).

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 16, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 16, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, fix conflicts.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Done: merged master (b185d975b034) in d76a9c6. The one conflict was the ci/docker/binary-builder/Dockerfile package list, where #131720 added libzstd-dev next to the libjemalloc-dev line this PR removes; I kept libzstd-dev. The PR diff against master is otherwise unchanged.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - d76a9c6

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Build (arm_tidy, 2/4) not from this PR (it changes only ci/ files): the only error is master's src/Parsers/ParserTransactionControl.h:12:5: function 'getDocumentation' should be marked [[nodiscard]]; the tree this run built (merge ref 84dc929) predates the fix #131891 (external, merged)
Build (arm_tidy, 3/4) same error as 2/4 #131891 (external, merged)
Build (arm_tidy, 4/4) same error as 2/4; these three failures dropped 67 dependent jobs, which did not run on this head #131891 (external, merged)
Sync - CH Inc sync (private, not actionable by me)

Session id: cron:our-pr-ci-monitor:20261116-050013

@snelheidai snelheidai mentioned this pull request Nov 17, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 17, 2026
Merged via the queue into ClickHouse:master with commit a505f7f Nov 17, 2026
193 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). manual approve Manual approve required to run CI pr-build Pull request with build/testing/packaging improvement pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants