feat: add fixed-address allocation for FrameAllocator#48
Merged
jiegec merged 1 commit intorcore-os:masterfrom Mar 30, 2026
Merged
feat: add fixed-address allocation for FrameAllocator#48jiegec merged 1 commit intorcore-os:masterfrom
jiegec merged 1 commit intorcore-os:masterfrom
Conversation
Add `alloc_at(start, count)` to allocate a specific range of frames, addressing the need for fixed-address allocation in OS scenarios like MMIO regions, DMA buffers, and identity mapping. Closes rcore-os#30
There was a problem hiding this comment.
Pull request overview
Adds fixed-address frame allocation support to the buddy-system FrameAllocator, enabling callers to request allocation of a specific physical frame range (useful for MMIO/DMA/identity-mapped regions), and validates behavior via new unit tests.
Changes:
- Add
FrameAllocator::alloc_at(start, count)public API plus internalalloc_at_power_of_twohelper to allocate an aligned, power-of-two-sized range at a specific start frame. - Implement split-down logic that returns non-target fragments back into the appropriate free lists.
- Add a focused suite of unit tests covering success, splitting behavior, misalignment, unavailable ranges, out-of-range requests, and dealloc/merge roundtrips.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/frame.rs |
Introduces fixed-address allocation API and implements the buddy split logic needed to allocate at an exact start frame. |
src/test.rs |
Adds unit tests validating alloc_at correctness across common and edge scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
FrameAllocator::alloc_at(start, count)for fixed-address frame allocation, as requested in #30.There are common scenarios (MMIO regions, DMA buffers, identity mapping) where frames must be allocated at a specific physical address rather than an arbitrary one chosen by the allocator. The new method finds the free block containing the requested range, splits it down to the exact target size, and returns the remaining fragments to the free lists.
API
The method follows the existing
alloc/alloc_power_of_twopattern with a public wrapper and a privatealloc_at_power_of_twohelper. Existingdeallocworks unchanged for blocks allocated viaalloc_at.Algorithm
countup to next power of two, validate alignmentallocTest plan
All 25 tests pass (
cargo test), no new clippy warnings.Closes #30