Skip to content

fork: hardlink snapshot mem-file into snapshot forks#221

Draft
sjmiller609 wants to merge 1 commit intohypeship/fork-shared-memfilefrom
hypeship/snapshot-fork-share-memfile
Draft

fork: hardlink snapshot mem-file into snapshot forks#221
sjmiller609 wants to merge 1 commit intohypeship/fork-shared-memfilefrom
hypeship/snapshot-fork-share-memfile

Conversation

@sjmiller609
Copy link
Copy Markdown
Collaborator

Summary

  • Snapshot forks now hardlink the source mem-file into the fork's data dir instead of sparse-copying it.
  • The mem-file is skipped from the directory walk via CopyOptions.SkipRelPaths, then os.Link'd into place after the copy returns. Dodges the multi-GB sparse copy and the directory-walk overhead in one step.
  • Falls back to the normal copy when no raw mem-file is present (e.g. compressed-only snapshot whose decompression failed, or a snapshot kind that doesn't carry guest memory).

Why this is safe

  • Snapshot mem-files are immutable.
  • The hypervisor mmaps them MAP_PRIVATE on restore, so fork writes never reach the underlying file — all forks of a snapshot can share the same inode.
  • Hardlinks survive snapshot deletion via inode refcount, so deleting a snapshot never strands a running fork.
  • Same-FS guarantee holds: snapshot dir and fork dir are both under hypeman's data dir.

Stack

Test plan

  • go test ./lib/instances/ -run TestForkSnapshotHardlinksRawMemoryFile
  • go test ./lib/instances/ -run TestForkSnapshotFromCompressedSourceCopiesRawMemory still passes (compressed source still gets a real raw file in the fork)
  • go test ./lib/forkvm/
  • Manual: fork a Standby snapshot, confirm stat -c %i matches between the source mem-file and the fork's mem-file

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.
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