fix: use conservative bucket reuse that survives reload#394
Merged
Conversation
|
|
|
|
|
|
michael-weigelt
approved these changes
Aug 21, 2025
maksymar
added a commit
that referenced
this pull request
Aug 25, 2025
This PR reverts adding `reclaim_memory` method. Reverts several recent commits in a single change: - `6e397bd` fix: use conservative bucket reuse that survives reload #394 - `00468e1` docs: update memory reclamation examples in the docs #392 - `b911479` docs: cleanup documentation #391 - `d1fde89` docs: use reclaim_memory() name and update docs accordingly #388 - `a18917b` docs: add safety documentation and tests for manual bucket release #387 - `73e96e8` feat: add manual bucket release to prevent memory waste #386 This PR restores the codebase to the state before these commits. Done with `git revert -n 6e397bd 00468e1 b911479 d1fde89 a18917b 73e96e8` The reason for reverting this approach was that it can reclaim unused memory in theory but provides little benefit in real-world migrations. All due to the requirement to keep buckets in ascending order in each VM. Example 1: Reuse works ``` A allocates: [0, 4, 5] B allocates: [1, 2, 3] A frees: [0, 4, 5] B grows: can reuse bucket 4 (since 4 > max(B) = 3) B after grow: [1, 2, 3, 4] ``` Example 2: Reuse fails ``` A allocates: [0, 1, 2] B allocates: [4, 5, 6] A frees: [0, 1, 2] B grows: cannot reuse any freed bucket (all < max(B) = 6), so allocates new bucket 7 B after grow: [4, 5, 6, 7] ``` In real life when migrating state A to state B, state B created after state A grown, so it's first bucket ID is already higher than any free bucket in state A virtual memory, therefore can not be reused.
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.
This PR uses conservative bucket reuse to preserve ordering across reloads.
Problem
Previously, a memory with buckets
[5, 6, 7]could reuse free buckets[0, 1, 2], producing[5, 6, 7, 0, 1, 2]. On reload, the manager reads buckets in ascending order —[0, 1, 2, 5, 6, 7]— corrupting the structure.Fix
When growing a memory, reuse only free buckets with IDs greater than the memory’s current max; otherwise allocate a new bucket. This keeps per-memory bucket IDs strictly ascending across lifetimes.
Guarantees
Result
A conservative reuse algorithm that maintains stable-structure consistency after reloads.