You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/04/04 11:28:32 UTC

[GitHub] [arrow-datafusion] yjshen commented on a diff in pull request #2135: fix: incorrect memory usage track for sort

yjshen commented on code in PR #2135:
URL: https://github.com/apache/arrow-datafusion/pull/2135#discussion_r841628602


##########
datafusion/core/src/execution/memory_manager.rs:
##########
@@ -342,8 +349,8 @@ impl MemoryManager {
                 // if we cannot acquire at lease 1/2n memory, just wait for others
                 // to spill instead spill self frequently with limited total mem
                 debug!(
-                    "Cannot acquire minimum amount of memory {} on memory manager {}, waiting for others to spill ...",
-                    human_readable_size(min_per_rqt), self);
+                    "Cannot acquire a minimum amount of {} memory from the manager of total {}, waiting for others to spill ...",

Review Comment:
   The second fix: stop calling std::fmt::Display on memory manager since it's acquiring a lock we are already holding. 



##########
datafusion/core/src/execution/memory_manager.rs:
##########
@@ -378,6 +403,8 @@ impl MemoryManager {
                 let mut total = self.requesters_total.lock();
                 assert!(*total >= mem_used);
                 *total -= mem_used;
+                self.cv.notify_all();
+                return;

Review Comment:
   The third fix: stop releasing memory twice for requesters.



##########
datafusion/core/src/physical_plan/sorts/sort.rs:
##########
@@ -169,13 +169,19 @@ impl ExternalSorter {
                 tracking_metrics,
             );
             // Report to the memory manager we are no longer using memory
-            self.metrics.mem_used().set(0);
+            self.free_all_memory();
             result
         } else {
             Ok(Box::pin(EmptyRecordBatchStream::new(self.schema.clone())))
         }
     }
 
+    fn free_all_memory(&self) -> usize {
+        let used = self.metrics.mem_used().set(0);
+        self.shrink(used);

Review Comment:
   The first fix, return all memory to the manager.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org