viirya commented on code in PR #7096:
URL: https://github.com/apache/datafusion-comet/pull/7096#discussion_r4362552466


##########
native/core/src/execution/memory_pools/fair_pool.rs:
##########
@@ -153,22 +209,32 @@ impl MemoryPool for CometFairMemoryPool {
     ) -> Result<(), DataFusionError> {
         if additional > 0 {
             let mut state = self.state.lock();
-            let num = state.consumers.len();
-            let limit = self
-                .pool_size
-                .checked_div(num)
-                .expect("overflow in checked_div");
-            let consumer_used = *state.consumer_used(reservation);
-            if limit < consumer_used.saturating_add(additional) {
-                return resources_err!(
-                    "Failed to acquire {additional} bytes where this consumer 
already holds {consumer_used} bytes and the fair limit is {limit} bytes, {num} 
registered ({} bytes overcommitted)",
-                    self.spark.overcommit()
-                );
-            }
-            // The shares alone do not bound the pool's total, because a 
consumer keeps what it
-            // reserved before another consumer registered.
+            let can_spill = reservation.consumer().can_spill();
             let used = state.used;
-            if self.pool_size < used.saturating_add(additional) {
+            if can_spill {
+                let (task_share, tasks) = self.task_share();
+                // `num_spill` counts this consumer.
+                let limit = task_share.saturating_sub(state.unspillable) / 
state.num_spill.max(1);

Review Comment:
   A follow-up is fine with me. The guides now name the failure and the 
workarounds, and 
`a_consumer_that_can_spill_is_refused_once_the_others_hold_the_tasks_share` 
pins the shape. Could you or @dwsmith1983 open the tracking issue now rather 
than waiting for a repro, and link it from the tuning paragraph in 
`memory_management.md`? Otherwise it only gets filed if someone happens to hit 
it, and the next person who sees "Not enough memory to continue external sort" 
under `fair_unified` has nowhere to land.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to