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 currently does not merge freed chunks (de-fragmentation). We don’t need to do so until we actually run out of address space or until a requested address is in a chunk that needs to be merged.


A reference to a single frame within a range of AllocatedFrames.
Represents a range of allocated physical memory [Frame]s; derefs to [FrameRange].
An iterator over each AllocatedFrame in a range of AllocatedFrames.
A series of pending actions related to frame allocator bookkeeping, which may result in heap allocation.
A region of physical memory.


Types of physical memory. See each variant’s documentation.


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.