Skip to content

fix: handle zero start correctly when splitting frame ranges#47

Merged
jiegec merged 1 commit intorcore-os:masterfrom
mevinagrise:fix-frame-zero-start
Mar 26, 2026
Merged

fix: handle zero start correctly when splitting frame ranges#47
jiegec merged 1 commit intorcore-os:masterfrom
mevinagrise:fix-frame-zero-start

Conversation

@mevinagrise
Copy link
Copy Markdown
Contributor

This PR fixes the special-case handling in FrameAllocator::add_frame when the range starts at 0.

Specific changes include:

  • Replaced the hard-coded 32 fallback used when current_start == 0 with the allocator's actual maximum block size.
  • Added a regression test showing that add_frame(0, 64) can now preserve and allocate a full 64-frame block.
  • Updated the existing large-range tests to match the corrected allocation behavior, where the allocator can now preserve larger blocks starting at 0.

Why this is useful:

  • The previous logic unnecessarily fragmented ranges that started at 0 by assuming a default alignment of 32.
  • Since address 0 is naturally aligned to any power-of-two, it should be allowed to form the largest possible block supported by the ORDER parameter.
  • This fix enables large allocations (e.g., 64 frames or more) from the start of memory that were previously impossible.
  • The fix keeps the implementation aligned with the allocator's configured maximum order.

Testing:

  • Ran cargo test.
  • Ran cargo test --doc.

Note:
This PR changes the expected allocation order in two existing tests because the corrected behavior now preserves the largest valid block at address 0 instead of fragmenting it early.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes FrameAllocator::add_frame special-casing for ranges starting at 0 so the allocator preserves the largest block size permitted by ORDER, avoiding unnecessary fragmentation at address 0.

Changes:

  • Replace the current_start == 0 fallback alignment from hard-coded 32 to the allocator’s computed maximum block size (1 << (ORDER - 1)).
  • Add a regression test ensuring add_frame(0, 64) can allocate a full 64-frame block.
  • Update large-range allocation tests to reflect the corrected block preservation behavior starting at 0.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/frame.rs Adjusts add_frame block sizing/alignment logic for start == 0 to use the allocator’s max block size.
src/test.rs Adds regression coverage for zero-start behavior and updates large-range expectations accordingly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jiegec jiegec merged commit 29f39f8 into rcore-os:master Mar 26, 2026
6 checks passed
@mevinagrise mevinagrise deleted the fix-frame-zero-start branch March 30, 2026 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants