#[repr(C)]pub struct BuddyAlg<A: MemPool> { /* private fields */ }
Expand description
Buddy Allocation Algorithm
It contains 61 free-lists of available buddy blocks to keep at most 2^64
bytes including meta-data information. A free-list k
keeps all available
memory blocks of size 2^k
bytes. Assuming that Buddy
has a size of
8 bytes, the shape of lists can be like this:
[8]: [8] -> [8]
[16]: [8|8] -> [8|8]
[32]: [8|24] -> [8|24] -> [8|24]
[64]: [8|56]
...
The first 8 bytes of each free block is meta-data. Once they are selected for occupation, this 8 byte is going to be used, too. So, the smallest block size is 8 bytes.
Implementations
sourceimpl<A: MemPool> BuddyAlg<A>
impl<A: MemPool> BuddyAlg<A>
sourcepub unsafe fn drop_on_failure(&mut self, off: u64, len: usize)
pub unsafe fn drop_on_failure(&mut self, off: u64, len: usize)
Adds a new low-level DropOnFailure
log entry
sourcepub unsafe fn aux_push(&mut self, off: u64, data: u64)
pub unsafe fn aux_push(&mut self, off: u64, data: u64)
Adds a new entry to the auxiliary list of changes
sourcepub fn drain_aux(&mut self)
pub fn drain_aux(&mut self)
Drain the auxiliary list of changes
The functions alloc_impl
and dealloc_impl
fills up the auxiliary
buffer with the required changes to the free lists. Then, they call this
function to materialize the changes. The changes are not valid until
drain_aux()
is called. The recovery procedure performs changes if they
are valid. Otherwise, it discards them.
sourcepub unsafe fn perform(&mut self)
pub unsafe fn perform(&mut self)
Materializes the changes in the auxiliary list and clears the drop log records
sourcepub unsafe fn alloc_impl(&mut self, len: usize, perform: bool) -> u64
pub unsafe fn alloc_impl(&mut self, len: usize, perform: bool) -> u64
Generates required changes to the metadata for allocating a new memory
block with the size len
, and materialize them by calling
drain_aux
according to the perform
argument.
If successful, it returns the offset of the available free block.
Otherwise, u64::MAX
is returned.
sourcepub unsafe fn dealloc_impl(&mut self, off: u64, len: usize, perform: bool)
pub unsafe fn dealloc_impl(&mut self, off: u64, len: usize, perform: bool)
Generates required changes to the metadata for reclaiming the memory
block at offset off
with the size of len
, and materialize them by
calling drain_aux
according to the perform
argument.
sourcepub fn is_allocated(&mut self, off: u64, _len: usize) -> bool
pub fn is_allocated(&mut self, off: u64, _len: usize) -> bool
Determines if the given address range is allocated
sourcepub fn recover(&mut self)
pub fn recover(&mut self)
Starts the recovery procedure. If the crash happened while draining the
auxiliary buffer, it continues draining it and making the remaining
changes. It is rational because the DropOnFailure
log was taken
before draining the auxiliary buffer. When the draining is finished,
the higher-level log reclaims the allocation in the higher level
recovery procedure.
pub fn recovery_info(&self, info_level: u32) -> String
pub fn check(&self, f: &str)
pub fn verify(&mut self) -> bool
Auto Trait Implementations
impl<A> LooseTxInUnsafe for BuddyAlg<A>
impl<A> PSafe for BuddyAlg<A>
impl<A> PSend for BuddyAlg<A> where
A: PSend,
impl<A> RefUnwindSafe for BuddyAlg<A>
impl<A> Send for BuddyAlg<A> where
A: Send,
impl<A> Sync for BuddyAlg<A> where
A: Sync,
impl<A> TxInSafe for BuddyAlg<A>
impl<A> TxOutSafe for BuddyAlg<A> where
A: TxOutSafe,
impl<A> Unpin for BuddyAlg<A> where
A: Unpin,
impl<A> UnwindSafe for BuddyAlg<A>
impl<A> VSafe for BuddyAlg<A> where
A: VSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more