Skip to content

build: link packages with mold - #70307

Closed
djgalloway wants to merge 4 commits into
ceph:mainfrom
djgalloway:wip-build-speedups
Closed

djgalloway wants to merge 4 commits into
ceph:mainfrom
djgalloway:wip-build-speedups

Conversation

@djgalloway

@djgalloway djgalloway commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Link package builds with mold, plus the fixes that needs.

Enablement (explicit WITH_MOLD=ON/OFF, no autodetection, per review):

  • deb: mold is simply ON everywhere. focal — the only release whose toolchain cannot use mold (gcc-11 lacks -fuse-ld=mold) — is no longer built from this branch, so every remaining release (jammy, noble, bookworm, trixie) builds with GCC ≥ 12 and mold is a plain Build-Depends in debian/control.
  • rpm: BuildRequires: mold and WITH_MOLD=ON on EL9+, behind a new mold bcond (mold comes from EPEL, so buildroots without EPEL can rpmbuild --without mold, which also flips WITH_MOLD off). Other rpm distros build with WITH_MOLD=OFF.

Fixes required by mold — mold resolves all archives on the link line as a single group, so it extracts members BFD's lazy single-pass walk never touched, exposing latent link-dependency bugs; all of these are no-ops for BFD builds:

  • --copy-dt-needed-entries (a BFD-quirk workaround on ~10 libcephfs/fs test binaries) is skipped under mold, which hard-rejects the option and does not exhibit the quirk.
  • ceph-dencoder now links librados explicitly: its cls_*_client static libs reference the librados C++ API. Latent underlink.
  • perf-staged-fltree gets -z muldefs under mold: mold extracts libcrimson-gtest.a(gtest_seastar.cc.o), whose main() collides with the tool's own; first definition (the tool's) wins, matching BFD behavior.
  • rgw_a now declares its heap_profiler dependency: 6d8851a added ceph_heap_profiler_*() calls to rgw_appmain.cc but only linked heap_profiler into radosgw/rgw/rgw_a_standalone, leaving every other consumer of rgw_a (radosgw-es, rgw test/bench binaries) underlinked. Latent underlink.

Timings

Measured with ceph-dev-pipeline on x86_64 gigantic builders, "build" stage (compile + package) per matrix cell. Baseline is main #7311 / #7312 (2026-07-17, warm sccache). "Cold" is this branch on a new sha (#7338); "warm" is a FORCE rerun of the same sha (#7341).

Cell main baseline this branch, cold cache this branch, warm cache warm Δ
centos9 debug 38.8 min 25.0 15.8 −59%
rocky10 debug 26.8 min 35.1 17.2 −36%
centos9 default 33.7 min 28.2 27.0 −20%
rocky10 default — 40.4 29.3 —
noble default 45.8 min 61.9 48.4 ~parity
noble debug 39.8 min 50.4 40.5 ~parity

Notes:

  • This branch originally also routed the bundled Boost build through the compiler launcher; the same change landed upstream via Improve the performance of Ceph builds and rebuilds. #70129 (and b2 launcher use was then deliberately bypassed in 0128fbe), so that commit was dropped on rebase. The timing runs above predate that and included it.
  • rpm cells currently miss the sccache cache on every new sha because the rpmbuild path embeds the version string; the deb path avoids this via CEPH_BUILD_NORMALIZE_PATHS. The cold column is today's per-push reality for rpm; making rpm paths sha-independent is a planned follow-up and would make every push look like the warm column.
  • deb builds were never as link-bound as rpm (their time is dominated by the packaging tail), hence noble parity.
  • Validation: run #8238 built all cells green — rocky10/centos9/noble default+debug and jammy default (jammy's mold 1.0.3 included); its only failures were chacra-node SSL upload errors unrelated to this PR.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
    • Includes unit test(s)
    • Includes integration test(s)
    • Includes bug reproducer
    • No tests

@djgalloway

Copy link
Copy Markdown
Contributor Author

Full disclosure, I asked AI for recommendations on speeding up Ceph builds. I don't know the implications of how using Mold might affect Ceph runtime, if at all. I'm eager to hear @tchaikov's input.

tchaikov

This comment was marked as resolved.

Comment thread src/script/buildcontainer-setup.sh Resolved
@djgalloway
djgalloway force-pushed the wip-build-speedups branch from 02edb41 to b8ac089 Compare July 30, 2026 16:56
@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@djgalloway

Copy link
Copy Markdown
Contributor Author

in general I'd prefer to keep this CMake option explicit: avoid AUTO and always pass ON or OFF, so the build is determined by the user rather than by the build environment.

in this case, whether we're allowed to use mold comes down to one thing: whether the compiler supports -fuse-ld=mold, which was introduced in GCC 12. we already install gcc-12 on jammy (install-deps.sh: ensure_decent_gcc_on_ubuntu 12 jammy), so the

jammy is gcc-11, therefore a no-op

reasoning in the description doesn't hold, right? as jammy would link with mold too.

that makes me wonder whether we could just use mold everywhere explicitly. the only holdout is focal, which we still build with gcc-11 (ensure_decent_gcc_on_ubuntu 11 focal) and which has no mold package. every other distro in the matrix (jammy, noble, bookworm, trixie, EL9/EL10) already clears the bar. so could we pass WITH_MOLD=ON where it's supported and OFF on focal, and drop AUTO altogether?

if we have to support focal (i doubt so), we could use something like

ifeq ($(DEB_DISTRIBUTION),focal)
  extraopts += -DWITH_MOLD=OFF
else
  extraopts += -DWITH_MOLD=ON
endif

and in ceph,spec.in

%if 0%{?rhel} >= 9
    -DWITH_MOLD=ON \
%else
    -DWITH_MOLD=OFF \
%endif

Implemented!

Comment thread debian/rules Resolved
Comment thread cmake/modules/BuildBoost.cmake Resolved
Comment thread src/test/fs/CMakeLists.txt Resolved
djgalloway added a commit to ceph/ceph-build that referenced this pull request Aug 4, 2026
jq '.[]' prints array elements as bare concatenated JSON documents, so
wrapping the output in "[" ... "]" only parsed when a page had a single
element (which the PR used for initial testing happened to have).  Emit
compact one-per-line elements and reassemble with jq -s instead, which is
correct for any element count.  Verified all three subcommands against a
multi-file PR (ceph/ceph#70307).

Signed-off-by: David Galloway <[email protected]>
@djgalloway
djgalloway force-pushed the wip-build-speedups branch 3 times, most recently from 3aa202b to 135db63 Compare August 13, 2026 22:50

@tchaikov tchaikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@tchaikov

Copy link
Copy Markdown
Contributor

@djgalloway hi David, did you get a chance to push this change to ceph-ci?

@djgalloway

Copy link
Copy Markdown
Contributor Author

@djgalloway hi David, did you get a chance to push this change to ceph-ci?

https://jenkins.ceph.com/job/ceph-dev-pipeline/8235/stages/ but Jenkins is backed up right now

@djgalloway
djgalloway requested a review from a team as a code owner August 14, 2026 04:02
@djgalloway

Copy link
Copy Markdown
Contributor Author

I don't know if the rgw fix is appropriate for this PR. Thoughts?

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

mold intentionally does not implement --copy-dt-needed-entries and
exits with 'mold: fatal: unknown command line option' when passed the
flag, which broke every WITH_MOLD=ON build on the ~10 libcephfs/fs test
executables that use it. The flag is a workaround for a BFD-specific
'DSO missing from command line' failure that mold does not exhibit, so
skip it when USING_MOLD_LINKER is set (by the WITH_MOLD cmake option).

Signed-off-by: David Galloway <[email protected]>
mold resolves all archives on the command line as if wrapped in a
single --start-group, so it extracts members that BFD's lazy
first-pass extraction never touched. Two targets tripped over this in
WITH_MOLD=ON builds:

* ceph-dencoder: the cls_*_client static libs reference the librados
  C++ API; mold pulls in the referencing members and fails with
  undefined librados symbols. Link librados explicitly - the target
  was underlinked all along.

* perf-staged-fltree: mold extracts
  libcrimson-gtest.a(gtest_seastar.cc.o), whose main() collides with
  the tool's own. Pass -z muldefs under mold so the first definition
  (the tool's) wins, matching BFD's behavior.

Signed-off-by: David Galloway <[email protected]>
Enable mold for deb and rpm package builds with an explicit
WITH_MOLD=ON/OFF instead of autodetection, per review.

On the deb side mold is simply ON everywhere: focal, the only release
whose toolchain cannot use mold (gcc-11 lacks -fuse-ld=mold), is no
longer built from this branch, so every remaining release (jammy,
noble, bookworm, trixie) builds with GCC >= 12 and mold is a plain
Build-Depends.

On the rpm side mold is a BuildRequires and WITH_MOLD=ON on EL9+,
gated by a new mold bcond (mold comes from EPEL, so buildroots
without EPEL can rpmbuild --without mold, which also flips
WITH_MOLD off). Other rpm distros build with WITH_MOLD=OFF.

Linking is never cached by sccache, and BFD ld runs single-threaded
over ~100 debug-heavy binaries on every package build. Measured with
ceph-dev-pipeline on centos9/rocky10/noble x86_64 (default and debug
flavors): the package build stage is 16-36% faster with a cold
sccache cache and up to 59% faster with a warm one.

Signed-off-by: David Galloway <[email protected]>
6d8851a ("rgw: add tcmalloc heap profiler support via admin
socket") made rgw_appmain.cc call ceph_heap_profiler_*() and
ceph_using_tcmalloc(), and added the heap_profiler library to the
radosgw, rgw and rgw_a_standalone targets - but not to rgw_a, whose
librgw_a.a(rgw_appmain.cc.o) actually carries the references. Every
other consumer of rgw_a (radosgw-es, the rgw test and bench binaries)
is therefore underlinked. BFD's lazy archive extraction happens to
never pull the referencing member into those links, but mold resolves
archives as a single group and fails with undefined symbols.

Declare the dependency on rgw_a itself so all consumers inherit it.

Signed-off-by: David Galloway <[email protected]>
@github-actions github-actions Bot added rgw and removed needs-rebase labels Sep 10, 2026
@djgalloway djgalloway changed the title build: link packages with mold, route bundled Boost through sccache build: link packages with mold Sep 10, 2026
Comment thread src/rgw/CMakeLists.txt
PRIVATE
rgw_schedulers
kmip
heap_profiler

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@djgalloway please see this fix: #71481
it also removes the hep_profiles from 2 other places.

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@Doracly

Doracly commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

@djgalloway after my experiments for #72620 I lean towards using lld as the "default linker" for ceph.
What do you think?

@djgalloway djgalloway closed this Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants