pub struct GlobalAllocator { /* private fields */ }Expand description
The global allocator used by ArceOS when buddy-slab is enabled.
Implementations§
Source§impl GlobalAllocator
impl GlobalAllocator
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates an empty GlobalAllocator.
Sourcepub fn init(&self, start_vaddr: usize, size: usize) -> AllocResult
pub fn init(&self, start_vaddr: usize, size: usize) -> AllocResult
Initializes the allocator with the given region.
Sourcepub fn add_memory(&self, start_vaddr: usize, size: usize) -> AllocResult
pub fn add_memory(&self, start_vaddr: usize, size: usize) -> AllocResult
Add the given region to the allocator.
Sourcepub fn alloc(&self, layout: Layout) -> AllocResult<NonNull<u8>>
pub fn alloc(&self, layout: Layout) -> AllocResult<NonNull<u8>>
Allocate arbitrary number of bytes. Returns the left bound of the allocated region.
Sourcepub fn dealloc(&self, pos: NonNull<u8>, layout: Layout)
pub fn dealloc(&self, pos: NonNull<u8>, layout: Layout)
Gives back the allocated region to the byte allocator.
Sourcepub fn alloc_pages(
&self,
num_pages: usize,
alignment: usize,
kind: UsageKind,
) -> AllocResult<usize>
pub fn alloc_pages( &self, num_pages: usize, alignment: usize, kind: UsageKind, ) -> AllocResult<usize>
Allocates contiguous pages.
Sourcepub fn alloc_dma32_pages(
&self,
num_pages: usize,
alignment: usize,
kind: UsageKind,
) -> AllocResult<usize>
pub fn alloc_dma32_pages( &self, num_pages: usize, alignment: usize, kind: UsageKind, ) -> AllocResult<usize>
Allocates contiguous low-memory pages (physical address < 4 GiB).
Sourcepub fn alloc_pages_at(
&self,
_start: usize,
_num_pages: usize,
_alignment: usize,
_kind: UsageKind,
) -> AllocResult<usize>
pub fn alloc_pages_at( &self, _start: usize, _num_pages: usize, _alignment: usize, _kind: UsageKind, ) -> AllocResult<usize>
Allocates contiguous pages starting from the given address.
Sourcepub fn dealloc_pages(&self, pos: usize, num_pages: usize, kind: UsageKind)
pub fn dealloc_pages(&self, pos: usize, num_pages: usize, kind: UsageKind)
Gives back the allocated pages starts from pos to the page allocator.
Sourcepub fn used_bytes(&self) -> usize
pub fn used_bytes(&self) -> usize
Returns the number of allocated bytes in the allocator backend.
Sourcepub fn available_bytes(&self) -> usize
pub fn available_bytes(&self) -> usize
Returns the number of available bytes in the allocator backend.
Sourcepub fn used_pages(&self) -> usize
pub fn used_pages(&self) -> usize
Returns the number of allocated pages in the allocator backend.
Sourcepub fn available_pages(&self) -> usize
pub fn available_pages(&self) -> usize
Returns the number of available pages in the allocator backend.
Trait Implementations§
Source§impl AllocatorOps for GlobalAllocator
impl AllocatorOps for GlobalAllocator
Source§fn init(&self, start_vaddr: usize, size: usize) -> AllocResult
fn init(&self, start_vaddr: usize, size: usize) -> AllocResult
Source§fn add_memory(&self, start_vaddr: usize, size: usize) -> AllocResult
fn add_memory(&self, start_vaddr: usize, size: usize) -> AllocResult
Source§fn alloc_pages(
&self,
num_pages: usize,
alignment: usize,
kind: UsageKind,
) -> AllocResult<usize>
fn alloc_pages( &self, num_pages: usize, alignment: usize, kind: UsageKind, ) -> AllocResult<usize>
Source§fn alloc_dma32_pages(
&self,
num_pages: usize,
alignment: usize,
kind: UsageKind,
) -> AllocResult<usize>
fn alloc_dma32_pages( &self, num_pages: usize, alignment: usize, kind: UsageKind, ) -> AllocResult<usize>
Source§fn alloc_pages_at(
&self,
start: usize,
num_pages: usize,
alignment: usize,
kind: UsageKind,
) -> AllocResult<usize>
fn alloc_pages_at( &self, start: usize, num_pages: usize, alignment: usize, kind: UsageKind, ) -> AllocResult<usize>
Source§fn dealloc_pages(&self, pos: usize, num_pages: usize, kind: UsageKind)
fn dealloc_pages(&self, pos: usize, num_pages: usize, kind: UsageKind)
Source§fn used_bytes(&self) -> usize
fn used_bytes(&self) -> usize
Source§fn available_bytes(&self) -> usize
fn available_bytes(&self) -> usize
Source§fn used_pages(&self) -> usize
fn used_pages(&self) -> usize
Source§fn available_pages(&self) -> usize
fn available_pages(&self) -> usize
Source§impl Default for GlobalAllocator
impl Default for GlobalAllocator
Source§impl GlobalAlloc for GlobalAllocator
impl GlobalAlloc for GlobalAllocator
Source§unsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
layout. Read more