notes

The page frame budget: what a test boot spends, and what it gets back

Name: provisional, minted 2026-10-11 (UTC) by lane/next-ten-longest-notes.

An appendix to notes/frames.md, which summarizes it. This is the receipt for the failure that misled three milestones. It is written as a budget rather than as a story, because the number is the point.

The symptom, and why it always accused the wrong test

The aarch64 test boot failed as Unmappable(OutOfPageFrames) about one run in three (measured 2026-08-16). It failed in whatever test happened to spawn last, which was never the test that spent the memory. It failed disguised: milestone 107 (socket) met it as time_tests reporting "no swish program in the initrd archive, or no memory to wire one", which reads like a packaging bug and is not one. notes/net/memory-and-reclamation.md had recorded it eight separate times as "virtio::MAX_DEVICES has asked for reclamation again".

Two numbers, not one, and the second is the one that fails a boot. Free page frames and the longest run of free page frames are different questions, and alloc_contiguous asks the second. Milestone 107 measured 137 page frames free and no run of 128 at the failing allocation and read it as exhaustion. Both readings now exist: memory::free_page_frames() and memory::largest_free_run() (PageFrameAllocator::largest_free_run, host-tested in crates/page_frames/tests/allocator.rs).

The instrument: the page frame ledger

kernel/src/testing.rs reads free page frames once per test, at the top, so the readings partition the run: what a test is charged is the drop between its own reading and the next one. That shape is not fussiness. Reading before and after the test body instead charges only what the test spent while it was running. A test that spawns a service and returns the moment it has its report leaves that service still mapping its heap. On the first measured boot, before-and-after attribution left 17362 of 29091 page frames landing nowhere at all.

What a run prints:

test kernel::user::dir_capability_tests::a_full_directory_capability_... ... ok
    [that test kept 2284 frames]
...
frames: 29280 free before the first test, 15249 after the last (14031 never returned); longest free run 14080

A charge under PAGE_FRAME_REPORT_MINIMUM (16 page frames) is silent, so the transcript names the services and not the arithmetic.

Two ceilings fail the run, and the second is the one that names the bug. SUITE_PAGE_FRAME_BUDGET catches the total residue growing past what is accounted for below, which is how a new service-shaped test that forgets to hand its memory back is caught in the act. SUITE_MINIMUM_FREE_RUN requires the boot to end with a free run of at least 1024 page frames, and that is the real gate: loading a program calls alloc_contiguous, so what a boot runs out of is contiguity rather than memory. A suite can pass a residue ceiling and still be fragmented into uselessness, which is exactly the state this one was in.

What the boot spent, measured

free before the first test free after the last never returned longest free run
before 29307 216 29091 117
after reclaiming init 29306 12504 16802 12394
after reclaiming init and the net services 29306 15307 13999 14080
the same, remeasured on the merged tree 29280 15249 14031 14080

216 free page frames and no run longer than 117 is the whole failure. There was no headroom left for anything, so which test died was decided by scheduling.

The fourth row is the same boot after merging main on 2026-08-16. The 32 extra page frames it keeps are the second act of milestone 54 (a network file service a Mac can actually mount). The SMB test now runs a seeding client through the FS service before it wires the adapter, and that client is one more process. The number that decides whether a boot lives is unchanged at 14080, because a client that runs and exits fragments nothing. Read the pair as the honest shape of this ledger: the residue moves a little every time a test grows a process, and the free run is what the gate is about. riscv64 came out at 13787 kept and 13733 longest, from 29692 free.

The largest single causes, before:

page frames who what it was
12289 the six spawn_progenitor tests 2048 page frames of building budget each, reserved and never returned
2759 the ten net tests a net_stack's 128-page-frame budget, its stack, and its client's, ten times
2284 the FS service one block server and one FS server with an 8 MiB heap budget
2146 the two authority_tests root_supervisor's 1024-page-frame budget, twice
1656 the credential store a 6 MiB budget sized by Argon2id's scratch
1362 the crash-recovery FS test two more FS servers, deliberately killed and never reclaimed

The fix, which is wiring and not mechanism

Everything used here is DECISIONS §16 object revocation, already built and already proved. What was missing was a handle and an ordering.

What is still held at the end of a boot, and why

14031 page frames on the merged tree (13999 before that merge; the table above says where the 32 went), and the difference is accounted rather than shrugged at:

BUGS in the ledger itself