misc: release old buffers before ensureCapacity growth - #804
Open
lizhen-0710 wants to merge 1 commit into
Open
Conversation
| auto rootPool = | ||
| memoryManager()->addRootPool("ensureCapacityReleaseBeforeAlloc", 6 << 20); | ||
| auto leafPool = rootPool->addLeafChild("leaf"); | ||
| BufferPtr buffer = AlignedBuffer::allocate<char>(4 << 20, leafPool.get()); |
Collaborator
There was a problem hiding this comment.
AlignedBuffer::allocate allocates more than 4M due to kPaddingSize, roughly equals to 1.5*4M. So ensureCapacity may not trigger date.reset and reallocate
Collaborator
Author
There was a problem hiding this comment.
Good catch, updated, thanks.
lizhen-0710
force-pushed
the
misc-ensure-capacity-release-buffer
branch
from
July 29, 2026 13:47
45291d2 to
a3056a3
Compare
lizhen-0710
force-pushed
the
misc-ensure-capacity-release-buffer
branch
from
July 29, 2026 14:09
a3056a3 to
7b91c27
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.
What problem does this PR solve?
Release the existing buffer before allocating a larger replacement in dwio::common::ensureCapacity(). The helper is used by Parquet decode buffers and other scan-side scratch buffers where growth can otherwise transiently hold both the old large allocation and the new larger allocation in the same memory pool.
Type of Change
Description
This reduces short-lived scan memory spikes without changing the returned buffer contents contract: callers already request capacity growth and do not depend on preserving old contents through this helper.
Add a regression test with a constrained memory pool. The test derives the old and new capacities from the allocator preferred size, then requests one byte beyond the old capacity so ensureCapacity must reallocate. Without releasing the old buffer first, the constrained pool cannot hold the old and new allocations at the same time and the test fails with MEM_CAP_EXCEEDED.
Performance Impact
No Impact: This change does not affect the critical path (e.g., build system, doc, error handling).
Positive Impact: I have run benchmarks.
Click to view Benchmark Results
Negative Impact: Explained below (e.g., trade-off for correctness).
Release Note
Please describe the changes in this PR
Release Note:
Checklist (For Author)
Breaking Changes
No
Yes (Description: ...)
Click to view Breaking Changes