[alloc+atomic] Fix missing cascade_discard_free_tail after non-tail dealloc/realloc#10
Open
williamwutq wants to merge 6 commits into
Open
[alloc+atomic] Fix missing cascade_discard_free_tail after non-tail dealloc/realloc#10williamwutq wants to merge 6 commits into
williamwutq wants to merge 6 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a space-reclamation bug in the first-fit allocator where coalescing during dealloc/realloc could create a free block at the arena tail that was never discarded, leaving the backing file larger than necessary after all allocations were freed.
Changes:
- Call
cascade_discard_free_tailafter everyadd_to_free_listin Rustdealloc/reallocto ensure tail free blocks are reclaimed. - Mirror the same tail-cascade calls in the C allocator implementation.
- Document the behavior change (allocator comments + changelog entry).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/alloc/first_fit.rs |
Adds tail-cascade calls after add_to_free_list and updates comments clarifying tail reclamation responsibility. |
c/bstack_alloc.c |
Adds tail-cascade calls after alff_add_to_free_list in dealloc/realloc. |
CHANGELOG.md |
Adds an Unreleased entry documenting the tail reclamation fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
726569b to
79adac1
Compare
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.
Description:
cascade_discard_free_tailwas only called from the explicit tail-discard path indealloc. When coalescing inadd_to_free_listproduced a merged block ending at the stack tail, that block was never reclaimed — leaving the arena non-empty after all allocations were freed. Fixed by calling cascade after everyadd_to_free_listin bothdeallocandrealloc(Rust + C). This is purely a space reclamation bug — blocks are correctly marked free and coalesced, they just aren't discarded from the tail. Existing allocated blocks are never touched, and the free list remains structurally valid throughout. The only effect is the file grows larger than necessary and never shrinks back to the header size.Important Feature: No
Type: Allocator - Correction; Allocator - Concurrent
Tests: Included
Feature Flags: alloc + set + atomic
Breaking change: No
New Types: None
Rust Only: No
Fuzz: Yes
Safety Review: Needed: Crash Safety, Invariants, Thread Safety