Skip to content

Commit 2e29fdf

Browse files
committed
rename enable_diff_snapshots API paramter to track_dirty_pages
We have two different API parameters that do the same thing in two different APIs: For booted VMs, we enable KVM dirty page tracking by setting track_dirty_pages to true in /machine-config. For resumed VMs, we enable KVM dirty page tracking by setting enable_diff_snapshots to true in /snapshot/load. Apart from being inconsistent for no reason, one of these is very badly named: With support for diff snapshots without dirty page tracking, enable_diff_snapshots is a misnomer, because setting it to false will still allow us to do diff snapshots, it'll just fall back to mincore. Rename enable_diff_snapshots to track_dirty_pages, so we're consistent and also so that the parameter reflects what is actually happening. Go through the whole deprecation cycle of deprecating enable_diff_snapshots and adding the new track_dirty_pages parameter at the same time. We will need to remove enable_diff_snapshots in 2.0 Signed-off-by: Patrick Roy <[email protected]>
1 parent 2c27ff6 commit 2e29fdf

File tree

10 files changed

+104
-86
lines changed

10 files changed

+104
-86
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ and this project adheres to
3131

3232
### Deprecated
3333

34+
- [#5274](https://github.com/firecracker-microvm/firecracker/pull/5274):
35+
Deprecated the `enable_diff_snapshots` parameter of the `/snapshot/load` API.
36+
Use `track_dirty_pages` instead.
37+
3438
### Removed
3539

3640
### Fixed

DEPRECATED.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ a future major Firecracker release, in accordance with our
2121
The functionality is substituted with ACPI.
2222
- \[[#2628](https://github.com/firecracker-microvm/firecracker/pull/2628)\] The
2323
`--basic` parameter of `seccompiler-bin`.
24+
- \[[#5274](https://github.com/firecracker-microvm/firecracker/pull/5274)\]: The
25+
`enable_diff_snapshots` body field in `PUT` requests on `/snapshot/load`

docs/device-api.md

Lines changed: 62 additions & 62 deletions
Large diffs are not rendered by default.

docs/snapshotting/snapshot-support.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ the snapshot. If they exist, the files will be truncated and overwritten.
277277
contents are only guaranteed to be committed/flushed to the host FS, but not
278278
necessarily to the underlying persistent storage (could still live in host
279279
FS cache).
280-
- If diff snapshots were enabled, the snapshot creation resets then the
281-
dirtied page bitmap and marks all pages clean (from a diff snapshot point of
282-
view).
280+
- If dirty page tracking is enabled, the snapshot creation resets then the
281+
dirtied page bitmap and marks all pages clean (from a dirty page tracking
282+
point of view).
283283

284284
- _on failure_: no side-effects.
285285

@@ -388,7 +388,7 @@ curl --unix-socket /tmp/firecracker.socket -i \
388388
"backend_path": "./mem_file",
389389
"backend_type": "File"
390390
},
391-
"enable_diff_snapshots": true,
391+
"track_dirty_pages": true,
392392
"resume_vm": false
393393
}'
394394
```
@@ -424,7 +424,7 @@ curl --unix-socket /tmp/firecracker.socket -i \
424424
-d '{
425425
"snapshot_path": "./snapshot_file",
426426
"mem_file_path": "./mem_file",
427-
"enable_diff_snapshots": true,
427+
"track_dirty_pages": true,
428428
"resume_vm": false
429429
}'
430430
```
@@ -455,8 +455,8 @@ to the new Firecracker process as they were to the original one.
455455
the guest memory and leads to undefined behavior.
456456
- The file indicated by `snapshot_path`, that is used to load from, is
457457
released and no longer used by this process.
458-
- If `enable_diff_snapshots` is set, then diff snapshots can be taken
459-
afterwards.
458+
- If `track_dirty_pages` is set, subsequent diff snapshots will be based on
459+
KVM dirty page tracking.
460460
- If `resume_vm` is set, the vm is automatically resumed if load is
461461
successful.
462462
- _on failure_: A specific error is reported and then the current Firecracker

src/firecracker/src/api_server/request/snapshot.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use super::super::parsed_request::{ParsedRequest, RequestError};
1313
use super::super::request::{Body, Method, StatusCode};
1414

1515
/// Deprecation message for the `mem_file_path` field.
16-
const LOAD_DEPRECATION_MESSAGE: &str = "PUT /snapshot/load: mem_file_path field is deprecated.";
16+
const LOAD_DEPRECATION_MESSAGE: &str =
17+
"PUT /snapshot/load: mem_file_path and enable_diff_snapshots fields are deprecated.";
1718
/// None of the `mem_backend` or `mem_file_path` fields has been specified.
1819
pub const MISSING_FIELD: &str =
1920
"missing field: either `mem_backend` or `mem_file_path` is required";
@@ -80,7 +81,8 @@ fn parse_put_snapshot_load(body: &Body) -> Result<ParsedRequest, RequestError> {
8081
// Check for the presence of deprecated `mem_file_path` field and create
8182
// deprecation message if found.
8283
let mut deprecation_message = None;
83-
if snapshot_config.mem_file_path.is_some() {
84+
#[allow(deprecated)]
85+
if snapshot_config.mem_file_path.is_some() || snapshot_config.enable_diff_snapshots {
8486
// `mem_file_path` field in request is deprecated.
8587
METRICS.deprecated_api.deprecated_http_api_calls.inc();
8688
deprecation_message = Some(LOAD_DEPRECATION_MESSAGE);
@@ -103,7 +105,9 @@ fn parse_put_snapshot_load(body: &Body) -> Result<ParsedRequest, RequestError> {
103105
let snapshot_params = LoadSnapshotParams {
104106
snapshot_path: snapshot_config.snapshot_path,
105107
mem_backend,
106-
enable_diff_snapshots: snapshot_config.enable_diff_snapshots,
108+
#[allow(deprecated)]
109+
track_dirty_pages: snapshot_config.enable_diff_snapshots
110+
|| snapshot_config.track_dirty_pages,
107111
resume_vm: snapshot_config.resume_vm,
108112
network_overrides: snapshot_config.network_overrides,
109113
};
@@ -180,7 +184,7 @@ mod tests {
180184
backend_path: PathBuf::from("bar"),
181185
backend_type: MemBackendType::File,
182186
},
183-
enable_diff_snapshots: false,
187+
track_dirty_pages: false,
184188
resume_vm: false,
185189
network_overrides: vec![],
186190
};
@@ -202,15 +206,15 @@ mod tests {
202206
"backend_path": "bar",
203207
"backend_type": "File"
204208
},
205-
"enable_diff_snapshots": true
209+
"track_dirty_pages": true
206210
}"#;
207211
let expected_config = LoadSnapshotParams {
208212
snapshot_path: PathBuf::from("foo"),
209213
mem_backend: MemBackendConfig {
210214
backend_path: PathBuf::from("bar"),
211215
backend_type: MemBackendType::File,
212216
},
213-
enable_diff_snapshots: true,
217+
track_dirty_pages: true,
214218
resume_vm: false,
215219
network_overrides: vec![],
216220
};
@@ -240,7 +244,7 @@ mod tests {
240244
backend_path: PathBuf::from("bar"),
241245
backend_type: MemBackendType::Uffd,
242246
},
243-
enable_diff_snapshots: false,
247+
track_dirty_pages: false,
244248
resume_vm: true,
245249
network_overrides: vec![],
246250
};
@@ -276,7 +280,7 @@ mod tests {
276280
backend_path: PathBuf::from("bar"),
277281
backend_type: MemBackendType::Uffd,
278282
},
279-
enable_diff_snapshots: false,
283+
track_dirty_pages: false,
280284
resume_vm: true,
281285
network_overrides: vec![NetworkOverride {
282286
iface_id: String::from("eth0"),
@@ -306,7 +310,7 @@ mod tests {
306310
backend_path: PathBuf::from("bar"),
307311
backend_type: MemBackendType::File,
308312
},
309-
enable_diff_snapshots: false,
313+
track_dirty_pages: false,
310314
resume_vm: true,
311315
network_overrides: vec![],
312316
};

src/firecracker/swagger/firecracker.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,11 @@ definitions:
12451245
enable_diff_snapshots:
12461246
type: boolean
12471247
description:
1248-
Enable support for incremental (diff) snapshots by tracking dirty guest pages.
1248+
(Deprecated) Enable dirty page tracking to improve space efficiency of diff snapshots
1249+
track_dirty_pages:
1250+
type: boolean
1251+
description:
1252+
Enable dirty page tracking to improve space efficiency of diff snapshots
12491253
mem_file_path:
12501254
type: string
12511255
description:

src/vmm/src/persist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ pub fn restore_from_snapshot(
347347
return Err(SnapshotStateFromFileError::UnknownNetworkDevice.into());
348348
}
349349
}
350-
let track_dirty_pages = params.enable_diff_snapshots;
350+
let track_dirty_pages = params.track_dirty_pages;
351351

352352
let vcpu_count = microvm_state
353353
.vcpu_states

src/vmm/src/rpc_interface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ mod tests {
12491249
backend_type: MemBackendType::File,
12501250
backend_path: PathBuf::new(),
12511251
},
1252-
enable_diff_snapshots: false,
1252+
track_dirty_pages: false,
12531253
resume_vm: false,
12541254
network_overrides: vec![],
12551255
},

src/vmm/src/vmm_config/snapshot.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ pub struct LoadSnapshotParams {
6464
pub snapshot_path: PathBuf,
6565
/// Specifies guest memory backend configuration.
6666
pub mem_backend: MemBackendConfig,
67-
/// Setting this flag will enable KVM dirty page tracking and will
68-
/// allow taking subsequent incremental snapshots.
69-
pub enable_diff_snapshots: bool,
67+
/// Whether KVM dirty page tracking should be abled, to space optimization
68+
/// of differential snapshots.
69+
pub track_dirty_pages: bool,
7070
/// When set to true, the vm is also resumed if the snapshot load
7171
/// is successful.
7272
pub resume_vm: bool,
@@ -90,7 +90,11 @@ pub struct LoadSnapshotConfig {
9090
pub mem_backend: Option<MemBackendConfig>,
9191
/// Whether or not to enable KVM dirty page tracking.
9292
#[serde(default)]
93+
#[deprecated]
9394
pub enable_diff_snapshots: bool,
95+
/// Whether KVM dirty page tracking should be enabled.
96+
#[serde(default)]
97+
pub track_dirty_pages: bool,
9498
/// Whether or not to resume the vm post snapshot load.
9599
#[serde(default)]
96100
pub resume_vm: bool,

src/vmm/tests/integration_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fn verify_load_snapshot(snapshot_file: TempFile, memory_file: TempFile) {
245245
backend_path: memory_file.as_path().to_path_buf(),
246246
backend_type: MemBackendType::File,
247247
},
248-
enable_diff_snapshots: false,
248+
track_dirty_pages: false,
249249
resume_vm: true,
250250
network_overrides: vec![],
251251
}))
@@ -329,7 +329,7 @@ fn verify_load_snap_disallowed_after_boot_resources(res: VmmAction, res_name: &s
329329
backend_path: memory_file.as_path().to_path_buf(),
330330
backend_type: MemBackendType::File,
331331
},
332-
enable_diff_snapshots: false,
332+
track_dirty_pages: false,
333333
resume_vm: false,
334334
network_overrides: vec![],
335335
});

0 commit comments

Comments
 (0)