Skip to content

execd: a job's chunks in one file, a 72 KiB stride each - #749

Merged
capy-ai[bot] merged 3 commits into
mainfrom
capy/a-jobs-chunks-in
Nov 27, 2026
Merged

capy-ai[bot] merged 3 commits into
mainfrom
capy/a-jobs-chunks-in

Conversation

@jaredLunde

@jaredLunde jaredLunde commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

A job's retained output was one 64 KiB file an inode: 129 names for an 8 MiB job, an inode creation and a close per chunk written, an open and a close per chunk read. Measured on this host, a chunk's creation cost 36-45 µs — more than the 7 µs it takes to copy its 64 KiB — so the inode, not the copy, was the tightest constraint in the output path.

This is variant 1 of reports/CAPY-13.md. A job's chunks now live in one file, ring/chunks, at a stride of 72 KiB: chunk k's bytes at k * 72 KiB, its 8 KiB of stderr bits at + 64 KiB. A chunk's offset is arithmetic on its index, never a table and never anything a client sends. A flush is one pwrite on a descriptor the ring holds while it writes and drops when the job ends, so an ended job holds no descriptor and a read opens the file once rather than once a chunk.

Every invariant is kept, and each has a test that fails without it

  • Offsets never move. The stride is a layout, not an offset. read and attach answer the same bytes before and after the change (read_and_stream_answer_the_same_bytes compares them over the same job), and ring.rs's differential test runs both layouts through the same random pushes, reads and refused chunks.
  • A gap is declared, never silent, and a torn stride is never fabricated data. A chunk's bytes go down before its bits, so the file's length names exactly the chunks that are whole; a length that stops inside a payload is a chunk the crash cut short and is not counted. Recovery takes the base from the file's first data byte (lseek(SEEK_DATA), rounded up to a stride), never from the length alone, so a chunk eviction punched is never served as zeros. A stride the journal had not advanced past is rebuilt from the journal byte-exactly; one the journal had passed leaves exactly the gap a per-chunk file cut short leaves today, and the ring restarts at the journal's byte.
  • The 8 MiB retention floor and R3's window are unchanged: the ring holds at least a chunk past the floor, and eviction is now one punch of one stride.
  • stderr labels stay with their chunk, and a stdout-only chunk costs one pread and no allocation (one 8 KiB buffer is reused).
  • The tombstone drops everything at the same offset, and the retention sweep's ledger-then-unlink order is untouched.

The capability gate, and no flag

Eviction is a punch, so spool::punch_hole_supported asks the jobs directory's filesystem once (a two-page scratch file, one page punched, removed) and remembers the answer per directory. Where it says no (NFS, SMB, some FUSE) the ring writes one file a chunk, the layout before this change, with a log_warn! at start saying why — that is the filesystem's answer, not an operator's, so there is no environment flag that asks for the old layout. Recovery reads the layout the files are in: a ring directory holding chunk files is served and continued as one, whatever this run's probe prefers (a probe answers per directory per run, so a remount can change it).

Worst failure mode, and why it is bounded

A crash between a chunk's bytes and its bits leaves a length that stops inside a payload: at most the last 64 KiB reads back as a declared gap, never as zeros, and every earlier byte is exact. A crash whose journal advanced past the torn chunk leaves the retained window as one declared gap starting at the journal's byte. A disk that refuses a chunk takes the file back to where the ring's window started (set_len), which is the same gap a refused per-chunk write leaves. The client always gets an answer with explicit gap ranges; there is no path that truncates, hangs or serves fabricated bytes.

Rebased onto 8a22dcc1, and what the merge broke

The branch was based on 87347af; main has taken four changes since, three touching crates/execd/src/jobs.rs (#746 ledger append, #747 serialized answers, #748 the kernel child list). The rebase itself was clean — none of the three landed on a pack hunk. One sibling call site broke: #747 added a second Job fixture to the serialized read/list equivalence test, still calling Ring::new(retain, dir), and that single E0061 was all four of this PR's red jobs at 80cae77 (build tests, execd (arm64), clippy, and Check counting them). Fixed in 0d86902.

Measured (release builds, one 8 MiB job; before = a release build of 8a22dcc1, re-taken because the base moved)

before (8a22dcc1) after
names in the job's spool 132 (ring/ 128) 5 (ring/ 1)
inode creations under the spool 257-259 128-132
ring syscalls per 64 KiB chunk 3.01-3.03 (create, write, close) 1.02-1.05 (one pwrite)
journal rewrites (renames) 130 128-131
spool syscalls per chunk (journal, punches, tail reads) 9.24-9.55 10.12-10.70
execd syscalls per chunk, all categories 37.7 37.3
idle RSS with a kept job 6.2-6.6 MB 6.2-6.6 MB
job wall time, median of 41 alternating rounds 110.7 / 84.7 / 85.2 ms 97.4 / 78.5 / 84.6 ms

The chunk inode's create and close are exactly what goes missing: −2.0 ring syscalls per chunk, −128 inode creations, −127 names. The journal's rewrite count is unchanged (#746 made the ledger append-only, not the job journal), and at this workload's pacing the tail now takes more, shorter rounds — a pread and a journal append each — so the aggregate per chunk is flat. I do not claim the design report's "13.2 → 11.2 syscalls per chunk": the −2.0 is what the pack removes from the ring path, and it is handed back in the tail's round count. Wall time is inside this host's noise (three 41-round alternating runs: −13.4, −6.1, −0.6 ms on an 85-110 ms baseline, minima favouring the after binary in all three), so the portable findings are the names, the inodes and the ring path's syscalls.

Red runs

  • mut_pack_keeps_short_tail — a_torn_pack_tail_is_recovered_from_the_journal and ring::tests::a_stride_the_crash_cut_short_is_not_a_chunk.
  • mut_pack_ignores_punch_probe — a_punchless_filesystem_keeps_one_file_a_chunk.
  • mut_pack_stride_overlap — the_stride_gives_every_chunk_its_own_bytes_and_labels and read_and_stream_answer_the_same_bytes.
  • mut_pack_ignores_journal_floor — a_pack_the_journal_outran_is_a_declared_gap and ring::tests::a_pack_short_of_the_journals_byte_is_a_gap. Added after the red runs disproved a claim this PR shipped with: that test said it went red under mut_pack_keeps_short_tail and it did not. What declares that gap is the journal-floor trip in recover_pack (end < floor → set_len(0), base = floor), and no mutation reached it; deleting the trip makes the test red at pack.rs:404, and this feature is that deletion. Test seam only.

Each run is a Cargo feature (--no-fail-fast, nothing in the tree touched), and in every one only the named test(s) failed.

What is not proven

  • The crash tests use EXECD_TEST_FAULT seams (debug builds only) for a torn stride and a journal that outran the pack; a real machine crash between two writes is not driven in-tree.
  • The punchless path is exercised through a fault seam, since NFS/SMB cannot be mounted here.
  • bytes_written / output_byte came out 1.67-1.73 → 1.70-1.80, leaning slightly against the pack for the same reason as the tail's round count; the journal rewrite it is dominated by is a pre-existing per-chunk cost this change neither fixes nor worsens structurally.
  • The wall-time effect is measurable but not separable from this host's spread.
  • endpoint::shutdown_kills_every_running_group flaked once in six reruns (shutdown_for returns ended + groups.shutdown(..), which double-counts a job whose removal has not landed); that code is unchanged by this PR and is worth its own fix. retention::a_sweep_concurrent_with_remove_and_start_leaves_one_state also flakes, leaving one spool journal behind — it does the same on a debug build of 8a22dcc1 (1 in 12 there, 3 in 25 here, and with the per-chunk layout too), so it is pre-existing and not this PR's.

crates/execd/ARCHITECTURE.md is updated in the same commit.

jaredLunde and others added 3 commits November 27, 2026 22:21
A job's output was one 64 KiB file an inode: 129 names for an 8 MiB job, an
inode creation and a close per chunk written, an open and a close per chunk
read. On this host a chunk's creation measured 36-45 us, more than the 7 us
the 64 KiB copy into it costs (reports/CAPY-13.md).

A job's chunks now go in one file, `ring/chunks`, at a stride of 72 KiB:
chunk k's bytes at k * 72 KiB, its 8 KiB of stderr bits at + 64 KiB. A
chunk's offset is arithmetic on its index; a flush is one `pwrite` on a
descriptor the ring holds while it writes and drops when the job ends.

Every invariant is kept, and each has a test that fails without it:

- Offsets never move: the stride is a layout, not an offset; `read` and
  `attach` answer the same bytes before and after (tests/pack.rs compares
  them explicitly, and ring.rs's differential test runs both layouts).
- A gap is declared, never silent, and a torn stride is never fabricated
  bytes: a chunk's bytes go down before its bits, so the file's length names
  exactly the chunks that are whole; recovery takes the base from the first
  data byte (lseek SEEK_DATA), never from the length, so a chunk the ring no
  longer holds is never served as zeros. A stride the journal had not passed
  is rebuilt from the journal byte-exactly; one the journal had passed leaves
  the gap a per-chunk file cut short leaves, and the ring starts at the
  journal's byte.
- The 8 MiB floor and R3's window: eviction is one punch of one stride.
- The stderr labels stay with their chunk, and a stdout-only chunk costs one
  pread and no allocation (the read reuses one 8 KiB buffer).
- The tombstone drops everything at the same offset, and the ledger-then-
  unlink order is untouched.

Eviction is now a punch, so the capability is probed once per directory and
remembered; where the filesystem cannot punch (NFS, SMB, some FUSE) the ring
keeps one file a chunk, the layout before this change, with a warning at
start. That fallback is the filesystem's answer, not an operator's: there is
no flag that asks for the old layout. Recovery reads the layout the files
are in, so a ring directory holding chunk files is served and continued as
one, whatever this run's probe prefers.

One descriptor a running job did not hold before (its pack, closed when the
job ends: an ended job holds none). Two of the three syscalls a chunk cost
are gone; the journal's per-flush temp file is variant 2 of CAPY-13 and is
not touched here.

Measured on this host (release build, one 8 MiB job): 4 names in the spool
instead of 131, 132 inode creations instead of 259, 2 fewer execd syscalls
per 64 KiB chunk, and the job's wall time 73-76 ms -> 63-70 ms (medians of
nine, alternating).

Red runs: mut_pack_keeps_short_tail (a torn stride counted as a chunk: the
torn test and the ring's own go red), mut_pack_ignores_punch_probe (the pack
used where the filesystem cannot punch: the fallback test goes red),
mut_pack_stride_overlap (the bits where the next chunk's bytes go: the stride
test goes red).

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
The rebase onto 8a22dcc carried `Ring::new`'s new layout argument to every call
site but one: the job `#747` added to the answer-equivalence test
(`jobs.rs`, the serialized `read`/`list` fixtures). It compiles now with the
per-chunk layout the sibling fixture uses; the test asserts the answer's
serialization, not the layout, and pushes nothing into the ring.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
The red runs disproved a claim the pack shipped with: `a_pack_the_journal_outran_is_a_declared_gap`
said it goes red under `mut_pack_keeps_short_tail`, and it stays green there. What declares that gap
is the journal-floor trip in `Ring::recover_pack` (`end < floor` -> `set_len(0)`, `base = floor`),
and no mutation reached it. Deleting the trip makes the test red (pack.rs:404); `mut_pack_ignores_journal_floor`
is that deletion, in the crate's own idiom, and the two tests that pin the trip name it: this one and
`ring::tests::a_pack_short_of_the_journals_byte_is_a_gap`. Test-only: with the feature off the code is
the same statement it was.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@jaredLunde
jaredLunde force-pushed the capy/a-jobs-chunks-in branch from 80cae77 to e0ce1a7 Compare November 27, 2026 22:56
@capy-ai
capy-ai Bot added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit e6a69b7 Nov 27, 2026
34 checks passed
@capy-ai
capy-ai Bot deleted the capy/a-jobs-chunks-in branch November 27, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant