Repository navigation
fix(shm): fault a pre-sized table in at creation instead of over the run - #24
Merged
Merged
Conversation
The arena is MAP_ANONYMOUS, so a block's pages arrive on first write. A structure that hands out one record at a time - ResultSlotTable, one slot per spawn - therefore pays for its pages a fault at a time for the whole life of a run, even though the table was pre-sized before the fork and nothing is being allocated. No arena counter can see it: the watermark and the allocator cursor are byte-flat throughout, and the only symptom is the family's RSS climbing with the workload, which is exactly what a memory gate calls a leak. native-php-coroutines#24 reported it as one: ~64 bytes of RSS per slot id consumed - the slot record - with both arena counters at +0.0. Arena::prefault() stores one zero per page across a block. The block is freshly bumped and therefore already zero, so it changes nothing; it only decides whether the residency is charged at creation or spread across the run. ResultSlotTable::create() calls it, which is a pre-fork moment, so the pages are materialized once and shared by the whole family. Measured on the reporting soak (8 slots/round): arena mapping RSS went from 60 KiB climbing to 84 KiB across 392 slots, to a flat 84 KiB from round one. No record shape, table meaning or globals[0] target changes, so LAYOUT_VERSION stays at 5. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U5QRWPfmkZME7hDjU6i5EA
lisachenko
marked this pull request as ready for review
August 16, 2026 09:24
lisachenko
pushed a commit
that referenced
this pull request
Aug 16, 2026
Brings in #24's prefault fix, which lands in the same two places this branch rewrites. `ResultSlotTable::create()` merged cleanly and correctly: the prefault call is kept and its `$size` is computed from THIS branch's geometry, so the whole of the larger table (8 header words, 12 words per slot, up from 4 and 8) is made resident at creation rather than only the part main's arithmetic would have covered. The inline comment's "one per eight slots" no longer matched either geometry and is now stated without the arithmetic. AGENTS.md §6 conflicted - both sides append a bullet after the shared-string rule. Both are kept, prefault first, and the recycling bullet now says why one does not replace the other: a steady-state pool reuses a handful of records and would look page-flat by accident, while a workload whose concurrency really grows still reaches records nothing has touched. The prefault is what makes that second case flat too. Suite on PHP 8.5: 182 tests, 15565 assertions, OK - including both of #24's prefault tests against the new geometry, and green under --order-by=random with MALLOC_CHECK_=3. Both soaks pass unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U5QRWPfmkZME7hDjU6i5EA
This was referenced Aug 16, 2026
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.
The substrate half of lisachenko/native-php-coroutines#24 (parent-side RSS climb the arena metrics do not see).
The mechanism
The arena is
MAP_ANONYMOUS, so a page exists only once something stores to it.ResultSlotTableis pre-sized before the fork, but slots are handed out one per spawn — so the table's pages fault in 64 bytes at a time over the entire run. Nothing is allocated (the bump cursor never moves, no watermark or allocator counter can see it), yet the family's RSS climbs with the workload: ~0.5 KiB per 8-spawn round, measured directly off the arena mapping'sRssin/proc/self/smapsat 62.7 B per consumed slot ≈ the 64-byte slot record. It plateaus only at full capacity (4096 slots / 256 KiB), which no run reaches — indistinguishable from a leak to any memory gate, and reported as one.The fix
Arena::prefault($address, $length)— one zero store per page across a freshly bumped block, called fromResultSlotTable::create(), which is a pre-fork moment. The block is new and already zero, so the store changes nothing; it only decides whether residency is charged at creation or spread across the run. Afterwards, a climb really is a climb — the honest fix, not a suppression.Details that earn their tests:
$address, not at its page boundary — the boundary may belong to the block allocated before this one, and a store there would silently clobber it (pinned by its own test);LAYOUT_VERSIONbump — no record shape, table meaning, orglobals[0]target changes.The consumer-side component of the climb (~77% of it: the runtime's own unpruned per-spawn slot views) is fixed separately in lisachenko/native-php-coroutines#29.
Verification
PHP 8.5.9 (this tree's z-engine line),
-d ffi.enable=1 -d opcache.jit=off:vendor/bin/phpunit— OK (172 tests, 14479 assertions), exit 0; also--order-by=randomandMALLOC_CHECK_=3 MALLOC_PERTURB_=85, both OK.tools/soak.php 5000— SOAK OK;tools/soak-drop.php 5000— SOAK-DROP OK.With this plus the consumer fix,
tools/soak-arena-watermark.phpover there goes fromrss CLIMBING +24.0 KiB / FAILtorss plateau +0.0 KiB / PASSat 40, 120 and 400 rounds with the tolerance untouched, and its--self-teststill fails as it must.🤖 Generated with Claude Code
https://claude.ai/code/session_01U5QRWPfmkZME7hDjU6i5EA