Skip to content

Commit 2b714e7

Browse files
committed
refactor: drop offset field from GuestMemoryRegionState
In praxis, the way we wrote our snapshot files has always been just writing all regions in-order. This mean that the offset of a region is simply the sum of the sizes of the preceding regions. The new `GuestMemoryMmap::create` code already computes the offsets for mapping the memory file this way, so drop the explicit calculation at snapshot creation time (as the calculated value isnt used by the restoration anymore). Bumps the snapshot version number. Signed-off-by: Patrick Roy <[email protected]>
1 parent 7090420 commit 2b714e7

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

src/vmm/src/persist.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub enum CreateSnapshotError {
161161
}
162162

163163
/// Snapshot version
164-
pub const SNAPSHOT_VERSION: Version = Version::new(5, 0, 0);
164+
pub const SNAPSHOT_VERSION: Version = Version::new(6, 0, 0);
165165

166166
/// Creates a Microvm snapshot.
167167
pub fn create_snapshot(
@@ -604,13 +604,15 @@ fn create_guest_memory(
604604
track_dirty_pages,
605605
)?;
606606
let mut backend_mappings = Vec::with_capacity(guest_memory.num_regions());
607-
for (mem_region, state_region) in guest_memory.iter().zip(mem_state.regions.iter()) {
607+
let mut offset = 0;
608+
for mem_region in guest_memory.iter() {
608609
backend_mappings.push(GuestRegionUffdMapping {
609610
base_host_virt_addr: mem_region.as_ptr() as u64,
610611
size: mem_region.size(),
611-
offset: state_region.offset,
612+
offset,
612613
page_size_kib: huge_pages.page_size_kib(),
613614
});
615+
offset += mem_region.size() as u64;
614616
}
615617

616618
Ok((guest_memory, backend_mappings))
@@ -790,7 +792,6 @@ mod tests {
790792
regions: vec![GuestMemoryRegionState {
791793
base_address: 0,
792794
size: 0x20000,
793-
offset: 0x10000,
794795
}],
795796
};
796797

@@ -799,7 +800,7 @@ mod tests {
799800

800801
assert_eq!(uffd_regions.len(), 1);
801802
assert_eq!(uffd_regions[0].size, 0x20000);
802-
assert_eq!(uffd_regions[0].offset, 0x10000);
803+
assert_eq!(uffd_regions[0].offset, 0);
803804
assert_eq!(
804805
uffd_regions[0].page_size_kib,
805806
HugePageConfig::None.page_size_kib()

src/vmm/src/vstate/memory.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ pub struct GuestMemoryRegionState {
128128
pub base_address: u64,
129129
/// Region size.
130130
pub size: usize,
131-
/// Offset in file/buffer where the region is saved.
132-
pub offset: u64,
133131
}
134132

135133
/// Describes guest memory regions and their snapshot file mappings.
@@ -188,15 +186,11 @@ impl GuestMemoryExtension for GuestMemoryMmap {
188186
/// Describes GuestMemoryMmap through a GuestMemoryState struct.
189187
fn describe(&self) -> GuestMemoryState {
190188
let mut guest_memory_state = GuestMemoryState::default();
191-
let mut offset = 0;
192189
self.iter().for_each(|region| {
193190
guest_memory_state.regions.push(GuestMemoryRegionState {
194191
base_address: region.start_addr().0,
195192
size: u64_to_usize(region.len()),
196-
offset,
197193
});
198-
199-
offset += region.len();
200194
});
201195
guest_memory_state
202196
}
@@ -571,12 +565,10 @@ mod tests {
571565
GuestMemoryRegionState {
572566
base_address: 0,
573567
size: page_size,
574-
offset: 0,
575568
},
576569
GuestMemoryRegionState {
577570
base_address: page_size as u64 * 2,
578571
size: page_size,
579-
offset: page_size as u64,
580572
},
581573
],
582574
};
@@ -601,12 +593,10 @@ mod tests {
601593
GuestMemoryRegionState {
602594
base_address: 0,
603595
size: page_size * 3,
604-
offset: 0,
605596
},
606597
GuestMemoryRegionState {
607598
base_address: page_size as u64 * 4,
608599
size: page_size * 3,
609-
offset: page_size as u64 * 3,
610600
},
611601
],
612602
};

0 commit comments

Comments
 (0)