Crate frame_allocator
source ·Expand description
Provides an allocator for physical memory frames. The minimum unit of allocation is a single frame.
This is currently a modified and more complex version of the page_allocator
crate.
TODO: extract the common code and create a generic allocator that can be specialized to allocate pages or frames.
This also supports early allocation of frames before heap allocation is available, and does so behind the scenes using the same single interface. Early pre-heap allocations are limited to tracking a small number of available chunks (currently 32).
Once heap allocation is available, it uses a dynamically-allocated list of frame chunks to track allocations.
The core allocation function is allocate_frames_deferred()
,
but there are several convenience functions that offer simpler interfaces for general usage.
Notes and Missing Features
This allocator only makes one attempt to merge deallocated frames into existing free chunks for de-fragmentation. It does not iteratively merge adjacent chunks in order to maximally combine separate chunks into the biggest single chunk. Instead, free chunks are merged only when they are dropped or when needed to fulfill a specific request.
Structs
- A reference to a single frame within a range of
AllocatedFrames
. - An iterator over each
AllocatedFrame
in a range ofAllocatedFrames
. - A series of pending actions related to frame allocator bookkeeping, which may result in heap allocation.
- A range of contiguous frames in physical memory.
PhysicalMemoryRegion
represents a range of contiguous frames in physical memory for bookkeeping purposes. It does not give access to the underlying frames.- The result of splitting a
Frames
object into multiple smallerFrames
objects.
Enums
- An enum that must be returned by the function passed into
inspect_then_allocate_free_frames()
in order to define the post-iteration behavior. - Types of physical memory. See each variant’s documentation.
Functions
- Allocates the given number of frames with no constraints on the starting physical address.
- Allocates the given number of frames starting at (inclusive of) the frame containing the given
PhysicalAddress
. - Allocates frames with no constraints on the starting physical address, with a size given by the number of bytes.
- Allocates frames starting at the given
PhysicalAddress
with a size given in number of bytes. - Similar to
allocated_frames_deferred()
, but accepts a size value for the allocated frames in number of bytes instead of number of frames. - The core frame allocation routine that allocates the given number of physical frames, optionally at the requested starting
PhysicalAddress
. - Initialize the frame allocator with the given list of available and reserved physical memory regions.
- Iterates over all free frames and invokes the given
func
on each one in order to determine what to do with those frames.
Type Aliases
- A type alias for
Frames
in theAllocated
state. - A type alias for
Frames
in theFree
state, which only suppports 4K pages. - A type alias for
Frames
in theMapped
state. - A type alias for
Frames
in theUnmapped
state.