Commit e65b87a
Add APFS clonefile fast path for macOS VM disk forks (#276)
* Add design proposal: APFS clonefile fast path for macOS VM forks
Documents wiring clonefile(2) into the forkvm reflink slot on darwin so
VM disk forks become copy-on-write-instant on Apple Silicon, with a
sparse-copy fallback for cross-volume cases.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* forkvm: add APFS clonefile(2) reflink fast path on darwin
Wire Apple's clonefile(2) into forkvm's reflink->sparse fallback ladder so
forking a guest directory on APFS becomes a near-instant, copy-on-write,
space-shared operation instead of a dense SEEK_DATA/SEEK_HOLE byte copy.
clonefile(2) requires the destination to not exist, so the darwin path removes
any stale destination first, clones with CLONE_NOFOLLOW|CLONE_NOOWNERCOPY, then
chmods to honor the perms contract. Unsupported/cross-volume failures
(ENOTSUP/EOPNOTSUPP/EXDEV/EEXIST/EINVAL/ENOTDIR) map to ErrReflinkUnsupported to
fall back to the sparse copy; EIO/ENOSPC/EACCES propagate. The non-Linux stub is
retagged to !linux && !darwin so darwin uses the new file.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* TEMP(ci): narrow to forkvm reflink feature — revert before merge
Disable the linux test and e2e-install jobs on this branch and run only the
forkvm tests on the darwin runner (make test TEST='Reflink|CopyGuestDirectory|
CopyRegularFile|Sparse|Clone') so this PR gets fast, focused darwin signal.
Revert this commit before merge.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* TEMP(ci): quote forkvm test regex so the | survives the make recipe
The make recipe substitutes -run=$(TEST) unquoted, so the recipe shell split
the alternation on |. Wrap the regex in embedded single quotes so go test
receives it intact. Part of the temporary forkvm-only narrowing; revert before
merge.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* forkvm: fix darwin clone tests for the macOS runner
Use a short /tmp base in the clone-correctness test so the unix socket fits the
sockaddr length limit (macOS t.TempDir() under /var/folders is too long), and
assert CoW block sharing via volume free space (statfs) rather than per-file
st_blocks, which still reports the full logical size for an APFS clone.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* forkvm: harden darwin clone tests and tighten errno mapping
Address review findings on the APFS clonefile fast path:
- SharesBlocks now compares the clone's free-space consumption against a
dense control file written in the same window instead of an absolute
statfs delta, so concurrent cross-package activity on the shared runner
perturbs both samples rather than flaking the assertion.
- Drop EINVAL and ENOTDIR from isReflinkUnsupportedError: on clonefile(2)
these are programming/path errors, not capability signals, so silently
falling back would mask a broken flag set. They now propagate.
- Add skipUnlessAPFS so clone tests fail hard (not skip) when
HYPEMAN_REQUIRE_APFS_CLONE=1, preventing a false green on a non-APFS
runner; clone-correctness probes APFS before asserting.
- Add a darwin integration test that injects a clonefile rejection via a
test seam and verifies the sparse fallback still yields identical bytes.
- Trim the CLONE_NOFOLLOW comment to note it is defensive only.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* TEMP(ci): verbose darwin run + require APFS clone — revert before merge
Set VERBOSE=1 so the narrowed darwin run logs per-test PASS/SKIP (proving
the clone tests executed), and HYPEMAN_REQUIRE_APFS_CLONE=1 so an
unexpected non-APFS skip fails the step instead of reporting a false
green. Revert alongside the other TEMP(ci) commits before merge.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* ci: restore full test workflow (drop temporary Rosetta-narrowing)
Reverts the temporary CI narrowing used during development; runs the full
linux + darwin + e2e-install suite again.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* forkvm: add macOS fork-speed benchmark (clonefile vs sparse)
BenchmarkForkGuestDisk copies a dense guest-disk-shaped file via the APFS
clonefile fast path and the sparse-copy fallback (the pre-clonefile
behavior) for an apples-to-apples comparison. Includes a temporary CI
step to capture the numbers on the macOS runner.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* ci: drop temporary fork-speed benchmark step
Numbers captured; the BenchmarkForkGuestDisk benchmark remains runnable
via `go test -bench=BenchmarkForkGuestDisk ./lib/forkvm/`.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* instances: add end-to-end VM fork-speed measurement
TestVZForkSpeed (gated behind HYPEMAN_FORK_BENCH) times mgr.ForkInstance
end to end — copy guest disk + rewrite manifest + materialize a stopped
instance — with the APFS clonefile fast path vs the sparse fallback, on a
source given a dense overlay. Includes a temporary CI step to capture the
numbers on the macOS runner.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* ci: drop temporary e2e fork-speed step
Numbers captured; TestVZForkSpeed remains runnable via HYPEMAN_FORK_BENCH=1.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* Address review: align clonefile RFC with shipped errno behavior
- Drop EEXIST from isReflinkUnsupportedError: the pre-clone os.Remove
owns the "destination exists" case, so a per-file EEXIST is unreachable
and should propagate rather than flip the whole walk to sparse.
- Remove the flake-prone CoW free-space test and its statfs helpers; the
fork-speed benchmark already evidences the space/latency win.
- Reconcile the RFC's errno block, prose, and testing plan with the
shipped mapping (EINVAL/ENOTDIR/EEXIST propagate, not fall back), soften
the perm-parity claim (umask divergence), and trim volatile x/sys
generated-file line numbers to stable public symbols.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* forkvm: address review — CoW write-isolation test + test hygiene + doc fixes
From hiro's review of #276 (all non-blocking):
- Add TestCopyRegularFileReflink_WriteIsolation: writing to a clone must not
modify the source (the headline CoW correctness property; previously only
verified manually).
- fork_speed_darwin_test: reset the global reflink flag via t.Cleanup so a
require failure mid-loop can't leak disabled-state into other tests.
- copy_bench_darwin_test: note the shared source means the sparse sub-benchmark
reads cache-warm (ratio valid; absolute sparse number is warm-cache).
- copy_reflink_darwin_test: listener close via t.Cleanup (consistency).
- proposal: correct the unix.Clonefile availability note (generated per-arch,
links on both darwin/arm64 and darwin/amd64; verified via go doc).
The reflinkDisabled flag is left in place: it predates this PR (lib/forkvm/copy.go
on main) and is used by existing tests to exercise the sparse fallback path
deterministically; removing it is out of scope here.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: rgarcia <72655+rgarcia@users.noreply.github.com>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>1 parent 8331138 commit e65b87a
6 files changed
Lines changed: 821 additions & 4 deletions
File tree
- docs/proposals
- lib
- forkvm
- instances
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
| 10 | + | |
| 11 | + | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
0 commit comments