rusty_mos::memory::buddy_allocator

Struct BuddyInner

Source
struct BuddyInner<const CCOUNT: usize> {
    free_list: [PageList; CCOUNT],
    page_start: *mut PageNode,
}
Expand description

The buddy system core data structure.

Fields§

§free_list: [PageList; CCOUNT]

Free page lists. Only the first page will be in the list.

The i-th category holds (2^i) pages each.

§page_start: *mut PageNode

The start page address used in the system.

Implementations§

Source§

impl<const CCOUNT: usize> BuddyInner<CCOUNT>

Source

const fn new() -> Self

Create a brand-new buddy contents.

Source

fn init(&mut self, page_start: *mut PageNode, size: usize)

Initialize the free list. The pages will be inserted into the topest category and the remained into one-level-lower category. As to the category zero.

Only after this function invoked, the system can be used.

Source§

impl<const CCOUNT: usize> BuddyInner<CCOUNT>

Source

fn alloc(&mut self, layout: Layout) -> *mut u8

Buddy Alloc.

This method will search the specified category’s free list first. If found, the page will be returned.

Otherwise, this method will search the higher category, until a free item was found. In this situation, the pages will be splitted and inserted into the lower category’s free list one by one.

If no pages can be found, a null pointer will be returned.

Source

fn dealloc(&mut self, ptr: *mut u8, layout: Layout)

Buddy Dealloc.

The page will be inserted into its category’s free list if no buddy is found.

Otherwise, the buddy will be removed from the free list. They will be merged into a larger item and be inserted into one-level-higher category.

The process above will be performed recursively unless reached the toppest category.

Trait Implementations§

Source§

impl<const CCOUNT: usize> Default for BuddyInner<CCOUNT>

Source§

fn default() -> Self

Default constructions.

Source§

impl<const CCOUNT: usize> Send for BuddyInner<CCOUNT>

For it can be used globally.

Auto Trait Implementations§

§

impl<const CCOUNT: usize> Freeze for BuddyInner<CCOUNT>

§

impl<const CCOUNT: usize> RefUnwindSafe for BuddyInner<CCOUNT>

§

impl<const CCOUNT: usize> !Sync for BuddyInner<CCOUNT>

§

impl<const CCOUNT: usize> Unpin for BuddyInner<CCOUNT>

§

impl<const CCOUNT: usize> UnwindSafe for BuddyInner<CCOUNT>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.