fix: drop old reservation before creating new one in claim() (#10139)#10167
Open
sandy-sachin7 wants to merge 1 commit into
Open
fix: drop old reservation before creating new one in claim() (#10139)#10167sandy-sachin7 wants to merge 1 commit into
sandy-sachin7 wants to merge 1 commit into
Conversation
…10139) The claim() method on Bytes and MutableBuffer created a new pool reservation before dropping the existing one, causing transient double-counting of memory in the pool during the window between reserve() and the old reservation being dropped. For pools with capacity limits, or when another thread reads the pool counter during this window, the pool would report up to 2x the actual memory in use. Fix: call guard.take() to drop the old reservation before calling pool.reserve() to create the new one.
Contributor
|
I can't help but notice multiple PRs were raised in a short span of time:
Are these all entirely LLM generated? |
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.
Which issue does this PR close?
Closes #10139.
Rationale for this change
The
claim()method onBytesandMutableBuffercreates a new pool reservation before dropping the existing one. This causes a transient period where both the old and new reservations exist simultaneously, resulting in the memory pool reporting up to 2x the actual memory in use.The problematic sequence in the old code:
For pools with capacity limits, or when another thread reads the pool counter during this window, the pool would report double the actual memory in use.
What changes are included in this PR?
arrow-buffer/src/bytes.rs:Bytes::claimnow drops the existing reservation (guard.take()) before callingpool.reserve().arrow-buffer/src/buffer/mutable.rs: Same fix forMutableBuffer::claim.arrow-buffer/src/bytes.rs: Addedtest_claim_does_not_double_countusing aMaxTrackerPoolwrapper that detects transient double-counting deterministically.Are these changes tested?
Yes — the new
test_claim_does_not_double_counttest uses a custom pool that records the maximumused()value observed during anyreserve()call. Before the fix, claiming the same buffer twice would producemax_used = 2048(double the 1024 buffer size). After the fix,max_used = 1024.All existing arrow-buffer tests (53) and downstream tests continue to pass.
Are there any user-facing changes?
No API changes. The behavior is identical except that there is no longer a window where the pool counter is double-counted during re-claiming.