Skip to content

Roll back free-list blocks from earlier collect() rounds - #588

Open
ariscript wants to merge 2 commits into
mainfrom
arprakas/chunked-alloc-rollback
Open

ariscript wants to merge 2 commits into
mainfrom
arprakas/chunked-alloc-rollback

Conversation

@ariscript

Copy link
Copy Markdown
Member

reuse() only returned blocks released in the current collect() to the bump pointer. A block that went to a free list in an earlier round stayed there even after the blocks above it were freed, so the heap could not shrink back past it. That matches the behavior before #583, but it is cheap to fix now that collect() runs periodically.

Each reuse() now merges the free lists with the newly released blocks, rolls the bump pointer down while a candidate ends exactly at it, and rebuilds the free lists from what is left. Both inputs are identical on every rank, so the result stays symmetric. Cost is O(F log F) per collect() for F free blocks, small next to its gc.collect() and device sync.

The free lists are rebuilt highest offset first, so pop() hands out the lowest block and keeps blocks near the top free for later rollbacks.

The churn test now frees everything at the end and checks that the heap rolls back to where it started, which fails without this change when buffers are kept every 16 iterations. Two new tests cover a block freed in an earlier round rolling back, and the lowest-first order.

This is the requested follow-up from the review comment on #583.

reuse() only returned blocks released in the current collect() to the
bump pointer. A block that went to a free list in an earlier round stayed
there even after the blocks above it were freed, so the heap could not
shrink back past it. That matches the behavior before #583, but it is
cheap to fix now that collect() runs periodically.

Each reuse() now merges the free lists with the newly released blocks,
rolls the bump pointer down while a candidate ends exactly at it, and
rebuilds the free lists from what is left. Both inputs are identical on
every rank, so the result stays symmetric. Cost is O(F log F) per
collect() for F free blocks, small next to its gc.collect() and device
sync.

The free lists are rebuilt highest offset first, so pop() hands out the
lowest block and keeps blocks near the top free for later rollbacks.

The churn test now frees everything at the end and checks that the heap
rolls back to where it started, which fails without this change when
buffers are kept every 16 iterations. Two new tests cover a block freed
in an earlier round rolling back, and the lowest-first order.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 15, 2026 20:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added in-progress We are working on it iris Iris project issue labels Oct 15, 2026

@nirvedhmeshram nirvedhmeshram left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM % small docs nit

Comment thread iris/host/memory/allocators/vmem_chunked_allocator.py Outdated
@ariscript
ariscript enabled auto-merge (squash) October 15, 2026 21:55

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in-progress We are working on it iris Iris project issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants