fix: preserve merged block when frame deallocation reaches the top order#46
Conversation
|
Please add a regression test. |
There was a problem hiding this comment.
Pull request overview
Fixes an edge case in the buddy-style FrameAllocator deallocation logic where reaching the maximum order during buddy merging could cause the final merged block to never be reinserted into the free list (silently losing reusable memory). The change brings FrameAllocator deallocation in line with the “merge-then-insert” approach already used elsewhere (e.g., heap dealloc behavior).
Changes:
- Prevent buddy-merge attempts beyond the highest valid order.
- Always reinsert the final merged block into the appropriate free list after merging completes.
- Add a regression test that reproduces the “top-order merge loses block” scenario.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/frame.rs |
Adjusts merge loop bounds and ensures the final merged block is inserted back into the free list. |
src/test.rs |
Adds a regression test covering deallocation/merge behavior at the maximum order boundary. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Added a regression test in It allocates two adjacent top-order blocks, deallocates both of them, and asserts that allocating the same size succeeds again, which reproduces the lost-free-block case this PR fixes. |
This PR fixes a
FrameAllocatordeallocation edge case where a fully merged block could be lost when buddy merging reached the top order. It aligns the implementation with the robust "merge-then-insert" pattern used inHeap::dealloc.Specific changes include:
Why this is useful:
FrameAllocatordeallocation behavior and does not alter the public API.Testing:
cargo test.cargo test --doc.