Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/firecracker/src/api_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ impl ApiServer {
&METRICS.latencies_us.diff_create_snapshot,
"create diff snapshot",
)),
// ADR 0045 off-pause flush — no dedicated latency metric.
SnapshotType::Msync | SnapshotType::MsyncAndState => None,
},
VmmAction::LoadSnapshot(_) => {
Some((&METRICS.latencies_us.load_snapshot, "load snapshot"))
Expand Down
6 changes: 0 additions & 6 deletions src/firecracker/src/api_server/request/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ fn parse_put_snapshot_load(body: &Body) -> Result<ParsedRequest, RequestError> {
network_overrides: snapshot_config.network_overrides,
vsock_override: snapshot_config.vsock_override,
clock_realtime: snapshot_config.clock_realtime,
shared: snapshot_config.shared,
uffd_base_file: snapshot_config.uffd_base_file,
};

Expand Down Expand Up @@ -211,7 +210,6 @@ mod tests {
network_overrides: vec![],
vsock_override: None,
clock_realtime: false,
shared: false,
uffd_base_file: None,
};
let mut parsed_request = parse_put_snapshot(&Body::new(body), Some("load")).unwrap();
Expand Down Expand Up @@ -245,7 +243,6 @@ mod tests {
network_overrides: vec![],
vsock_override: None,
clock_realtime: false,
shared: false,
uffd_base_file: None,
};
let mut parsed_request = parse_put_snapshot(&Body::new(body), Some("load")).unwrap();
Expand Down Expand Up @@ -279,7 +276,6 @@ mod tests {
network_overrides: vec![],
vsock_override: None,
clock_realtime: false,
shared: false,
uffd_base_file: None,
};
let mut parsed_request = parse_put_snapshot(&Body::new(body), Some("load")).unwrap();
Expand Down Expand Up @@ -322,7 +318,6 @@ mod tests {
}],
vsock_override: None,
clock_realtime: false,
shared: false,
uffd_base_file: None,
};
let mut parsed_request = parse_put_snapshot(&Body::new(body), Some("load")).unwrap();
Expand Down Expand Up @@ -353,7 +348,6 @@ mod tests {
network_overrides: vec![],
vsock_override: None,
clock_realtime: false,
shared: false,
uffd_base_file: None,
};
let parsed_request = parse_put_snapshot(&Body::new(body), Some("load")).unwrap();
Expand Down
16 changes: 2 additions & 14 deletions src/firecracker/swagger/firecracker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1621,19 +1621,14 @@ definitions:
enum:
- Full
- Diff
- Msync
- MsyncAndState
description:
Type of snapshot to create. It is optional and by default, a full
snapshot is created. `Msync` flushes a MAP_SHARED file-backed guest
memory to its backing memfile via msync(MS_SYNC) without writing the
machine state; `MsyncAndState` also writes the state file.
snapshot is created.
vmstate_only:
type: boolean
description:
Write only the microVM state file and skip the guest-memory leg
entirely (mem_file_path is ignored). Incompatible with the
Msync/MsyncAndState snapshot types. Optional and defaults to false.
entirely (mem_file_path is ignored). Optional and defaults to false.

NetworkOverride:
type: object
Expand Down Expand Up @@ -1720,13 +1715,6 @@ definitions:
elapsed since the snapshot was taken. When false (default), kvmclock resumes
from where it was at snapshot time. This option may be extended to other clock
sources and CPU architectures in the future."
shared:
type: boolean
description:
When set to true and the memory is restored from a file, map the guest
memory MAP_SHARED so guest writes flush back to the backing memfile (the
page-readable source for post-copy live migration). No effect for the UFFD
backend. Optional; defaults to false (MAP_PRIVATE).
uffd_base_file:
type: string
description:
Expand Down
47 changes: 9 additions & 38 deletions src/vmm/src/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ use crate::utils::u64_to_usize;
use crate::vmm_config::boot_source::BootSourceConfig;
use crate::vmm_config::instance_info::InstanceInfo;
use crate::vmm_config::machine_config::{HugePageConfig, MachineConfigError, MachineConfigUpdate};
use crate::vmm_config::snapshot::{
CreateSnapshotParams, LoadSnapshotParams, MemBackendType, SnapshotType,
};
use crate::vmm_config::snapshot::{CreateSnapshotParams, LoadSnapshotParams, MemBackendType};
use crate::vstate::kvm::KvmState;
use crate::vstate::memory::{
self, GuestMemoryState, GuestRegionMmap, GuestRegionType, MemoryError,
Expand Down Expand Up @@ -170,31 +168,11 @@ pub fn create_snapshot(
vm_info: &VmInfo,
params: &CreateSnapshotParams,
) -> Result<(), CreateSnapshotError> {
// `vmstate_only` skips the memory leg; the msync types ARE memory
// flushes, so the combination would write nothing at all — reject it.
if params.vmstate_only
&& matches!(
params.snapshot_type,
SnapshotType::Msync | SnapshotType::MsyncAndState
)
{
return Err(CreateSnapshotError::MicrovmState(
MicrovmStateError::NotAllowed(
"vmstate_only cannot combine with the msync snapshot types".into(),
),
));
}

// `Msync` is a memory-only off-pause flush: the machine state file is not
// written (the durable state rides a separate `MsyncAndState`/`Full` capture).
// Every other type writes the state file as usual.
if params.snapshot_type != SnapshotType::Msync {
let microvm_state = vmm
.save_state(vm_info)
.map_err(CreateSnapshotError::MicrovmState)?;
let microvm_state = vmm
.save_state(vm_info)
.map_err(CreateSnapshotError::MicrovmState)?;

snapshot_state_to_file(&microvm_state, &params.snapshot_path)?;
}
snapshot_state_to_file(&microvm_state, &params.snapshot_path)?;

// engram v3 (ADR 0045 C2): vmstate-only capture for post-copy live
// migration — skip the memory leg (and its dirty-queue correction, which
Expand Down Expand Up @@ -482,7 +460,7 @@ pub fn restore_from_snapshot(
.into());
}
(
guest_memory_from_file(mem_backend_path, mem_state, track_dirty_pages, params.shared)
guest_memory_from_file(mem_backend_path, mem_state, track_dirty_pages)
.map_err(RestoreFromSnapshotGuestMemoryError::File)?,
None,
)
Expand Down Expand Up @@ -546,16 +524,9 @@ fn guest_memory_from_file(
mem_file_path: &Path,
mem_state: &GuestMemoryState,
track_dirty_pages: bool,
shared: bool,
) -> Result<Vec<GuestRegionMmap>, GuestMemoryFromFileError> {
// A `MAP_SHARED` mapping that flushes guest writes back needs the fd opened
// for writing; the default `MAP_PRIVATE` restore only reads.
let mem_file = OpenOptions::new()
.read(true)
.write(shared)
.open(mem_file_path)?;
let guest_mem =
memory::snapshot_file(mem_file, mem_state.regions(), track_dirty_pages, shared)?;
let mem_file = File::open(mem_file_path)?;
let guest_mem = memory::snapshot_file(mem_file, mem_state.regions(), track_dirty_pages)?;
Ok(guest_mem)
}

Expand Down Expand Up @@ -641,7 +612,7 @@ fn create_guest_memory(
return Err(GuestMemoryFromUffdError::BaseFileHugetlbfs);
}
let file = std::fs::File::open(path).map_err(GuestMemoryFromUffdError::OpenBaseFile)?;
memory::snapshot_file(file, mem_state.regions(), track_dirty_pages, /* shared */ false)
memory::snapshot_file(file, mem_state.regions(), track_dirty_pages)
.map_err(GuestMemoryFromUffdError::BaseFileMap)?
}
None => memory::anonymous(mem_state.regions(), track_dirty_pages, huge_pages)?,
Expand Down
10 changes: 0 additions & 10 deletions src/vmm/src/rpc_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,15 +952,6 @@ impl RuntimeApiController {
elapsed_time_us
);
}
// ADR 0045 off-pause flush. No dedicated latency metric (reuses the
// monotonic clock for the log line) to keep the fork surface minimal.
SnapshotType::Msync | SnapshotType::MsyncAndState => {
let elapsed_time_us = get_time_us(ClockType::Monotonic) - create_start_us;
info!(
"'create msync snapshot' VMM action took {} us.",
elapsed_time_us
);
}
}
Ok(VmmData::Empty)
}
Expand Down Expand Up @@ -1341,7 +1332,6 @@ mod tests {
network_overrides: vec![],
vsock_override: None,
clock_realtime: false,
shared: false,
uffd_base_file: None,
},
)));
Expand Down
19 changes: 1 addition & 18 deletions src/vmm/src/vmm_config/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ pub enum SnapshotType {
/// Full snapshot.
#[default]
Full,
/// Memory-only flush of a `MAP_SHARED` file-backed guest memory to its backing
/// memfile via `msync(MS_SYNC)`. No machine state is written. The off-pause
/// continuous-flush primitive for ADR 0045 live teleport.
Msync,
/// Like [`SnapshotType::Msync`], but the machine state file is also written —
/// an `msync` memory flush paired with a normal `state` file.
MsyncAndState,
}

/// Specifies the method through which guest memory will get populated when
Expand Down Expand Up @@ -56,8 +49,7 @@ pub struct CreateSnapshotParams {
/// entirely (`mem_file_path` is ignored). The post-copy live-migration
/// blackout primitive for ADR 0045: the dirty memory never materializes
/// as a file — the destination demand-faults it from the paused source's
/// address space. Incompatible with the `Msync`/`MsyncAndState` types
/// (those ARE memory flushes).
/// address space.
#[serde(default)]
pub vmstate_only: bool,
}
Expand Down Expand Up @@ -100,11 +92,6 @@ pub struct LoadSnapshotParams {
/// advancing kvmclock by the wall-clock time elapsed since the snapshot was taken. When false
/// (default), kvmclock resumes from where it was at snapshot time.
pub clock_realtime: bool,
/// When set and the memory is restored from a file (`MemBackendType::File`),
/// map the guest memory `MAP_SHARED` so guest writes flush back to the backing
/// memfile — the page-readable source for ADR 0045 post-copy. No effect for
/// the UFFD backend. Defaults to false (today's `MAP_PRIVATE` behavior).
pub shared: bool,
/// ADR 0045 unified memory substrate (v2b). When set with the Uffd memory
/// backend, guest memory is created as `MAP_PRIVATE` of this file (a
/// tmpfs/shmem per-template base) instead of anonymous, and the UFFD
Expand Down Expand Up @@ -150,10 +137,6 @@ pub struct LoadSnapshotConfig {
/// [x86_64 only] When set to true, passes `KVM_CLOCK_REALTIME` to `KVM_SET_CLOCK` on restore.
#[serde(default)]
pub clock_realtime: bool,
/// Whether to map file-backed guest memory `MAP_SHARED` (ADR 0045 post-copy
/// source). Top-level (not inside `mem_backend`). Defaults to false.
#[serde(default)]
pub shared: bool,
/// ADR 0045 substrate v2b: back Uffd-restored guest memory `MAP_PRIVATE`
/// by this shmem base file and register UFFD `MISSING | MINOR`. Top-level
/// (not inside `mem_backend`, which is `deny_unknown_fields`).
Expand Down
58 changes: 12 additions & 46 deletions src/vmm/src/vstate/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ pub enum MemoryError {
SeekError(std::io::Error),
/// Volatile memory error: {0}
VolatileMemoryError(vm_memory::VolatileMemoryError),
/// Cannot msync guest memory to its backing file: {0}
Msync(std::io::Error),
}

impl From<vm_memory::VolatileMemoryError> for MemoryError {
Expand Down Expand Up @@ -576,15 +574,11 @@ pub fn anonymous(
}

/// Creates a GuestMemoryMmap given a `file` containing the data
/// and a `state` containing mapping information. When `shared` is set, the
/// regions are mapped `MAP_SHARED` so guest writes flush back to the backing
/// file (the page-readable post-copy source, ADR 0045); otherwise `MAP_PRIVATE`
/// (the default restore behavior).
/// and a `state` containing mapping information.
pub fn snapshot_file(
file: File,
regions: impl Iterator<Item = (GuestAddress, usize)>,
track_dirty_pages: bool,
shared: bool,
) -> Result<Vec<GuestRegionMmap>, MemoryError> {
let regions: Vec<_> = regions.collect();
let memory_size = regions
Expand All @@ -599,12 +593,12 @@ pub fn snapshot_file(
return Err(MemoryError::OffsetTooLarge);
}

let flags = if shared {
libc::MAP_SHARED
} else {
libc::MAP_PRIVATE
};
create(regions.into_iter(), flags, Some(file), track_dirty_pages)
create(
regions.into_iter(),
libc::MAP_PRIVATE,
Some(file),
track_dirty_pages,
)
}

/// Defines the interface for snapshotting memory.
Expand All @@ -628,11 +622,6 @@ where
dirty_bitmap: &DirtyBitmap,
) -> Result<(), MemoryError>;

/// Flushes the regions' dirty pages to their backing file via `msync(MS_SYNC)`.
/// Only meaningful when the memory is mapped `MAP_SHARED` on a file (ADR 0045
/// off-pause flush); a harmless flush for anonymous mappings.
fn msync(&self) -> Result<(), MemoryError>;

/// Resets all the memory region bitmaps
fn reset_dirty(&self);

Expand Down Expand Up @@ -724,28 +713,6 @@ impl GuestMemoryExtension for GuestMemoryMmap {
.map_err(MemoryError::WriteMemory)
}

/// Flushes the regions' dirty pages to their backing file via `msync(MS_SYNC)`.
fn msync(&self) -> Result<(), MemoryError> {
self.iter().try_for_each(|region| {
// `region` derefs to its underlying MmapRegion. For a MAP_SHARED
// file-backed region, MS_SYNC blocks until the dirty pages are
// written back to the backing file; for anonymous memory it's a
// harmless flush.
// SAFETY: `as_ptr()`/`size()` describe this region's valid host mmap.
let ret = unsafe {
libc::msync(
region.as_ptr().cast::<libc::c_void>(),
region.size(),
libc::MS_SYNC,
)
};
if ret != 0 {
return Err(MemoryError::Msync(std::io::Error::last_os_error()));
}
Ok(())
})
}

/// Dumps all pages of GuestMemoryMmap present in `dirty_bitmap` to a writer.
fn dump_dirty<T: WriteVolatile + std::io::Seek>(
&self,
Expand Down Expand Up @@ -954,7 +921,7 @@ mod tests {

let regions = vec![(GuestAddress(0), page_size)];
let guest_regions =
snapshot_file(file, regions.into_iter(), dirty_page_tracking, false).unwrap();
snapshot_file(file, regions.into_iter(), dirty_page_tracking).unwrap();
assert_eq!(guest_regions.len(), 1);
guest_regions.iter().for_each(|region| {
assert_eq!(region.bitmap().is_some(), dirty_page_tracking);
Expand All @@ -975,7 +942,7 @@ mod tests {
(GuestAddress(0x10000), page_size),
(GuestAddress(0x20000), page_size),
];
let guest_regions = snapshot_file(file, regions.into_iter(), false, false).unwrap();
let guest_regions = snapshot_file(file, regions.into_iter(), false).unwrap();
assert_eq!(guest_regions.len(), 3);
}

Expand All @@ -987,7 +954,7 @@ mod tests {
file.write_all(&vec![0x42u8; page_size]).unwrap();

let regions = vec![(GuestAddress(0), 2 * page_size)];
let result = snapshot_file(file, regions.into_iter(), false, false);
let result = snapshot_file(file, regions.into_iter(), false);
assert!(matches!(result.unwrap_err(), MemoryError::OffsetTooLarge));
}

Expand Down Expand Up @@ -1178,7 +1145,7 @@ mod tests {
guest_memory.dump(&mut memory_file).unwrap();

let restored_guest_memory =
into_region_ext(snapshot_file(memory_file, memory_state.regions(), false, false).unwrap());
into_region_ext(snapshot_file(memory_file, memory_state.regions(), false).unwrap());

// Check that the region contents are the same.
let mut restored_region = vec![0u8; page_size * 2];
Expand Down Expand Up @@ -1243,7 +1210,7 @@ mod tests {

// We can restore from this because this is the first dirty dump.
let restored_guest_memory =
into_region_ext(snapshot_file(file, memory_state.regions(), false, false).unwrap());
into_region_ext(snapshot_file(file, memory_state.regions(), false).unwrap());

// Check that the region contents are the same.
let mut restored_region = vec![0u8; region_size];
Expand Down Expand Up @@ -1467,7 +1434,6 @@ mod tests {
memory_file,
std::iter::once((GuestAddress(0), 2 * page_size)),
false,
false,
)
.unwrap(),
);
Expand Down
Loading
Loading