Skip to main content

FreeListFrameAllocator

Struct FreeListFrameAllocator 

Source
pub struct FreeListFrameAllocator { /* private fields */ }
Expand description

A free list allocator for physical memory frames.

Maintains a list of free frames and supports allocation and deallocation. Suitable for dynamic memory management after boot.

Implementations§

Source§

impl FreeListFrameAllocator

Source

pub unsafe fn new(start: usize, end: usize) -> Self

Creates a new free list frame allocator for the given region.

§Safety

The given range must be frame-aligned and not overlap with used memory.

Source

pub unsafe fn new_static( start: usize, end: usize, backing: &mut [PhysFrame<Size4KiB>], ) -> (Self, usize)

Creates a new free list frame allocator using a static mutable slice as storage.

This avoids dynamic allocation and does not require a global allocator. The slice will be used as a stack of frames; its length determines the maximum number of frames.

Returns a tuple of the allocator and the number of frames initialized.

§Safety

The caller must ensure that:

  • The given range (start to end) is frame-aligned and does not overlap with any used memory.
  • The backing slice is large enough to hold all frames in the region, otherwise only as many frames as fit will be initialized.
  • The backing slice is not aliased elsewhere while the allocator is in use.
Source

pub unsafe fn reset(&mut self, start: usize, end: usize)

Resets the allocator to a new region, clearing and repopulating the free list.

§Safety

The given range must be frame-aligned and not overlap with used memory.

Source

pub fn alloc_frame(&mut self) -> Option<PhysFrame<Size4KiB>>

Allocates a frame. Returns None if out of memory.

Source

pub fn free_frame(&mut self, frame: PhysFrame<Size4KiB>)

Frees a frame, making it available for reuse.

Trait Implementations§

Source§

impl FrameAllocator<Size4KiB> for FreeListFrameAllocator

Source§

fn allocate_frame(&mut self) -> Option<PhysFrame<Size4KiB>>

Allocate a frame of the appropriate size and return it if possible.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.