Skip to content

Commit 6ff0ff5

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). Do not bump the snapshot version number, because we already did so since the last release. Signed-off-by: Patrick Roy <[email protected]>
1 parent 3ab85d2 commit 6ff0ff5

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

src/vmm/src/persist.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -129,8 +129,6 @@ pub struct GuestMemoryRegionState {
129129
pub base_address: u64,
130130
/// Region size.
131131
pub size: usize,
132-
/// Offset in file/buffer where the region is saved.
133-
pub offset: u64,
134132
}
135133

136134
/// Describes guest memory regions and their snapshot file mappings.
@@ -184,15 +182,11 @@ impl GuestMemoryExtension for GuestMemoryMmap {
184182
/// Describes GuestMemoryMmap through a GuestMemoryState struct.
185183
fn describe(&self) -> GuestMemoryState {
186184
let mut guest_memory_state = GuestMemoryState::default();
187-
let mut offset = 0;
188185
self.iter().for_each(|region| {
189186
guest_memory_state.regions.push(GuestMemoryRegionState {
190187
base_address: region.start_addr().0,
191188
size: u64_to_usize(region.len()),
192-
offset,
193189
});
194-
195-
offset += region.len();
196190
});
197191
guest_memory_state
198192
}
@@ -567,12 +561,10 @@ mod tests {
567561
GuestMemoryRegionState {
568562
base_address: 0,
569563
size: page_size,
570-
offset: 0,
571564
},
572565
GuestMemoryRegionState {
573566
base_address: page_size as u64 * 2,
574567
size: page_size,
575-
offset: page_size as u64,
576568
},
577569
],
578570
};
@@ -597,12 +589,10 @@ mod tests {
597589
GuestMemoryRegionState {
598590
base_address: 0,
599591
size: page_size * 3,
600-
offset: 0,
601592
},
602593
GuestMemoryRegionState {
603594
base_address: page_size as u64 * 4,
604595
size: page_size * 3,
605-
offset: page_size as u64 * 3,
606596
},
607597
],
608598
};

0 commit comments

Comments
 (0)