dbs-address-space

Crates.iodbs-address-space
lib.rsdbs-address-space
version0.3.0
sourcesrc
created_at2022-05-12 06:31:27.335199
updated_at2023-03-01 06:00:21.687415
descriptionaddress space manager for virtual machines.
homepagehttps://github.com/openanolis/dragonball-sandbox
repositoryhttps://github.com/openanolis/dragonball-sandbox
max_upload_size
id585048
size155,413
Helin Guo (HerlinCoder)

documentation

README

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.

Commit count: 375

cargo fmt