Skip to content

ADR 0045 D2: substrate v2b wiring — shared base shm + handler CONTINUE arm - #165

Merged
nikhilunni merged 2 commits into
mainfrom
adr-0045-d2-substrate
Jun 10, 2026
Merged

nikhilunni merged 2 commits into
mainfrom
adr-0045-d2-substrate

Conversation

@nikhilunni

Copy link
Copy Markdown
Contributor

Summary

The engrams half of the unified memory substrate (ADR 0045 D2), stacked on #164 (the fork gitlink bump it requires). Ships dark: ENGRAM_FC_UFFD_BASE_DIR is unset everywhere; with it unset every path is byte-identical to today (load bodies omit the field, the handler runs stock Route-B). D3/D4's parity gates flip it on and retire the knob.

When the env points at a tmpfs dir, Uffd restores become the v2b substrate:

guest RAM = MAP_PRIVATE of <dir>/<canonical-manifest>-v<n>.base   (forked FC, MISSING|MINOR)
ResolvedPage::Canonical → ensure-base-populated (SEEK_HOLE probe; idempotent pwrite) + UFFDIO_CONTINUE
ResolvedPage::Chunk     → UFFDIO_COPY (private, unchanged)
guest writes            → kernel-native COW
  • One page-cache copy of base content per host, shared by every same-template VM — File-mode density extended to Uffd restores; the populated fast path skips the chunk fetch entirely on warm bases.
  • The handler creates + sizes the base file before binding its UDS; wait_for_socket orders FC's open(O_RDONLY) after that, so the load always sees a fully-sized file. One path-derivation helper serves both the spawn and the load.
  • Prefault routes canonical positions through the shared install too (a prefault COPY would privately duplicate exactly the hot set the substrate exists to share).
  • Zero chunks: ZEROPAGE (kernel zero page) with a cached COPY-of-zeros fallback on kernels that reject it on this mapping.

Validation (engram-dev, real KVM + forked FC)

  • substrate_uffd_base (new, fork-gated like stock_fork_snapshot_compat, wired into ci.yml): restore round-trips on the fork, base shm created/sized/populated by the handler (SEEK_DATA finds extents), sibling restores against the already-warm base, both VMs alive — green in 21s.
  • snapshot_uffd (stock path, base off): 2/2 green — inertness proof.
  • Handler + FC crates: Linux clippy -D warnings clean; just check green (1047 tests).

Density (PSS) parity measurement is deliberately D3's gate, not this PR.

🤖 Generated with Claude Code

nikhilunni and others added 2 commits June 9, 2026 16:53
Picks up cortexapps/firecracker#4 — the ADR 0045 D1 fork surface: an
optional uffd_base_file load param backing Uffd-restored guest memory
MAP_PRIVATE on a shmem base file with MISSING|MINOR registration.
Inert in this binary: engrams never sends the field yet (that's the D2
wiring PR), and the default path is byte-identical to the current fork
(R2 guard verifies). The fleet roll this triggers ships a drop-in.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The engrams half of the unified memory substrate, dark behind
ENGRAM_FC_UFFD_BASE_DIR (unset everywhere; D3/D4 parity gates flip it
on and retire the knob):

- client: SnapshotLoadBody grows uffd_base_file (skip_serializing_if —
  bodies stay byte-identical to stock when off).
- engram-sandbox-firecracker: FirecrackerConfig.uffd_base_dir; the Uffd
  restore leg derives <dir>/<canonical>-v<n>.base through one helper for
  both the handler spawn (--base-shm) and the FC load, so the two can't
  diverge.
- engram-uffd-handler: a BaseShm module (create+size before the UDS
  binds — FC's open is ordered after wait_for_socket; SEEK_HOLE
  populated-probe; idempotent canonical pwrites) and the substrate
  resolution: ResolvedPage::Canonical → ensure-base-populated +
  UFFDIO_CONTINUE over the chunk range (one page-cache copy shared by
  every same-template VM; the populated fast path skips the chunk fetch
  entirely), ResolvedPage::Chunk → UFFDIO_COPY as today, zero chunks →
  ZEROPAGE with COPY-of-zeros fallback. The prefault path routes
  canonical positions through the shared install too — a prefault COPY
  would privately duplicate exactly the hot pages the substrate shares.
- host-agent env + Tiltfile plumbing.
- tests/substrate_uffd_base.rs (fork-gated like stock_fork_snapshot_compat,
  wired into ci.yml): restore round-trips on the forked FC, the base shm
  is created/sized/populated by the handler, and a sibling restores
  against the already-warm base — green on engram-dev real KVM (21s).
  snapshot_uffd (stock path, base off) stays green; Linux clippy clean.

Rides the fc-fork-substrate-v2-bump gitlink (cortexapps/firecracker#4).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Base automatically changed from fc-fork-substrate-v2-bump to main June 10, 2026 00:31
@nikhilunni
nikhilunni merged commit e81296e into main Jun 10, 2026
2 checks passed
@nikhilunni
nikhilunni deleted the adr-0045-d2-substrate branch June 10, 2026 00:33
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