Skip to content

[PHP] refactor: preserve first-fit mmap gap selection#751

Merged
brandonpayton merged 1 commit into
integration/kd-6nz-php-phpt-platform-fixesfrom
gascity/kd-6nz/split-pr717-mmap-gap-sort
Jul 11, 2026
Merged

[PHP] refactor: preserve first-fit mmap gap selection#751
brandonpayton merged 1 commit into
integration/kd-6nz-php-phpt-platform-fixesfrom
gascity/kd-6nz/split-pr717-mmap-gap-sort

Conversation

@brandonpayton

@brandonpayton brandonpayton commented Jun 20, 2026

Copy link
Copy Markdown
Member

Why

MemoryManager selects automatic mmap and host-reserved ranges from two address-ordered collections. The previous implementation concatenated and sorted those collections before every scan. This replacement walks the two ordered collections together while preserving the same first-fit result.

The original split also carried an unrelated munmap-rounding regression test whose implementation and stronger focused coverage are now owned by #756.

This is an unmeasured internal refactor. It makes no throughput or PHP/PHPT coverage claim.

What

  • Normalize fork-restored mappings once at their ingestion boundary so the address-order invariant is explicit.
  • Walk mappings and host reservations as two ordered streams in find_gap().
  • Compare every result against a test-only copy of the former collect-and-stable-sort algorithm.
  • Cover empty, interleaved, equal-start, overlapping, below-base, exact-fit, exhaustion, and 675 systematic relative layouts.
  • Drop the redundant munmap-rounding test already covered by [PHP] fix: preserve process-shared state across fork and exec #756.

Review changes

The original source commit was not replayed. Review found that its copied #756 test failed on the stale source branch and that its measurable-overhead, throughput, and retained-PHP claims had no benchmark or exact-tree PHPT evidence. The replacement makes the restored-order invariant explicit, adds reference-equivalence coverage, removes the redundant test, and states the evidence boundary directly.

Contract scope

Automatic mmap addresses are observable, so equivalence with the former first-fit algorithm is the load-bearing requirement. No host, browser, libc, package, or structural ABI surface is intended to change.

Validation

On replacement source commit 7336e524836773027951dda95f1607fbc39429c1:

  • git diff HEAD^ HEAD --check: clean.
  • Focused memory::tests: 36/36 passed.
  • scripts/dev-shell.sh cargo test -p kandelo --target aarch64-apple-darwin --lib: 1,104/1,104 passed.
  • scripts/dev-shell.sh bash scripts/check-abi-version.sh: passed; snapshot, C header, and TypeScript bindings are synchronized.

Full host, libc, POSIX, Sortix, browser, PHPT, and performance gates remain deferred to the Batch 2 aggregate. Performance was not measured.

Review view

Accept as an unmeasured kernel-internal equivalence refactor. The replacement preserves first-fit selection across ordered streams, normalizes restored input at its boundary, removes stale duplicated coverage, and makes no workload claim beyond the evidence run.

Merge the address-sorted guest mapping and host reservation streams without materializing a combined list. Normalize fork-restored mappings once at their ingestion boundary so the ordering invariant is explicit.

Reference-equivalence tests cover interleaving, equal starts, overlap, exact fits, exhaustion, and systematic relative orderings. The copied munmap regression from the original PR remains owned by #756.

This is an unmeasured internal refactor. It makes no throughput or PHP/PHPT coverage claim and changes no intended host or ABI contract.
@brandonpayton
brandonpayton force-pushed the gascity/kd-6nz/split-pr717-mmap-gap-sort branch from bb8a322 to 7336e52 Compare July 11, 2026 19:39
@brandonpayton brandonpayton changed the title [PHP] perf: avoid per-mmap gap sort allocation [PHP] refactor: preserve first-fit mmap gap selection Jul 11, 2026
@brandonpayton
brandonpayton changed the base branch from integration/kd-6nz-php-phpt-harness-only-base to integration/kd-6nz-php-phpt-platform-fixes July 11, 2026 19:40
@brandonpayton
brandonpayton merged commit 347bcea into integration/kd-6nz-php-phpt-platform-fixes Jul 11, 2026
@brandonpayton
brandonpayton deleted the gascity/kd-6nz/split-pr717-mmap-gap-sort branch July 11, 2026 19:40
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