Skip to main content

MemoryLayout

Struct MemoryLayout 

Source
pub struct MemoryLayout { /* private fields */ }
Expand description

Describes the memory layout of a guest.

Implementations§

Source§

impl MemoryLayout

Source

pub fn new( ram_size: u64, mmio_gaps: &[MemoryRange], pci_ecam_gaps: &[MemoryRange], pci_mmio_gaps: &[MemoryRange], vtl2_range: Option<MemoryRange>, ) -> Result<Self, Error>

Makes a new memory layout for a guest with ram_size bytes of memory and MMIO gaps at the locations specified by gaps.

ram_size must be a multiple of the page size. Each mmio and device reserved gap must be non-empty, and the gaps must be in order and non-overlapping.

vtl2_range describes a range of memory reserved for VTL2. It is not reported in ram.

All RAM is assigned to NUMA node 0.

Source

pub fn new_with_numa( numa_mem_sizes: &[u64], mmio_gaps: &[MemoryRange], pci_ecam_gaps: &[MemoryRange], pci_mmio_gaps: &[MemoryRange], vtl2_range: Option<MemoryRange>, ) -> Result<Self, Error>

Like Self::new(), but distributes RAM across NUMA nodes according to the per-node sizes in numa_mem_sizes.

numa_mem_sizes[i] is the number of RAM bytes for vnode i. Each size must be page-aligned and non-zero. The sum of all sizes is the total guest RAM.

RAM is placed sequentially around MMIO gaps, filling each node’s budget in order. When a node’s budget is exhausted mid-chunk, the chunk is split and the next node continues from that address.

Source

pub fn new_from_ranges( memory: &[MemoryRangeWithNode], gaps: &[MemoryRange], ) -> Result<Self, Error>

Makes a new memory layout for a guest with the given mmio gaps and memory ranges.

memory and gaps ranges must be in sorted order and non-overlapping, and describe page aligned ranges.

Source

pub fn new_from_resolved_ranges( ram: Vec<MemoryRangeWithNode>, mmio_gaps: Vec<MemoryRange>, pci_ecam_gaps: Vec<MemoryRange>, pci_mmio_gaps: Vec<MemoryRange>, vtl2_range: Option<MemoryRange>, ) -> Result<Self, Error>

Makes a new memory layout from already-resolved RAM and fixed ranges.

Each individual range must be non-empty, but the lists themselves may be empty (e.g. no PCIe root complexes means empty PCI ECAM/MMIO vectors). Ranges within each list must be sorted and non-overlapping. MMIO gaps may contain empty placeholder ranges to preserve positional indexing (e.g. mmio()[0] = low, mmio()[1] = high); empty entries are ignored during validation. The combined layout is also validated for overlaps, including the optional VTL2 range.

Source

pub fn mmio(&self) -> &[MemoryRange]

The MMIO gap ranges.

Source

pub fn ram(&self) -> &[MemoryRangeWithNode]

The populated RAM ranges. This does not include the vtl2_range.

Source

pub fn vtl2_range(&self) -> Option<MemoryRange>

A special memory range for VTL2, if any. This memory range is treated like RAM, but is only used to hold VTL2 and is located above ram and mmio.

Source

pub fn ram_size(&self) -> u64

The total RAM size in bytes. This is not contiguous.

Source

pub fn end_of_ram(&self) -> u64

One past the last byte of RAM.

Source

pub fn ram_below_4gb(&self) -> u64

The bytes of RAM below 4GB.

Source

pub fn ram_above_4gb(&self) -> u64

The bytes of RAM at or above 4GB.

Source

pub fn ram_above_high_mmio(&self) -> Option<u64>

The bytes of RAM above the high MMIO gap.

Returns None if there aren’t exactly 2 MMIO gaps.

Source

pub fn max_ram_below_4gb(&self) -> Option<u64>

The ending RAM address below 4GB.

Returns None if there is no RAM mapped below 4GB.

Source

pub fn end_of_layout(&self) -> u64

One past the last byte of RAM, MMIO, PCI ECAM, or PCI MMIO.

Source

pub fn probe_address(&self, address: u64) -> Option<AddressType>

Probe a given address to see if it is in the memory layout described by self. Returns the AddressType of the address if it is in the layout.

This does not check the vtl2_range.

Trait Implementations§

Source§

impl Clone for MemoryLayout

Source§

fn clone(&self) -> MemoryLayout

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MemoryLayout

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Inspect for MemoryLayout

Source§

fn inspect(&self, req: Request<'_>)

Inspects the object.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more