fix: track untracked memory allocations in spill-capable operators#1
Draft
wirybeaver wants to merge 1 commit into
Draft
fix: track untracked memory allocations in spill-capable operators#1wirybeaver wants to merge 1 commit into
wirybeaver wants to merge 1 commit into
Conversation
Add memory reservation tracking for previously unaccounted allocations in NestedLoopJoin, GroupValuesRows emit, External Sort merge, and SpillManager IPC buffers to close the gap between actual allocator usage and MemoryPool-reported usage, preventing OOM kills. Key changes: SpillManager centralized accounting: - SpillManager::new() requires caller-owned MemoryReservation - Write-side: append_batch tracks IPC buffer overhead (grow/shrink) - Read-side: read_spill_as_stream accepts optional reservation with capacity pre-reservation before spawn_buffered; unbuffered reads pre-reserve one batch slot with try_grow before each blocking decode - ReservationGuard RAII utility (try_grow_guard/grow_guard) NestedLoopJoin probe accounting: - probe_reservation field for tracking probe-phase intermediates - RAII guards for Cartesian indices, filter take, output take - push_output_batch with best-effort try_grow and error-path cleanup - 4 reservation balance tests (inner/left/right/full joins) Aggregation emit accounting: - transient_reservation tracks emitted arrays until yielded downstream - estimated_emit_size() on GroupValues trait (6 implementations) - 2 reservation balance tests (primitive + GroupValuesRows path) External sort: - Sort merge single-file path transfers merge reservation via take() - Grow-to-at-least semantics for transferred reservation reuse - 1 sort spill reservation balance test HEADROOM_FACTOR reduced from 8.0 to 6.0. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Thank you for opening this pull request! Reviewer note: cargo-semver-checks reported the current version number is not SemVer-compatible with the changes in this pull request (compared against the base branch). Details |
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?
Rationale for this change
DataFusion's spill-capable operators (NestedLoopJoin, Aggregation, External Sort) allocate more memory than they reserve through
MemoryPool. This causes actual memory usage to exceed the declared pool budget, leading to OOM kills in production. This PR closes the gap between actual allocator usage andMemoryPool-reported usage by addingMemoryReservationtracking at each untracked allocation site.What changes are included in this PR?
SpillManager centralized IPC buffer accounting:
SpillManager::new()requires a caller-ownedMemoryReservation(production paths must pass one)append_batchtracks IPC buffer overhead with balanced grow/shrinkread_spill_as_streamaccepts optional reservation with capacity pre-reservation beforespawn_buffered; unbuffered reads pre-reserve withtry_growbefore each blocking decodeReservationGuardRAII utility (try_grow_guard/grow_guard) for error-safe accountingNestedLoopJoin probe accounting:
probe_reservationfield for probe-phase intermediatespush_output_batchwith best-efforttry_growand error-path cleanupAggregation emit accounting:
transient_reservationtracks emitted arrays until yielded downstreamestimated_emit_size()onGroupValuestrait (6 implementations)External sort:
take()with grow-to-at-least semanticsHeadroom:
HEADROOM_FACTORreduced from 8.0 to 6.0.Are these changes tested?
Yes:
ReservationGuardunit tests (auto_shrinks, release_prevents_shrink, grow_guard, error_path)Are there any user-facing changes?
SpillManager::new()now requires aMemoryReservationparameter (API change for external callers constructing SpillManager directly)read_spill_as_streamandread_spill_as_stream_unbufferedaccept an additional optionalMemoryReservationparameter