Skip to content

uffd: serve firecracker page faults from a shared template mem-file#216

Draft
sjmiller609 wants to merge 1 commit intohypeship/fork-shared-memfilefrom
hypeship/uffd-page-server
Draft

uffd: serve firecracker page faults from a shared template mem-file#216
sjmiller609 wants to merge 1 commit intohypeship/fork-shared-memfilefrom
hypeship/uffd-page-server

Conversation

@sjmiller609
Copy link
Copy Markdown
Collaborator

Stacked on: #214 (shared mem-file) — review #213#214 first.

Summary

  • New lib/uffd package: a userfaultfd page server that backs many concurrent fan-out forks against a single read-only template mem-file.
  • Each fork's firecracker connects to a per-fork UDS, hands the server its userfaultfd via SCM_RIGHTS plus a JSON mappings handshake; the server then services UFFD_EVENT_PAGEFAULT with UFFDIO_COPY reads from the template.
  • Linux hot path lives in server_linux.go behind a build tag; non-Linux builds return ErrUnsupported so callers can fall back to MAP_PRIVATE.
  • Tests cover the cross-platform handshake parser and Server lifecycle.

Why

Symlinking the mem-file (the prior PR) avoids the copy but still forces firecracker to MAP_PRIVATE the file, so every page is COW'd on first touch. UFFD lets all forks share the read-only template extents and only allocate guest pages on actual writes — the canonical fan-out memory model for firecracker.

Test plan

  • go test ./lib/uffd/... (cross-platform parser/lifecycle)
  • Manual integration: configure firecracker with UFFD memory backend pointing at this server's UDS, restore a snapshot, confirm page faults are served and the guest boots
  • Stress: launch N=20 forks against one server, watch pmap to confirm pages are shared

🤖 Generated with Claude Code

Adds lib/uffd, a userfaultfd page server that backs many concurrent
fan-out forks against a single read-only template mem-file instead of
letting each fork mmap it privately. Firecracker connects to a per-fork
UDS, hands us its userfaultfd via SCM_RIGHTS along with a JSON
mappings handshake, and the server then services UFFD_EVENT_PAGEFAULT
events with UFFDIO_COPY reads from the template.

The Linux hot path lives behind a build tag; non-Linux builds return
ErrUnsupported so callers can fall back to MAP_PRIVATE. Cross-platform
tests cover the handshake parser and the server lifecycle.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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