Struct kalloc::buddy::BuddySystem[][src]

#[repr(C)]
pub struct BuddySystem<P> { /* fields omitted */ }
Expand description

Buddy System Allocator Structure.

Memory Layout

         bitmap_begin          page_begin          page_end
              |                    |                   |
              v                    v                   v
+-------------+--------+-----------+-------------------+
| this struct | bitmap | (padding) | 2^max_order pages |
+-------------+--------+-----------+-------------------+
                                   ^
                                   |      
                   page_begin is a multiple of P

Implementations

impl<P: Unsigned + PowerOfTwo> BuddySystem<P>[src]

pub unsafe fn build(begin: usize, end: usize) -> Result<&'static mut Self, ()>[src]

Construct a buddy system allocator at memory [begin, end) with specific page size.

Notice that it guarantees safety only if the access to [begin, end) is safe and self is a static variable.

pub unsafe fn alloc1(&mut self, order: usize) -> *mut u8[src]

Alloccate memory by order.

pub unsafe fn free(&mut self, ptr: *mut u8, order: usize) -> usize[src]

Free the block of memory starting from ptr with specific order. Return the order of the freed page after merging possible buddy pages.

pub unsafe fn alloc(&mut self, layout: Layout) -> *mut u8[src]

Allocate memory specified by layout.

pub unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout)[src]

Free the block of memory starting from ptr with specific layout.

pub unsafe fn check(&self)[src]

Check the properties maintained by buddy system.

  • 1-nodes that don’t have any 1-node child are allocated chunks.
  • Root 0-nodes and 0-nodes whose father is 1-node and buddy is 1-node are free chunks.
  • Children of any 0-node must be also 0-nodes.

Auto Trait Implementations

impl<P> RefUnwindSafe for BuddySystem<P>

impl<P> !Send for BuddySystem<P>

impl<P> !Sync for BuddySystem<P>

impl<P> Unpin for BuddySystem<P>

impl<P> UnwindSafe for BuddySystem<P>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Same<T> for T[src]

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.