Skip to content

Commit a9fe910

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 0296646 commit a9fe910

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
@@ -121,8 +121,6 @@ pub struct GuestMemoryRegionState {
121121
pub base_address: u64,
122122
/// Region size.
123123
pub size: usize,
124-
/// Offset in file/buffer where the region is saved.
125-
pub offset: u64,
126124
}
127125

128126
/// Describes guest memory regions and their snapshot file mappings.
@@ -181,15 +179,11 @@ impl GuestMemoryExtension for GuestMemoryMmap {
181179
/// Describes GuestMemoryMmap through a GuestMemoryState struct.
182180
fn describe(&self) -> GuestMemoryState {
183181
let mut guest_memory_state = GuestMemoryState::default();
184-
let mut offset = 0;
185182
self.iter().for_each(|region| {
186183
guest_memory_state.regions.push(GuestMemoryRegionState {
187184
base_address: region.start_addr().0,
188185
size: u64_to_usize(region.len()),
189-
offset,
190186
});
191-
192-
offset += region.len();
193187
});
194188
guest_memory_state
195189
}
@@ -564,12 +558,10 @@ mod tests {
564558
GuestMemoryRegionState {
565559
base_address: 0,
566560
size: page_size,
567-
offset: 0,
568561
},
569562
GuestMemoryRegionState {
570563
base_address: page_size as u64 * 2,
571564
size: page_size,
572-
offset: page_size as u64,
573565
},
574566
],
575567
};
@@ -594,12 +586,10 @@ mod tests {
594586
GuestMemoryRegionState {
595587
base_address: 0,
596588
size: page_size * 3,
597-
offset: 0,
598589
},
599590
GuestMemoryRegionState {
600591
base_address: page_size as u64 * 4,
601592
size: page_size * 3,
602-
offset: page_size as u64 * 3,
603593
},
604594
],
605595
};

0 commit comments

Comments
 (0)