Skip to content

Commit f47b9b7

Browse files
committed
doc: document mincore-based diff snapshots
Document that diff snapshots can work even without dirty page tracking, and what the drawbacks of this are (bigger snapshots, no swap support). Signed-off-by: Patrick Roy <[email protected]>
1 parent 2e29fdf commit f47b9b7

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

docs/snapshotting/snapshot-support.md

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,18 @@ the microVM in the `Paused` state. **Effects**:
207207
Now that the microVM is paused, you can create a snapshot, which can be either a
208208
`full`one or a `diff` one. Full snapshots always create a complete, resume-able
209209
snapshot of the current microVM state and memory. Diff snapshots save the
210-
current microVM state and the memory dirtied since the last snapshot (full or
211-
diff). The result of a diff snapshot will be a sparse file, with only dirty
212-
pages written (and undirtied ranges becoming holes). Diff snapshots are
213-
generally not resume-able, but must be merged with a base snapshot into a full
214-
snapshot. The exception here are diff snapshots of booted VMs, which are
215-
immediately resumable. In this context, we will refer to the base as the first
216-
memory file created by a `/snapshot/create` API call and the layer as a memory
217-
file created by a subsequent `/snapshot/create` API call. The order in which the
218-
snapshots were created matters and they should be merged in the same order in
219-
which they were created. To merge a `diff` snapshot memory file on top of a
220-
base, users should copy its content over the base. This can be done using the
221-
`rebase-snap` (deprecated) or `snapshot-editor` tools provided with the
222-
firecracker release:
210+
current microVM state and the memory accessed since the last snapshot (full or
211+
diff). The result of a diff snapshot will be a sparse file, with only accessed
212+
pages written (and other ranges becoming holes). Diff snapshots are generally
213+
not resume-able, but must be merged with a base snapshot into a full snapshot.
214+
The exception here are diff snapshots of booted VMs, which are immediately
215+
resumable. In this context, we will refer to the base as the first memory file
216+
created by a `/snapshot/create` API call and the layer as a memory file created
217+
by a subsequent `/snapshot/create` API call. The order in which the snapshots
218+
were created matters and they should be merged in the same order in which they
219+
were created. To merge a `diff` snapshot memory file on top of a base, users
220+
should copy its content over the base. This can be done using the `rebase-snap`
221+
(deprecated) or `snapshot-editor` tools provided with the firecracker release:
223222

224223
```bash
225224
snapshot-editor edit-memory rebase \
@@ -309,10 +308,20 @@ curl --unix-socket /tmp/firecracker.socket -i \
309308

310309
**Prerequisites**: The microVM is `Paused`.
311310

312-
*Note*: On a fresh microVM, `track_dirty_pages` field should be set to `true`,
313-
when configuring the `/machine-config` resource, while on a snapshot loaded
314-
microVM, `enable_diff_snapshots` from `PUT /snapshot/load`request body, should
315-
be set.
311+
*Note*: Diff snapshots come in two flavors. If `track_dirty_pages` was set to
312+
`true` when configuring the `/machine-config` resource or when restoring from a
313+
snapshot via `/snapshot/load`, Firecracker will use KVM's dirty page log runtime
314+
functionality to ensure the diff snapshot only contains exactly pages that were
315+
written to since boot / snapshot restoration. If `track_dirty_pages` is not
316+
enabled, Firecracker will instead over-approximate the set of pages to include
317+
in the snapshot by instead considering all pages that were _accessed_ since the
318+
VM was booted/resumed. This potentially results in bigger memory files (although
319+
they are still sparse), but avoids the runtime overhead of dirty page logging.
320+
321+
Without dirty page tracking enabled, Firecracker uses the
322+
[`mincore(2)`][man mincore] syscall to determine which pages to include in the
323+
snapshot. As such, this mode of snapshot taking will only work _if swap is
324+
disabled_, as mincore does not consider pages written to swap to be "in core".
316325

317326
**Effects**:
318327

@@ -628,3 +637,5 @@ the compatibility table reported below:
628637
For example, a snapshot taken on a m6i.metal host running a 5.10 host kernel can
629638
be restored on a different m6i.metal host running a 6.1 host kernel (but not
630639
vice versa), but could not be restored on a c5n.metal host.
640+
641+
[man mincore]: https://man7.org/linux/man-pages/man2/mincore.2.html

0 commit comments

Comments
 (0)