[−][src]Struct crndm::alloc::BuddyAlg
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
impl<A: MemPool> BuddyAlg<A>
[src]
pub fn init(&mut self, size: usize)
[src]
Pool Initialization with a given device size
pub unsafe fn log(&mut self, off: u64, data: u64)
[src]
Adds a new low-level 64-bit log entry
pub unsafe fn drop_on_failure(&mut self, off: u64, len: usize)
[src]
Adds a new low-level DropOnFailure
log entry
pub unsafe fn aux_push(&mut self, off: u64, data: u64)
[src]
Adds a new entry to the auxiliary list of changes
pub fn drain_aux(&mut self)
[src]
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.
pub fn discard(&mut self)
[src]
Discards the changes in the auxiliary buffer
pub unsafe fn alloc_impl(&mut self, len: usize, perform: bool) -> u64
[src]
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.
pub unsafe fn dealloc_impl(&mut self, off: u64, len: usize, perform: bool)
[src]
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.
pub unsafe fn perform(&mut self)
[src]
Materializes the changes in the auxiliary list and clears the drop log records
pub fn is_allocated(&mut self, off: u64, _len: usize) -> bool
[src]
Determines if the given address range is allocated
pub fn recover(&mut self)
[src]
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 size(&self) -> usize
[src]
Returns the pool size
pub fn available(&self) -> usize
[src]
Returns the total available space in the pool
pub fn used(&self) -> usize
[src]
Returns the total number of bytes used from the pool
pub fn print(&self)
[src]
Prints the free lists
Auto Trait Implementations
impl<A> LooseTxInUnsafe for BuddyAlg<A> where
A: LooseTxInUnsafe,
[src]
A: LooseTxInUnsafe,
impl<A> PSafe for BuddyAlg<A> where
A: PSafe,
[src]
A: PSafe,
impl<A> RefUnwindSafe for BuddyAlg<A> where
A: RefUnwindSafe,
[src]
A: RefUnwindSafe,
impl<A> Send for BuddyAlg<A> where
A: Send,
[src]
A: Send,
impl<A> Sync for BuddyAlg<A> where
A: Sync,
[src]
A: Sync,
impl<A> TxInSafe for BuddyAlg<A> where
A: TxInSafe,
[src]
A: TxInSafe,
impl<A> TxOutSafe for BuddyAlg<A> where
A: TxOutSafe,
[src]
A: TxOutSafe,
impl<A> Unpin for BuddyAlg<A> where
A: Unpin,
[src]
A: Unpin,
impl<A> UnwindSafe for BuddyAlg<A> where
A: UnwindSafe,
[src]
A: UnwindSafe,
impl<A> VSafe for BuddyAlg<A> where
A: VSafe,
[src]
A: VSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
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]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
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]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,