Skip to content

feat: Expose used MemoryPool details in ResourcesExhausted error messages#20387

Merged
xudong963 merged 2 commits intoapache:mainfrom
erenavsarogullari:expose_memory_pool_name_in_error_messages
Apr 21, 2026
Merged

feat: Expose used MemoryPool details in ResourcesExhausted error messages#20387
xudong963 merged 2 commits intoapache:mainfrom
erenavsarogullari:expose_memory_pool_name_in_error_messages

Conversation

@erenavsarogullari
Copy link
Copy Markdown
Member

@erenavsarogullari erenavsarogullari commented Feb 16, 2026

Which issue does this PR close?

Rationale for this change

memory_limit (RuntimeEnvBuilder::new().with_memory_limit()) configuration uses greedy memory pool as default. However, if memory_pool (RuntimeEnvBuilder::new().with_memory_pool()) is set, it overrides by expected memory_pool config such as fair. Also, if both memory_limit and memory_pool configs are not set, unbounded memory pool will be used so it can be useful to expose ultimately used/selected pool as part of ResourcesExhausted error message for the end user awareness and the user may need to switch used memory pool (greedy, fair, unbounded),

  • Also, this comparison table is an example use-case for both greedy and fair memory pools runtime behaviors and this addition can help for this kind of comparison table by exposing used memory pool info as part of native logs.

Please find following example use-cases by datafusion-cli:
Case1: datafusion-cli result when memory-limit and top-memory-consumers > 0 are set:

eren.avsarogullari@AWGNPWVK961 debug % ./datafusion-cli --memory-limit 10M --command 'select * from generate_series(1,500000) as t1(v1) order by v1;' --top-memory-consumers 3

DataFusion CLI v53.0.0
Error: Not enough memory to continue external sort. Consider increasing the memory limit config: 'datafusion.runtime.memory_limit', or decreasing the config: 'datafusion.execution.sort_spill_reservation_bytes'.
caused by
Resources exhausted: Additional allocation failed for ExternalSorter[0] with top memory consumers (across reservations) as:
  ExternalSorterMerge[0]#2(can spill: false) consumed 10.0 MB, peak 10.0 MB,
  DataFusion-Cli#0(can spill: false) consumed 0.0 B, peak 0.0 B,
  ExternalSorter[0]#1(can spill: true) consumed 0.0 B, peak 0.0 B.
Error: Failed to allocate additional 128.0 KB for ExternalSorter[0] with 0.0 B already allocated for this reservation - 0.0 B remain available for the total memory pool: greedy(used: 10.0 MB, pool_size: 10.0 MB)

Case2: datafusion-cli result when memory-limit and top-memory-consumers = 0 (disabling top memory consumers logging) are set:

eren.avsarogullari@AWGNPWVK961 debug % ./datafusion-cli --memory-limit 10M --command 'select * from generate_series(1,500000) as t1(v1) order by v1;' --top-memory-consumers 0

DataFusion CLI v53.0.0
Error: Not enough memory to continue external sort. Consider increasing the memory limit config: 'datafusion.runtime.memory_limit', or decreasing the config: 'datafusion.execution.sort_spill_reservation_bytes'.
caused by
Resources exhausted: Failed to allocate additional 128.0 KB for ExternalSorter[0] with 0.0 B already allocated for this reservation - 0.0 B remain available for the total memory pool: greedy(used: 10.0 MB, pool_size: 10.0 MB)

Case3: datafusion-cli result when only memory-limit, memory-pool and top-memory-consumers > 0 are set:

eren.avsarogullari@AWGNPWVK961 debug % ./datafusion-cli --memory-limit 10M --mem-pool-type fair --top-memory-consumers 3 --command 'select * from generate_series(1,500000) as t1(v1) order by v1;'

DataFusion CLI v53.0.0
Error: Not enough memory to continue external sort. Consider increasing the memory limit config: 'datafusion.runtime.memory_limit', or decreasing the config: 'datafusion.execution.sort_spill_reservation_bytes'.
caused by
Resources exhausted: Additional allocation failed for ExternalSorter[0] with top memory consumers (across reservations) as:
  ExternalSorterMerge[0]#2(can spill: false) consumed 10.0 MB, peak 10.0 MB,
  ExternalSorter[0]#1(can spill: true) consumed 0.0 B, peak 0.0 B,
  DataFusion-Cli#0(can spill: false) consumed 0.0 B, peak 0.0 B.
Error: Failed to allocate additional 128.0 KB for ExternalSorter[0] with 0.0 B already allocated for this reservation - 0.0 B remain available for the total memory pool: fair(pool_size: 10.0 MB)

What changes are included in this PR?

  • Adding name property to MemoryPool instances,
  • Expose used MemoryPool info to Resources Exhausted error messages

Are these changes tested?

Yes and updating existing test cases.

Are there any user-facing changes?

Yes, being updated Resources Exhausted error messages.

@github-actions github-actions Bot added core Core DataFusion crate execution Related to the execution crate physical-plan Changes to the physical-plan crate labels Feb 16, 2026
@erenavsarogullari erenavsarogullari force-pushed the expose_memory_pool_name_in_error_messages branch 4 times, most recently from 75af7db to 168b51a Compare February 16, 2026 23:52
@erenavsarogullari erenavsarogullari force-pushed the expose_memory_pool_name_in_error_messages branch from 168b51a to 73bcc70 Compare March 10, 2026 02:53
@erenavsarogullari erenavsarogullari force-pushed the expose_memory_pool_name_in_error_messages branch from b24f6c8 to 897b01c Compare April 13, 2026 01:03
@github-actions github-actions Bot removed core Core DataFusion crate physical-plan Changes to the physical-plan crate labels Apr 13, 2026
@erenavsarogullari erenavsarogullari changed the title [WIP] feat: Expose used MemoryPool in ResourcesExhausted error messages feat: Expose used MemoryPool in ResourcesExhausted error messages Apr 13, 2026
@erenavsarogullari erenavsarogullari changed the title feat: Expose used MemoryPool in ResourcesExhausted error messages feat: Expose used MemoryPool details in ResourcesExhausted error messages Apr 13, 2026
@erenavsarogullari erenavsarogullari force-pushed the expose_memory_pool_name_in_error_messages branch 4 times, most recently from 200940a to 10d6c19 Compare April 20, 2026 00:07
Copy link
Copy Markdown
Contributor

@nathanb9 nathanb9 left a comment

Choose a reason for hiding this comment

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

Nice. This makes sense to me

Comment thread datafusion/execution/src/memory_pool/pool.rs Outdated
@erenavsarogullari erenavsarogullari force-pushed the expose_memory_pool_name_in_error_messages branch 2 times, most recently from ff7b82a to 9abbd3a Compare April 20, 2026 04:01
write!(
f,
"{}",
format_args!(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do we need this format_args!?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed by the last commit. Thanks for the review.

}
}

impl Display for FairSpillPool {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

how about adding used in FairSpillPool Display

Copy link
Copy Markdown
Member Author

@erenavsarogullari erenavsarogullari Apr 21, 2026

Choose a reason for hiding this comment

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

Currently, both GreedyMemoryPool and UnboundedMemoryPool track used memory size. FairSpillPool can also be extended to track it. I think it can be useful extension. Does it make sense to address by a follow-up issue? If so, i can create and work on it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yes, good to me

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

#21753 has been created for follow-up effort. Thanks for quick feedback.

@erenavsarogullari erenavsarogullari force-pushed the expose_memory_pool_name_in_error_messages branch from 9abbd3a to 5b181a1 Compare April 21, 2026 05:12
@xudong963 xudong963 added this pull request to the merge queue Apr 21, 2026
Merged via the queue into apache:main with commit 9b5e43e Apr 21, 2026
31 checks passed
@erenavsarogullari erenavsarogullari deleted the expose_memory_pool_name_in_error_messages branch April 22, 2026 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

execution Related to the execution crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose used MemoryPool details in ResourcesExhausted error messages

3 participants