Skip to content

Build the CI toolchain with jemalloc - #131183

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:ci-toolchain-jemalloc
Nov 13, 2026
Merged

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

Conversation

@groeneai

@groeneai groeneai commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #130064
Related: #130705

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 (clang, lld and the other LLVM tools built by the OptimizeToolchain workflow) is now linked with jemalloc, so building ClickHouse with it is about 4-6% faster. The built binaries are unchanged.

Description

clang and lld spend a measurable share of a ClickHouse build in glibc malloc (lld runs one ThinLTO backend per core). The toolchain's executables now link Ubuntu's static libjemalloc_pic.a with --whole-archive, the recipe LLVM uses for its own BOLT image (bolt/utils/docker/Dockerfile): clickhouse/binary-builder installs libjemalloc-dev, and stage 2 adds -ljemalloc_pic -lstdc++ -lm to CMAKE_EXE_LINKER_FLAGS. CMake also links its compiler checks with these flags, and the archive's C++ part and amd64 profiling code need libstdc++ and libm. It is Ubuntu 24.04's jemalloc 5.3.0, the same build as the libjemalloc2 the reporter preloaded (built for 64 KiB pages on arm64). Shared libraries, stage 1, the compiler-rt runtimes and -znow/--emit-relocs/PIE/RELRO are unchanged, and the tarball gains no runtime dependency and ships jemalloc's license (share/doc/jemalloc/copyright).

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 runs the amd64 and aarch64 toolchain builds.

Validation on x86 (Xeon 6975P): the modified job ran from stage 2 to the package in the image with libjemalloc-dev (BOLT applied), stage 2's configure results equal master's, and clang/lld resolve malloc and operator new to jemalloc. Two non-PGO toolchains from one LLVM tree, differing only in the allocator, on the 32 physical cores of a NUMA node, nodes swapped: from-scratch ninja clickhouse 1281.7 / 1282.2 s -> 1200.9 / 1242.8 s (-4.7%), lld ThinLTO link of clang median 58.2 -> 55.7 s (-4.3%, peak RSS -20%); all outputs byte-identical. Cross-built for aarch64 against the arm64 image with these flags, clang and lld configure and link, and under qemu they run on jemalloc (64 KiB pages) with output identical to master's flags. On Graviton3 the reporter measured -5.9% with jemalloc preloaded into the CI toolchain: #130705 (comment).


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

Version info

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

groeneai and others added 2 commits November 13, 2026 00:07
clang and lld spend a measurable share of a ClickHouse build in glibc malloc
(lld runs one ThinLTO backend per core). Link the toolchain's executables with
Ubuntu's static jemalloc, the recipe LLVM itself uses for its BOLT image
(bolt/utils/docker/Dockerfile): libjemalloc-dev is added to the binary-builder
image, and stage 2 links libjemalloc_pic.a with --whole-archive, so malloc and
operator new/delete of clang, lld and the other LLVM tools resolve to jemalloc
inside the executable. The tarball stays self-contained: no runtime dependency
on libjemalloc.so.2 is added.

Why -lstdc++ -lm: CMake also links its compiler check at project() and every
try_compile/check_* probe with CMAKE_EXE_LINKER_FLAGS (CMP0056 is NEW under
LLVM's cmake_minimum_required), and those C links pull in the archive's C++
part (jemalloc_cpp.pic.o needs libstdc++) and, on amd64, the --enable-prof code
(exp, log, round from libm). Without them the stage 2 configure fails with "The
C compiler ... is not able to compile a simple test program". -lpthread and
-ldl of the upstream line are not needed with glibc >= 2.34.

Ubuntu builds the package with --with-lg-page=12 on amd64 and 16 on arm64, so
the aarch64 toolchain also runs on 64 KiB-page kernels, and with
--with-lg-hugepage=21. It is the same 5.3.0 build as libjemalloc2, which was
used for the measurements.

Shared libraries (libclang.so, libLTO.so, LLVMgold.so), stage 1 (the
instrumented build) and the compiler-rt runtimes and builtins are unchanged:
CMAKE_SHARED_LINKER_FLAGS is not touched, and CMAKE_EXE_LINKER_FLAGS is not
passed to the runtimes' or bolt_rt's external projects. -znow, --emit-relocs,
PIE and RELRO are kept. The memory columns of -ftime-report (glibc mallinfo2)
no longer report the toolchain's heap.

It takes effect once OptimizeToolchain runs on master and the toolchain pin in
the binary-builder Dockerfile moves.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The toolchain's executables now contain jemalloc, which is BSD-2-Clause:
a binary redistribution must reproduce its copyright notice, conditions and
disclaimer, and the archive is published. The package stage installs the
copyright file of the image's libjemalloc-dev package
(/usr/share/doc/libjemalloc-dev/copyright) as share/doc/jemalloc/copyright,
after the strip step; when the file is missing, the stage fails and no archive
is written.

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) plus my own review, two rounds. Round 1: 2 findings + 1 nit. Round 2 (re-review of the fix): 0 findings.

# Sev Finding Verdict Evidence / action
1 ❌ The archive statically includes jemalloc (BSD-2-Clause) without its notice (ci/jobs/build_toolchain.py) AGREE, fixed the package stage installs the package's copyright file as share/doc/jemalloc/copyright and fails without it; utils/download-ci-toolchain.sh is unchanged, since a new tar --wildcards member fails (exit 2) on archives without it, including the pinned one
2 ⚠️ No proof that the final artifacts keep jemalloc after BOLT, strip and packaging DISAGREE on the packaged amd64 archive (BOLTed clang-22): MALLOC_CONF=abort_conf:true,no_such_key:1 aborts with jemalloc's message for clang-22 and ld.lld, LD_DEBUG=bindings shows libc and libstdc++ binding malloc/free/_Znwm to the executable, no libjemalloc in NEEDED; aarch64 runs in this PR's CI with the ci-toolchain label
3 💡 aarch64 and the PGO stage 2 were not built locally AGREE the description names the ci-toolchain label

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

@groeneai

groeneai commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? N/A as a bug repro (build-time improvement). The measured effect is reproducible: two toolchains from one LLVM tree that differ only in the allocator, A/B on the 32 physical cores of a NUMA node, nodes swapped.
b Root cause explained? clang's cc1 and lld's ThinLTO backends are allocation-heavy and the toolchain used glibc malloc. Its executables now link Ubuntu's static libjemalloc_pic.a; -lstdc++ -lm are there because CMake also links its compiler checks with CMAKE_EXE_LINKER_FLAGS.
c Fix matches root cause? Yes: the allocator is linked into the executables (LD_DEBUG=bindings: libc and libstdc++ bind malloc/free/operator new to the executable), the same jemalloc 5.3.0 build that was measured preloaded.
d Test intent preserved / new tests added? No test of the CI infrastructure itself; validated locally (the modified job ran from stage 2 to the package with BOLT applied).
e Both directions demonstrated? Master's flags vs the new flags, same tree: ninja clickhouse 1281.7 / 1282.2 s vs 1200.9 / 1242.8 s, ThinLTO link of clang median 58.2 vs 55.7 s (3 of 3 pairs faster, peak RSS -20%); all outputs byte-identical.
f Fix is general across code paths? Every stage 2 executable (clang, lld, clang-tidy, llvm-bolt, ...) gets it from one flag. Shared libraries, stage 1, compiler-rt runtimes and bolt_rt are deliberately unchanged.
g Fix generalizes across inputs (params/datatypes/wrappers)? C and C++ links with both bfd (CMake's checks) and lld; stage 2 configure results identical to master's (all cache probes and config headers); arm64 uses the same flags and Ubuntu's 64 KiB-page package.
h Backward compatible? (maintainer-approved exception only) Yes: no setting or product change; the current toolchain stays pinned until the next toolchain update PR; ClickHouse's own configure is identical in the image with libjemalloc-dev.
i Invariants and contracts preserved? -znow, --emit-relocs, PIE and RELRO kept; max GLIBC_ of the toolchain binaries unchanged, NEEDED sets too except, on aarch64, the interpreter ld-linux-aarch64.so.1 (jemalloc's __stack_chk_guard lives in ld.so there); no runtime dependency on libjemalloc.so.2; the archive ships jemalloc's BSD-2-Clause notice (share/doc/jemalloc/copyright); produced objects and binaries byte-identical.

Session id: cron:clickhouse-impl-slot-4:20261113-021300

@clickhouse-gh

clickhouse-gh Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e141ba8]

Summary: ✅


AI Review

Summary

PR #131183, reviewed at e141ba8b1899adb0a1bc5e4a857d46ab0f109101, links the stage 2 LLVM executables with static jemalloc and includes its license in the toolchain archive. The reported amd64 benchmarks and packaged-binary checks support the approach. Request changes for the remaining aarch64 validation gap.

Findings

⚠️ Majors

  • ci/jobs/build_toolchain.py:415: The actual aarch64 toolchain remains unvalidated. [dismissed by author -- https://github.com/Build the CI toolchain with jemalloc #131183#issuecomment-6842280659] The earlier response relies on the opt-in toolchain builds to cover aarch64, but the PR lacks ci-toolchain, and both the amd64 job and aarch64 job were skipped without running any steps. The reported ARM benchmark uses LD_PRELOAD; it does not exercise this static link or the resulting packaged executable. Regular ClickHouse builds use the older pinned toolchain. Enable the opt-in jobs and obtain validation of the actual aarch64 artifact before relying on this coverage. The amd64 artifact evidence already supplied addresses that architecture; it need not be repeated.
Tests
  • ⚠️ Provide a successful aarch64 stage 2/package result and a smoke compile/link using the archive's clang and ld.lld. Verify jemalloc is active in those packaged tools and that neither gains a dynamic dependency on libjemalloc.so.2, as already checked for amd64.
Final Verdict

Status: ⚠️ Request changes. Close the aarch64 artifact-validation gap. No additional inline thread was opened for the concern already discussed.

@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 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e141ba8b1 with master acd88ab8f (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.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.56, programs/clickhouse-keeper ×0.62 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 6.3 s 8.7 s +5.1 s (+143%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.6 s 7.1 s +5.0 s (+248%)
Compile time of recompiled translation units

6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline.

Job report

binutils-dev \
build-essential \
zlib1g-dev \
libjemalloc-dev \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It it fresh?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Ubuntu 24.04 ships jemalloc 5.3.0 (5.3.0-2build1, the upstream release of 2022-05-06). Upstream has since released 5.3.1 (2026-04-13) and 5.4.0 (2026-09-17), and dev is 95 commits past 5.4.0. I'm measuring a from-source build against it now.

@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, also test the fresh jemalloc built from the source, and test mimalloc the same way.

@alexey-milovidov alexey-milovidov self-assigned this Nov 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 13, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Acknowledged. I'm measuring the toolchain linked with jemalloc built from source (5.4.0 and dev HEAD) and with mimalloc, the same A/B as for 5.3.0; I'll follow up here with the numbers, and a PR if one of them is better.

Merged via the queue into ClickHouse:master with commit c65bdd8 Nov 13, 2026
410 of 411 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 13, 2026
@snelheidai

Copy link
Copy Markdown

@alexey-milovidov @groeneai, Graviton3 results for this comparison. Nearly all CI build jobs run on Graviton runners (the amd64 ones cross-compile); @groeneai is measuring x86.

jemalloc 5.4.0 built from source compiles no faster than Ubuntu's 5.3.0; 5.4.0 and dev link about 1% faster. mimalloc 3.6.1 makes a clean build 12% faster, but links 2.4% slower. It requests transparent huge pages for its heap by default, and jemalloc 5.4.0 built to do the same is faster in both: −13% for the clean build, −4.7% for the link.

Allocator in clang and lld Clean build, ninja clickhouse ThinLTO link of clickhouse
jemalloc 5.3.0, Ubuntu package (this PR) 2,941 / 2,945 s 532 s
jemalloc 5.4.0 2,941 / 2,913 s (−0.5%) 527 s (−1.2%)
jemalloc dev (ecb4556b) not measured 526 s (−1.0%)
mimalloc 3.6.1 2,584 / 2,613 s (−11.7%) 546 s (+2.4%)
jemalloc 5.4.0, --with-malloc-conf=thp:always,metadata_thp:always 2,567 / 2,544 s (−13.2%) 507 s (−4.7%)

The clean builds use the method of #130705 (comment): the allocator is preloaded into every clang and lld process of the CI toolchain (22.1.8), on a 16-core Graviton3 with 123 GiB and THP mode madvise; default RelWithDebInfo build of master 6f5e52a from an empty directory, no compiler cache, Rust off. The link is the ThinLTO link of clickhouse in a build configured like CI's arm_release PR build, 16 threads; each percentage compares with 5.3.0 links run alternately with it (530-534 s). Allocators alternated in both series, and every build produced the same clickhouse binary, every link the same output.

With huge pages, system CPU time fell by two thirds and page faults by about 90% (1.5-1.6 million huge-page faults per build, no compaction stalls). Memory: during a clean build, the lowest available memory was 95-97 GiB of 123 with THP-jemalloc, against 98-99 GiB with the other allocators. In the link, lld's peak RSS was 15.2 GB with jemalloc 5.3.0, 15.7 GB with THP-jemalloc and 17.1 GB with mimalloc; with THP-jemalloc the host's peak memory in use was 5.5 GB higher. Huge pages need THP mode madvise or always; with never, neither allocator gets them. Not measured: x86, and runners with less memory per core.

So the 13% does not need mimalloc. jemalloc 5.4.0 configured with --with-lg-page=16 --with-malloc-conf=thp:always,metadata_thp:always gets it and has the fastest link. --with-lg-page=16, as in Ubuntu's arm64 package, keeps the toolchain working on 64 KiB-page kernels.

Builds and per-run numbers
# jemalloc 5.4.0 release tarball; the THP variant adds --with-malloc-conf=thp:always,metadata_thp:always
./configure --with-lg-page=16 && make
# jemalloc dev at ecb4556becc8
./autogen.sh --with-lg-page=16 && make
# mimalloc v3.6.1, defaults (MI_OVERRIDE=ON, MI_ALLOW_THP=FULL)
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build

Clean builds as in the earlier comment, with LD_PRELOAD=<the library> in the five launchers, in the order 5.3.0, 5.4.0, mimalloc, THP-jemalloc, mimalloc, 5.4.0, 5.3.0, THP-jemalloc, 5.4.0. The second 5.4.0 build took 3,071 s: in its first 30 minutes, compile steps took 4-9% longer than the same steps in the first 5.4.0 build and then returned to normal, so the host was disturbed and that build was repeated. Mean user / system CPU time: 5.3.0 42,113 / 3,979 s, 5.4.0 41,887 / 3,966 s, mimalloc 39,375 / 1,299 s, THP-jemalloc 38,570 / 1,414 s.

Links, each allocator twice, alternating with 5.3.0 links: 5.4.0 526.6 / 526.9 s, dev 524.7 / 526.5 s, mimalloc 544.4 / 547.6 s, THP-jemalloc 507.3 / 507.2 s; 5.3.0 530.4-534.2 s in six runs.

@groeneai

Copy link
Copy Markdown
Collaborator Author

The x86 results (Xeon 6975P-C; non-PGO clang/lld 22.1.8 from one LLVM tree, differing only in the linked allocator). Compile: a fixed sample of 1192 of ClickHouse's translation units (8.5% of the compile time) rebuilt 6 times per variant, interleaved, on one 32-core NUMA node. Link: 5 interleaved ThinLTO links of clang.

allocator compile wall compile user link wall link peak RSS
jemalloc 5.3.0 (Ubuntu, this PR) 95.2 s 2820 s 52.8 s 4.37 GiB
glibc malloc +6.8% +8.1% +5.0% +25.7%
jemalloc 5.4.0 +2.6% +2.0% -0.7% +3.6%
jemalloc dev ecb4556b -0.2% -0.4% -1.3% +3.7%
mimalloc 3.6.1 +82% +7.0% +10.2% +10.9%
mimalloc 3.6.1, MIMALLOC_ALLOW_THP=0 +0.9% +0.8% +3.6% +4.5%
mimalloc 2.5.2 - - +16.1% -10.0%

Two compile runs of the same 5.3.0 toolchain differ by 3.7% (median) on this shared machine, so smaller compile differences are not resolved. As on Graviton3, 5.4.0 and dev link about 1% faster.

Requesting huge pages is what makes mimalloc slow here: 12x the system time, and +0.9% without them. This host (up 106 days, THP madvise) has no free 2 MiB block on the benchmark's NUMA node, and over 90% of its compactions since boot failed, so THP-jemalloc cannot be measured fairly here, and on a long-running, fragmented machine huge pages can cost more than they save.

The only measured win is snelheidai's THP-configured jemalloc 5.4.0 above (Graviton3: -13% clean build, -4.7% link). Should I open the PR that builds jemalloc 5.4.0 from source in the toolchain job with --with-lg-page=16 --with-malloc-conf=thp:always,metadata_thp:always, or keep 5.3.0?

@snelheidai

Copy link
Copy Markdown

@alexey-milovidov, about @groeneai's question above (build jemalloc 5.4.0 with huge pages on, or keep 5.3.0): there is a third option. Keep 5.3.0 with its default options (5.4.0 by itself only links about 1% faster), and let CI turn huge pages on at run time. jemalloc reads MALLOC_CONF when a process starts, so with this PR's toolchain, setting MALLOC_CONF=thp:always,metadata_thp:always in CI build jobs gives the same clean-build speedup as building the option into 5.4.0. Builds on developers' machines with utils/download-ci-toolchain.sh keep jemalloc's default, so they avoid the huge-page slowdown that @groeneai measured with mimalloc on a long-running machine with fragmented memory. This replaces my suggestion above to build the option into jemalloc.

Clean builds of clickhouse on the same Graviton3 host, source and method as in my comment above: Ubuntu's jemalloc 5.3.0, which this PR links, preloaded into every clang and lld process, run without, with, with and without the variable:

jemalloc in clang and lld Clean build, ninja clickhouse
5.3.0, default options 2,918 / 2,951 s
5.3.0, MALLOC_CONF=thp:always,metadata_thp:always 2,544 / 2,538 s (−13.4%)
5.4.0 with these options built in (my comment above, a day earlier) 2,567 / 2,544 s

Every build produced the same clickhouse binary. With the variable, system CPU time fell by 65% and page faults by 90% (1.48 million huge-page faults per build, no compaction stalls). Memory cost: the lowest available memory during a build was 97.2-97.8 GiB of 123 GiB, against 98.4-98.8 GiB without it, and the largest process, the clickhouse link, peaked at 20.4 GB RSS instead of 19.2 GB. For the CI-style ThinLTO link of clickhouse, the same variable made links with 5.3.0 3.3% faster (577-579 s instead of 597-599 s on 16 Graviton3 cores, same output, lld peak RSS +3.4%; measured on 2026-11-11 on an earlier master).

The variable also reaches compilations that go through sccache: sccache 0.17.0, which CI uses, passes MALLOC_CONF on to the compiler and finds the same cache entries with and without it.

Once clang and lld use jemalloc, the GLIBC_TUNABLES=glibc.malloc.hugetlb=1 setting for CI build jobs that I suggested in #130064 (comment) no longer affects them. It still applies to clang-tidy, which CI takes from apt's clang-tidy-22 (huge pages cut its CPU time by 9.8% on Graviton3, as reported there). The patch below therefore sets both variables in CI build jobs, so it works with the current toolchain and with one built by this PR; TOOLCHAIN_COMMIT in ci/docker/binary-builder/Dockerfile still points to bbbf2c95, built before this PR. Not measured: x86, and runners with less memory per core.

Patch (CI build jobs only)
--- a/ci/jobs/build_clickhouse.py
+++ b/ci/jobs/build_clickhouse.py
@@ -317,6 +317,17 @@
 
     setup_build_caches_env(info)
 
+    # CI build jobs run on freshly started instances with plenty of free 2 MiB blocks: back the heaps of compilers,
+    # linkers and clang-tidy with transparent huge pages, through MALLOC_CONF for the jemalloc linked into the
+    # toolchain's clang and lld, and through GLIBC_TUNABLES for tools that use glibc malloc (such as apt's
+    # clang-tidy). Not for local builds: on a long-running machine with fragmented memory, huge-page faults stall
+    # in direct compaction and make builds slower.
+    if not info.is_local_run:
+        os.environ.setdefault("MALLOC_CONF", "thp:always,metadata_thp:always")
+        tunables = os.environ.get("GLIBC_TUNABLES", "")
+        if "glibc.malloc.hugetlb" not in tunables:
+            os.environ["GLIBC_TUNABLES"] = ":".join(t for t in (tunables, "glibc.malloc.hugetlb=1") if t)
+
     is_private = (
         "PRIVATE_BUILDS_TO_CMAKE" in vars() or "PRIVATE_BUILDS_TO_CMAKE" in globals()
     )

@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, I choose 5.4.0 with the built-in options. Send a PR.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Acknowledged. I'm preparing the PR that builds jemalloc 5.4.0 from source with --with-malloc-conf=thp:always,metadata_thp:always (plus --with-lg-page=16 on aarch64); I'll post the link here.

@groeneai

Copy link
Copy Markdown
Collaborator Author

The PR: #131745. It takes effect once OptimizeToolchain runs on master and the toolchain pin in ci/docker/binary-builder/Dockerfile moves.

@snelheidai snelheidai mentioned this pull request Nov 17, 2026
eoger-ant pushed a commit to eoger-ant/ClickHouse that referenced this pull request Nov 17, 2026
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]>
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.

4 participants