Skip to content

Commit 43f9cbf

Browse files
committed
refactor: Remove GuestMemoryExtension::with_size
It was only used in test code, but test code has its own utilities for creating guest memory, so just use those, and remove the production fn. Also remove documentation references to guard pages because they are a thing of the past. Signed-off-by: Patrick Roy <[email protected]>
1 parent 11ac487 commit 43f9cbf

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

src/vmm/src/builder.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,7 @@ pub mod tests {
969969
use crate::devices::virtio::{TYPE_BALLOON, TYPE_BLOCK, TYPE_RNG};
970970
use crate::mmds::data_store::{Mmds, MmdsVersion};
971971
use crate::mmds::ns::MmdsNetworkStack;
972+
use crate::utilities::test_utils::{arch_mem, single_region_mem, single_region_mem_at};
972973
use crate::vmm_config::balloon::{BalloonBuilder, BalloonDeviceConfig, BALLOON_DEV_ID};
973974
use crate::vmm_config::boot_source::DEFAULT_KERNEL_CMDLINE;
974975
use crate::vmm_config::drive::{BlockBuilder, BlockDeviceConfig};
@@ -1040,7 +1041,7 @@ pub mod tests {
10401041
}
10411042

10421043
pub(crate) fn default_vmm() -> Vmm {
1043-
let guest_memory = GuestMemoryMmap::with_size(128, false).unwrap();
1044+
let guest_memory = arch_mem(128 << 20);
10441045

10451046
let vcpus_exit_evt = EventFd::new(libc::EFD_NONBLOCK)
10461047
.map_err(VmmError::EventFd)
@@ -1268,8 +1269,6 @@ pub mod tests {
12681269
);
12691270
}
12701271

1271-
use crate::utilities::test_utils::{single_region_mem, single_region_mem_at};
1272-
12731272
#[test]
12741273
fn test_load_initrd_unaligned() {
12751274
let image = vec![1, 2, 3, 4];
@@ -1289,7 +1288,7 @@ pub mod tests {
12891288
#[test]
12901289
fn test_create_vcpus() {
12911290
let vcpu_count = 2;
1292-
let guest_memory = GuestMemoryMmap::with_size(128, false).unwrap();
1291+
let guest_memory = arch_mem(128 << 20);
12931292

12941293
#[allow(unused_mut)]
12951294
let mut vm = Vm::new(vec![]).unwrap();

src/vmm/src/vstate/memory.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,13 @@ where
5959
/// Creates a GuestMemoryMmap with `size` in MiB backed by a memfd.
6060
fn memfd_backed(mem_size_mib: usize, track_dirty_pages: bool) -> Result<Self, MemoryError>;
6161

62-
/// Creates a GuestMemoryMmap with `size` in MiB and guard pages.
63-
fn with_size(size: usize, track_dirty_pages: bool) -> Result<Self, MemoryError>;
64-
65-
/// Creates a GuestMemoryMmap from raw regions with guard pages.
62+
/// Creates a GuestMemoryMmap from raw regions.
6663
fn from_raw_regions(
6764
regions: &[(GuestAddress, usize)],
6865
track_dirty_pages: bool,
6966
) -> Result<Self, MemoryError>;
7067

71-
/// Creates a GuestMemoryMmap from raw regions with guard pages.
68+
/// Creates a GuestMemoryMmap from raw regions.
7269
fn from_raw_regions_file(
7370
regions: Vec<(FileOffset, GuestAddress, usize)>,
7471
track_dirty_pages: bool,
@@ -139,14 +136,6 @@ impl GuestMemoryExtension for GuestMemoryMmap {
139136
Self::from_raw_regions_file(regions, track_dirty_pages, true)
140137
}
141138

142-
/// Creates a GuestMemoryMmap with `size` in MiB and guard pages backed by anonymous memory.
143-
fn with_size(size: usize, track_dirty_pages: bool) -> Result<Self, MemoryError> {
144-
let mem_size = size << 20;
145-
let regions = crate::arch::arch_memory_regions(mem_size);
146-
147-
Self::from_raw_regions(&regions, track_dirty_pages)
148-
}
149-
150139
/// Creates a GuestMemoryMmap from raw regions backed by anonymous memory.
151140
fn from_raw_regions(
152141
regions: &[(GuestAddress, usize)],
@@ -174,7 +163,7 @@ impl GuestMemoryExtension for GuestMemoryMmap {
174163
GuestMemoryMmap::from_regions(regions).map_err(MemoryError::VmMemoryError)
175164
}
176165

177-
/// Creates a GuestMemoryMmap from raw regions with guard pages backed by file.
166+
/// Creates a GuestMemoryMmap from raw regions backed by file.
178167
fn from_raw_regions_file(
179168
regions: Vec<(FileOffset, GuestAddress, usize)>,
180169
track_dirty_pages: bool,

0 commit comments

Comments
 (0)