fork: hardlink snapshot mem-file into snapshot forks#221
Draft
sjmiller609 wants to merge 1 commit intohypeship/fork-shared-memfilefrom
Draft
fork: hardlink snapshot mem-file into snapshot forks#221sjmiller609 wants to merge 1 commit intohypeship/fork-shared-memfilefrom
sjmiller609 wants to merge 1 commit intohypeship/fork-shared-memfilefrom
Conversation
Snapshot forks copy the source guest dir into the fork instance dir; the dominant cost is the multi-GB mem-file. Hardlink it instead and skip the file from the directory walk via CopyOptions.SkipRelPaths (introduced for template forks). This is safe because: - snapshot mem-files are immutable - the hypervisor mmaps them MAP_PRIVATE on restore, so fork writes never reach the underlying file - hardlinks survive snapshot deletion via inode refcount, so a deleted snapshot never strands a running fork Falls back to the regular copy walk when no raw mem-file is present.
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.
Summary
CopyOptions.SkipRelPaths, thenos.Link'd into place after the copy returns. Dodges the multi-GB sparse copy and the directory-walk overhead in one step.Why this is safe
MAP_PRIVATEon restore, so fork writes never reach the underlying file — all forks of a snapshot can share the same inode.Stack
hypeship/fork-shared-memfile(PR fork: share template mem-file via symlink for fan-out forks #214) because that PR introducedCopyOptions.SkipRelPaths.share_memoryAPI.Test plan
go test ./lib/instances/ -run TestForkSnapshotHardlinksRawMemoryFilego test ./lib/instances/ -run TestForkSnapshotFromCompressedSourceCopiesRawMemorystill passes (compressed source still gets a real raw file in the fork)go test ./lib/forkvm/stat -c %imatches between the source mem-file and the fork's mem-file