pub struct BuddySet<const PAGE_SIZE: usize = { crate::DEFAULT_PAGE_SIZE }> { /* private fields */ }Expand description
A buddy set implementation - represents a single zone
Uses pooled linked lists with global node pool for efficient memory usage. All zones share the same global node pool.
Implementations§
Source§impl<const PAGE_SIZE: usize> BuddySet<PAGE_SIZE>
impl<const PAGE_SIZE: usize> BuddySet<PAGE_SIZE>
Sourcepub const fn new(base_addr: usize, size: usize, zone_id: usize) -> Self
pub const fn new(base_addr: usize, size: usize, zone_id: usize) -> Self
Create a new buddy set for a zone (uninitialized, must call init())
pub const fn max_order(&self) -> usize
Sourcepub fn addr_in_zone(&self, addr: usize) -> bool
pub fn addr_in_zone(&self, addr: usize) -> bool
Check if an address belongs to this zone
Sourcepub fn init(&mut self, pool: &mut GlobalNodePool, base_addr: usize, size: usize)
pub fn init(&mut self, pool: &mut GlobalNodePool, base_addr: usize, size: usize)
Initialize the buddy set with a memory region
Sourcepub fn alloc_pages(
&mut self,
pool: &mut GlobalNodePool,
num_pages: usize,
alignment: usize,
) -> AllocResult<usize>
pub fn alloc_pages( &mut self, pool: &mut GlobalNodePool, num_pages: usize, alignment: usize, ) -> AllocResult<usize>
Allocate pages using buddy system
Sourcepub fn dealloc_pages(
&mut self,
pool: &mut GlobalNodePool,
addr: usize,
num_pages: usize,
)
pub fn dealloc_pages( &mut self, pool: &mut GlobalNodePool, addr: usize, num_pages: usize, )
Deallocate pages back to buddy system with automatic merging
Sourcepub fn get_free_blocks_by_order<'a>(
&'a self,
pool: &'a GlobalNodePool,
order: u32,
) -> PooledListIter<'a> ⓘ
pub fn get_free_blocks_by_order<'a>( &'a self, pool: &'a GlobalNodePool, order: u32, ) -> PooledListIter<'a> ⓘ
Get free blocks of a specific order as an iterator
Sourcepub fn get_order_block_count(&self, order: usize) -> usize
pub fn get_order_block_count(&self, order: usize) -> usize
Get the number of blocks in a specific order
Sourcepub fn alloc_pages_at(
&mut self,
pool: &mut GlobalNodePool,
base: usize,
num_pages: usize,
alignment: usize,
) -> AllocResult<usize>
pub fn alloc_pages_at( &mut self, pool: &mut GlobalNodePool, base: usize, num_pages: usize, alignment: usize, ) -> AllocResult<usize>
Allocate pages at a specific address
This method allocates memory at a specific address. If the address range is completely free, it will be allocated. If part of a larger free block, the block will be split appropriately.
Trait Implementations§
Auto Trait Implementations§
impl<const PAGE_SIZE: usize> Freeze for BuddySet<PAGE_SIZE>
impl<const PAGE_SIZE: usize> RefUnwindSafe for BuddySet<PAGE_SIZE>
impl<const PAGE_SIZE: usize> Send for BuddySet<PAGE_SIZE>
impl<const PAGE_SIZE: usize> Sync for BuddySet<PAGE_SIZE>
impl<const PAGE_SIZE: usize> Unpin for BuddySet<PAGE_SIZE>
impl<const PAGE_SIZE: usize> UnwindSafe for BuddySet<PAGE_SIZE>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more