Crates.io | dbs-address-space |
lib.rs | dbs-address-space |
version | 0.3.0 |
source | src |
created_at | 2022-05-12 06:31:27.335199 |
updated_at | 2023-03-01 06:00:21.687415 |
description | address space manager for virtual machines. |
homepage | https://github.com/openanolis/dragonball-sandbox |
repository | https://github.com/openanolis/dragonball-sandbox |
max_upload_size | |
id | 585048 |
size | 155,413 |
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:
#[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,
}
#[derive(Clone)]
pub struct AddressSpaceBase {
regions: Vec<Arc<AddressSpaceRegion>>,
layout: AddressSpaceLayout,
}
/// The `AddressSpace` is a wrapper over [AddressSpaceBase] to support hotplug of
/// address space regions.
#[derive(Clone)]
pub struct AddressSpace {
state: Arc<ArcSwap<AddressSpaceBase>>,
}
// 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());
This project is licensed under Apache License, Version 2.0.