Skip to content

perf(fs): splice large buffered Linux outputs past mold #79

Closed

Description

@zackees

Context

Exact final-SHA benchmark run 32881046576 leaves native reld within 31.4 ms of the Linux full-LTO lead:

Linker full-LTO median
mold 306.9 ms
reld 338.3 ms

Startup is only 2.0 ms and is reported separately, so this is linker work rather than front-door cost. The full-LTO reld phase trace attributes 265.45 ms of a 308.43 ms traced link to output:

  • Write data to file: 167.90 ms
  • Compute build ID: 20.12 ms
  • Flush and unmap output file: 76.99 ms
  • all non-output work: approximately 43 ms

Issue #77 established that assembling the benchmark-sized ext4 output in an anonymous buffer is faster than faulting a file-backed mmap. Its final step still uses write_all, copying the complete 356 MiB buffer into the kernel page cache.

Two controlled Bosn/Linux probes compared persistence primitives over a completed 356 MiB page-aligned buffer. On the persistent Docker volume, warmed write took 406–487 ms while vmsplice(SPLICE_F_GIFT) plus splice took 242–281 ms, a 42–50% reduction. On overlay storage, the same ordering held and the splice path was roughly 3x faster after warmup. copy_file_range from a memfd failed with EXDEV; anonymous huge-page advice was slower and did not materially reduce minor faults. These local timings are directional because the authoritative runner uses ext4, but the measured flush reduction has enough ceiling to close the 31.4 ms hosted gap.

Prior exact experiments already rejected adjacent approaches:

  • file-to-file copy_file_range for unchanged sections missed the performance gate in every LTO mode;
  • parallel buffered ranged writes were inconsistent;
  • output prefaulting regressed medians;
  • overlapping build-ID hashing with buffered flush increased memory-bandwidth contention.

Proposal

  1. For the existing 256–512 MiB Linux ext4 buffered policy, allocate the completed output in an owned page-aligned anonymous mapping rather than an ordinary Vec.
  2. At OutputFileData::finish, transfer every complete page through a pipe using vmsplice with SPLICE_F_GIFT followed by splice into the already opened output file. Write any unaligned tail normally.
  3. Loop correctly over short vmsplice/splice results and EINTR. If the optimized primitive is unavailable before any output progress, rewind and fall back to the existing write_all path. After observable progress, preserve correctness by completing the remaining transfer or returning an error rather than overwriting or silently truncating bytes.
  4. Restrict automatic selection to regular Linux ext4 outputs in the already measured 256–512 MiB range. Preserve ordinary Vec buffering for pipes/devices, other filesystems, small outputs, multi-gigabyte outputs, and non-Linux platforms.
  5. Keep build-ID calculation over the completed userspace bytes before ownership is gifted. Do not overlap hashing and splicing; prior evidence found that contention counterproductive.
  6. Instrument the selected persistence path and transferred byte count in the existing phase evidence so the exact run proves activation.

Acceptance criteria

  • Commit RED evidence first: a focused test proves benchmark-sized Linux ext4 buffered output currently lacks a page-aligned splice-capable representation and uses the serial write_all finish path.
  • GREEN tests prove the optimized path activates only for the bounded regular-file policy and preserves exact bytes, executable permissions, output length, and GNU build ID.
  • Tests cover short vmsplice, short splice, EINTR, zero-progress unsupported fallback, unaligned tail handling, and failure after partial progress.
  • No page is modified after it is gifted; ownership, mapping lifetime, pipe draining, and unsafe syscall preconditions are documented and reviewed.
  • Small outputs, outputs above 512 MiB, explicit non-regular destinations, other filesystems, Android, macOS, and Windows retain a correct supported path.
  • The unchanged captured Rust workload, LTO configurations, round-robin ordering, trial count, correctness oracle, exact-SHA gate, startup reporting, and history identity are preserved.
  • Exact GitHub Linux evidence records raw samples, median/MAD, filesystem, output size, phase timings, selected persistence path, and transferred bytes.
  • Native reld full-LTO median on Linux is lower than mold in the same exact workflow run. This is the completion gate; a projected or local-only win is insufficient.
  • no-LTO and ThinLTO do not regress by more than 2% against merged main in a paired comparison.
  • An ordinary small-link comparison does not regress by more than 2%.
  • Linux correctness/self-hosting/Clippy and all-platform linker-mode and benchmark gates remain green.
  • The final PR links RED, GREEN, and exact hosted benchmark evidence.

Decisions

  • Priority: P1. Winning full-LTO is the explicit objective and the current gap is small enough for the measured flush ceiling to close.
  • Scope: the existing bounded Linux ext4 buffered policy. This avoids turning a benchmark-proven optimization into an unbounded-memory or cross-platform behavior change.
  • Primitive: anonymous pages plus vmsplice/splice. It preserves the fast userspace assembly path while targeting its remaining full-buffer kernel copy.
  • Fallback: only before observable progress. Restarting a partially gifted transfer would risk duplicated or corrupted output; partial-progress errors must remain explicit.
  • No benchmark changes. The workload already exposes real output cost and changing it would invalidate the crown comparison.
  • No hash/flush overlap. Previous exact evidence rejected the added memory-bandwidth contention.

Open questions

  • Does GitHub ubuntu-24.04 ext4 preserve the local splice advantage once page-cache/writeback ordering is balanced?
  • Should a successful splice path become available to explicit --no-mmap-output-file on matching regular ext4 files immediately, or only after the automatic-policy path wins the exact gate?

Related issues

Activity

  1. zackees commented on Aug 25, 2026

    @zackees
    CollaboratorAuthor

    Hosted run 32897398720 disproved the splice direction: full-LTO reld was 384.4 ms versus mold at 302.2 ms, and splice raised hosted flush to about 101 ms versus about 77 ms on the prior mmap path. The branch now reverts splice and moves to #81, which targets the measured 71,604-section monolithic-object write bottleneck.

  2. zackees commented on Aug 26, 2026

    @zackees
    CollaboratorAuthor

    Exact hosted splice evidence showed the proposed transport regressed the full-LTO flush path. The accepted replacement work is tracked by #81 and implemented in PR #80, where intra-section debug-relocation sharding now beats mold on Linux full-LTO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions