Repository navigation
execd: end a job from the kernel's child list, and stop allocating per process in the scan - #748
Merged
Merged
Conversation
…uffers A job-life cycle paid one full `/proc` scan: at 731 processes, 28.7 ms, 1 467 opens and 13 436 allocations per start -> ended -> remove. Two changes, both counted with `benches/proc_scan.py`: - `proc::scan` reuses one `Scratch` (path, mark bytes, read buffer) instead of a `format!` and an `fs::read` per file per process: allocations per cycle 5 755 -> 307 at 333 processes, 13 436 -> 309 at 733, flat. - A job this server spawned ends from the kernel's child list: where execd is the subreaper every process of the job is its descendant, so `waitid(P_ALL, WEXITED|WNOHANG|WNOWAIT) == ECHILD` answers the end without reading `/proc`. `WNOWAIT` is `waitid`'s (waitpid rejects it) and leaves a zombie waitable, so the check never takes a status the reaper owes. Cycle 28.67 -> 3.72 ms and 1 467 -> 0 `/proc` opens at 731 processes. The scan is still the answer whenever the child list is not empty (another job, a keeper, an adopted stray), for a job a restart adopted, and for everything that names processes. A process carrying the mark without being a descendant of execd no longer holds its job open; `mut_end_scan_always` keeps the old path as a test feature rather than a switch. tests/job_escape.rs pins each invariant and goes red under `mut_end_group_only` and `mut_end_scan_always`. ARCHITECTURE.md documents the decision and the gate chain. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
jaredLunde
force-pushed
the
capy/end-a-job-from
branch
from
November 27, 2026 20:53
e13253d to
783781d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One full
/procscan of every process on the box happened once per job-life event (proc::members), so a cycle's costtracked the sandbox's process table rather than the job: at 731 processes, 28.7 ms per
start→ended→removecycle,1 467
/procopens and 13 436 allocations. Both halves of that are gone.A job this server spawned now ends from the kernel's child list. execd is the subreaper, so every process of a job
it spawned descends from it, and a live process's ancestors are live — the topmost is a live child of execd, or the
survivors were adopted by the subreaper, which is execd again. So
waitid(P_ALL, WEXITED|WNOHANG|WNOWAIT) == ECHILD(nochild at all, a zombie included) proves nothing of the job is running.
WNOWAITiswaitid's —waitpidrejects itwith
EINVAL— and it leaves a zombie waitable, so the check never collects a status the reaper must deliver.jobs.rs:2547,jobs.rs:2564→proc::job_gone_owned(proc.rs:497).The scan is still the answer wherever it is needed, unchanged in behaviour: whenever the child list is not empty
(another job, a terminal's keeper, anything execd adopted — which is what a living stray always is), for a job a restart
adopted (
supervise_adopted: a previous execd spawned it, so it is not this process's descendant), on the slow tick, andfor everything that must name processes (
kill,wipe,survivors,terminals). The end still goes throughkernel::step(Ev::GroupEmpty)in the same place.The scan no longer allocates per process.
proc::scanreuses oneScratch: a pathString, theEXECD_JOB_MARK=<mark>bytes, and one read buffer, instead of aformat!and anfs::readper file per process. Samepids, same filter, same syscalls.
Measured on the real release binary (
benches/proc_scan.py, new), one job at a time, 3 warm-up + 10 cycles, p50:/procopens per cycleproc.rsallocations per cycleWith one long-lived job beside the churn (~734 processes) the child list cannot answer and the scan still runs, twice per
cycle there: 30.0 → 20.0 ms,
/procopens 2 759 → 2 580 (no win — stated, not hidden), allocations 28 756 → 3 603 andbytes 7.89 MB → 133 KB, which is part 1 alone.
The benchmark carries the gate:
--assert-proc-opens 1 --assert-flat 1.3passes on this head and fails every row on thepre-change binary (1 494
/procopens per cycle at 746, allocations growing 8.03× across the process counts).One behaviour changes, and it is documented. A process that carries a job's mark without being a descendant of execd
— a client can read the mark off the wire and put it on a process of its own — no longer holds that job open. Every
process that got the mark the documented way inherited it and is a descendant. The state before this change is kept as
the test-only mutant
mut_end_scan_always, not as a shipped switch: no rollback flag (CREW rule 6), and nothing new iswritten to disk so same-build crash recovery is untouched.
Proofs.
tests/job_escape.rsgains a double-forked daemon, a grandchild that outlives its parent, a stray underEXECD_RUN_AS, a check that the fast path fires for a quiet end and stands aside for a busy one, and the forged-markcase.
mut_end_group_only(a gone group reads as the end) turns the three stray tests red;mut_end_scan_always(the fast path removed) turns the fast-path test red. All 32 execd suites pass at this head(including differential's 40 random programs), with
cargo fmt --check,dprint checkandclippy --all-targets -- -D warningsclean on the pinned 1.92 toolchain.ARCHITECTURE.mdgains "The end of a job" under Process model, the tests-table row, and the changed mark caveat.