-
Notifications
You must be signed in to change notification settings - Fork 9
Snapshot shm via APFS fclonefileat for safe CoW #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The child elfuse process is already spawned by
posix_spawnatsrc/runtime/forkipc.c:1324, well before any of the snapshot/IPC steps run. Everygoto fail_snapshotafter that point therefore unwinds with a live child, but thefail_snapshot:block (src/runtime/forkipc.c:1637) only doesclose(ipc_sock)(:1655) and returns-LINUX_ENOMEM(:1660). It never reaps the child, and nothing else does either — so the child becomes a zombie that lingers for the parent elfuse's lifetime.Why it becomes a zombie
close(ipc_sock)makes the child exit (it reads EOF on the control socket and bails), but exiting is exactly what creates the zombie: on macOS a child that has exited is kept as a<defunct>entry until its parentwaitpids it. elfuse installs no hostSIGCHLDhandler and sets neitherSIG_IGNnorSA_NOCLDWAIT(the only host-side touch ispthread_sigmask(SIG_BLOCK, …)insrc/core/rosetta.c:1094, which merely defers delivery), so the kernel will not auto-discard the status. Something must callwaitpid— and on this path nothing does:sys_wait4→ hostwait4): the path returns-LINUX_ENOMEM, i.e. the guest'sfork()reports failure, so the guest believes no child exists and never waits for it.proc_reap_finished()sweepsproc_tablewithwaitpid(WNOHANG)): entries land inproc_tableonly viaproc_register_child, which runs only on the success path atsrc/runtime/forkipc.c:1603. A child unwound throughfail_snapshotis never registered, so the sweep never sees it.Both reapers key off "child was registered / guest knows about it." On the failure path neither holds, so no
waitpidforchild_host_pidis ever issued and the zombie persists. For a long-running, fork-heavy guest that repeatedly hits this path, zombies accumulate and consume host PIDs.Scope note — which new fail points actually reach this path
This is pre-existing debt in
fail_snapshot, but this PR changes the odds of reaching it:mkdtemp/fclonefileat/openinsidefork_snapshot_shm_via_clonefile()return-1and the caller falls back (rosetta →use_shm = falseat:1455; native → liveshm_fd). They do notgoto fail_snapshot.pwritefailure doesgoto fail_snapshot, and that block is pre-existing (the PR only moved it ahead of the header).use_shm = false, so the overlay-syncpwriteblock was skipped entirely and could not reachfail_snapshot; post-PR Rosetta runsuse_shm = true(:1448) and now executes thatpwrite, adding one newfail_snapshottrigger for Rosetta guests.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed and fixed.
Primary fix (this thread): every
goto fail_snapshotlands afterposix_spawn, sochild_host_pidis always a live process there. After closingipc_sock(which makes the child read EOF onfork_ipc_read_alland return nonzero fromfork_child_main), reap it explicitly:A blocking
waitpidis safe becausefork_ipc_write_allonly returns -1 when the write didn't deliver, so the child always sees EOF on a parent-side IPC failure (no pathological "child finished restore while parent thinks send failed" case to defend against).Bonus fix found while reviewing this patch:
vfork_notify_fds[1]is closed at the post-spawn cleanup (line 1342) but never reset to -1, so the guardedclose(vfork_notify_fds[1])infail_snapshotdouble-closes. In a multithreaded guest another vCPU can open a new fd between the two closes and the second close would steal it. Pre-existing, but adjacent to the lines this PR touches, so folded in:vfork_notify_fds[1] = -1;after the first close.Validation: temporarily injected
goto fail_snapshotimmediately afterposix_spawn, ran a fork-then-sleep guest, andps -axo pid,ppid,statunder the elfuse parent showed:<defunct>child (STAT=ZN)