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 PageNodeThe start page address used in the system.
Implementations§
Source§impl<const CCOUNT: usize> BuddyInner<CCOUNT>
impl<const CCOUNT: usize> BuddyInner<CCOUNT>
Source§impl<const CCOUNT: usize> BuddyInner<CCOUNT>
impl<const CCOUNT: usize> BuddyInner<CCOUNT>
Sourcefn alloc(&mut self, layout: Layout) -> *mut u8
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.
Sourcefn dealloc(&mut self, ptr: *mut u8, layout: Layout)
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>
impl<const CCOUNT: usize> Default for BuddyInner<CCOUNT>
impl<const CCOUNT: usize> Send for BuddyInner<CCOUNT>
For it can be used globally.