5 unstable releases

0.3.0 Mar 1, 2023
0.2.2 Nov 10, 2022
0.2.1 Nov 8, 2022
0.2.0 Oct 24, 2022
0.1.0 May 12, 2022

#303 in Emulators

Download history 39/week @ 2023-12-04 1/week @ 2023-12-11 8/week @ 2023-12-18 12/week @ 2024-01-01 11/week @ 2024-01-29 64/week @ 2024-02-19 53/week @ 2024-02-26 30/week @ 2024-03-04 40/week @ 2024-03-11 16/week @ 2024-03-18

141 downloads per month

Apache-2.0

145KB
2.5K SLoC

dbs-address-space

Design

The dbs-address-space crate is an address space manager for virtual machines, which manages memory and MMIO resources resident in the guest physical address space.

Main components are:

  • AddressSpaceRegion: Struct to maintain configuration information about a guest address region.
#[derive(Debug, Clone)]
pub struct AddressSpaceRegion {
    /// Type of address space regions.
    pub ty: AddressSpaceRegionType,
    /// Base address of the region in virtual machine's physical address space.
    pub base: GuestAddress,
    /// Size of the address space region.
    pub size: GuestUsize,
    /// Host NUMA node ids assigned to this region.
    pub host_numa_node_id: Option<u32>,

    /// File/offset tuple to back the memory allocation.
    file_offset: Option<FileOffset>,
    /// Mmap permission flags.
    perm_flags: i32,
    /// Hugepage madvise hint.
    ///
    /// It needs 'advise' or 'always' policy in host shmem config.
    is_hugepage: bool,
    /// Hotplug hint.
    is_hotplug: bool,
    /// Anonymous memory hint.
    ///
    /// It should be true for regions with the MADV_DONTFORK flag enabled.
    is_anon: bool,
}
  • AddressSpaceBase: Base implementation to manage guest physical address space, without support of region hotplug.
#[derive(Clone)]
pub struct AddressSpaceBase {
    regions: Vec<Arc<AddressSpaceRegion>>,
    layout: AddressSpaceLayout,
}
  • AddressSpaceBase: An address space implementation with region hotplug capability.
/// The `AddressSpace` is a wrapper over [AddressSpaceBase] to support hotplug of
/// address space regions.
#[derive(Clone)]
pub struct AddressSpace {
    state: Arc<ArcSwap<AddressSpaceBase>>,
}

Usage

// 1. create several memory regions
let reg = Arc::new(
    AddressSpaceRegion::create_default_memory_region(
        GuestAddress(0x100000),
        0x100000,
        None,
        "shmem",
        "",
        false,
        false,
        false,
    )
    .unwrap()
);
let regions = vec![reg];
// 2. create layout (depending on archs)
let layout = AddressSpaceLayout::new(GUEST_PHYS_END, GUEST_MEM_START, GUEST_MEM_END);
// 3. create address space from regions and layout
let address_space = AddressSpace::from_regions(regions, layout.clone());

License

This project is licensed under Apache License, Version 2.0.

Dependencies

~3.5MB
~66K SLoC