Skip to main content

BuddySet

Struct BuddySet 

Source
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>

Source

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())

Source

pub const fn empty() -> Self

Create an empty buddy set

Source

pub const fn max_order(&self) -> usize

Source

pub fn addr_in_zone(&self, addr: usize) -> bool

Check if an address belongs to this zone

Source

pub fn zone_info(&self) -> ZoneInfo

Get zone information

Source

pub fn init(&mut self, pool: &mut GlobalNodePool, base_addr: usize, size: usize)

Initialize the buddy set with a memory region

Source

pub fn alloc_pages( &mut self, pool: &mut GlobalNodePool, num_pages: usize, alignment: usize, ) -> AllocResult<usize>

Allocate pages using buddy system

Source

pub fn dealloc_pages( &mut self, pool: &mut GlobalNodePool, addr: usize, num_pages: usize, )

Deallocate pages back to buddy system with automatic merging

Source

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

Source

pub fn get_order_block_count(&self, order: usize) -> usize

Get the number of blocks in a specific order

Source

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§

Source§

impl Default for BuddySet

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.