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
impl FreeListFrameAllocator
Sourcepub unsafe fn new(start: usize, end: usize) -> Self
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.
Sourcepub unsafe fn new_static(
start: usize,
end: usize,
backing: &mut [PhysFrame<Size4KiB>],
) -> (Self, usize)
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 (
starttoend) is frame-aligned and does not overlap with any used memory. - The
backingslice is large enough to hold all frames in the region, otherwise only as many frames as fit will be initialized. - The
backingslice is not aliased elsewhere while the allocator is in use.
Sourcepub unsafe fn reset(&mut self, start: usize, end: usize)
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.
Sourcepub fn alloc_frame(&mut self) -> Option<PhysFrame<Size4KiB>>
pub fn alloc_frame(&mut self) -> Option<PhysFrame<Size4KiB>>
Allocates a frame. Returns None if out of memory.
Sourcepub fn free_frame(&mut self, frame: PhysFrame<Size4KiB>)
pub fn free_frame(&mut self, frame: PhysFrame<Size4KiB>)
Frees a frame, making it available for reuse.