notes

The free-page-frames sweep, 2026-09-23

(An appendix of notes/load-sensitive-assertions.md, which holds the register and the rules. Moved here on 2026-09-24 and tightened; pull request #1211's first commit has the text verbatim.)

The sweep, 2026-09-23: all forty-six reads of the global counter, classified

The two fixes in the unowned reds were each found by a red CI leg and fixed one at a time, which is the expensive way to find the rest. This is the other way. It reads every call of crate::memory::free_page_frames() in kernel/src and says, for each one, which of the two fixes fits, or that neither does and why.

There are forty-six reads in the tree, and "46 sites" and "46 hazards" are different claims. One is the definition itself (memory.rs). Two are prose in doc comments recording that a site once read it. One is the companion largest_free_run's cross-reference. That leaves 42 executable reads, in nine files.

The classification

Kind Count Where
Not an assertion (diagnostic, ledger, demo report) 7 testing.rs (2), user.rs (3), arch/x86_64/mmu.rs (2)
Named-frame case, fixed here 35 sched.rs (15), user/force_kill_tests.rs (13), user/tests.rs (4), user/cpu_time_tests.rs (3)
Scoped-count case (memory_region::usage) 0 remaining the one instance was live_swap_tests.rs, fixed 2026-09-22
Neither fits 0 remaining the one instance was current_cpu_tests.rs, fixed 2026-09-23

Every assertion in the tree that bracketed the global counter is gone. Not one of the 35 needed a mechanism that did not exist, which was the surprise. The expectation going in was a long tail of category-four sites wanting a kernel API nobody had written.

(Scope, added 2026-09-24: this sweep read free_page_frames() only. Assertions that bracket memory::stats() or thread_count() have the same shape and were not read; the main page's "Where to look for the next one" has the counts.)

Why they were all one shape, and what that shape is

Every one of the 35 was a test that created one or more root memory_regions, did something to them, reclaimed them, and asserted the machine's free-frame count was back where it started. The property each was reaching for is "this region's pages came back". A root region's pages are allocator bits: memory_region::create takes them with alloc_contiguous, and destroy returns every one of them with memory::free. So the region's own run of frames, asked about one bit at a time with memory::is_page_frame_used, is the property itself.

That is the current_cpu_tests.rs fix generalized from one frame to a run. The generalization is testing::RegionRun (name provisional), a test-only type in the #[cfg(test)] harness module rather than a kernel surface:

let region = crate::memory_region::create(16).expect("no region for the runaway");
let run = crate::testing::RegionRun::of(region);   // names the run, and asserts every frame used
// ... start a runaway, force-kill it, reclaim its region ...
run.assert_returned("reclaiming a force-killed runaway did not return its frames");

of carries the vacuity guard the current_cpu_tests.rs fix established. It asserts every frame in the run is currently marked used, so a wrong base address fails loudly at capture. Otherwise it would read as "not used" after the reclaim and pass for the wrong reason. assert_held is the third method, for tests whose claim is that pages did not reach the allocator: a split child's pages go back to its parent, and a lent region is not the borrower's to free.

What each fixed test gained beyond not flaking

The seven that stay, and why they are not the same thing

They are not assertions about a window, which is what makes a global count wrong. They are reports.

BUGS