Ngone51 commented on a change in pull request #32625:
URL: https://github.com/apache/spark/pull/32625#discussion_r637812120



##########
File path: core/src/main/java/org/apache/spark/memory/TaskMemoryManager.java
##########
@@ -202,14 +202,22 @@ public long acquireExecutionMemory(long required, 
MemoryConsumer consumer) {
         }
       }
 
-      // call spill() on itself
-      if (got < required) {
+      // Attempt to free up memory by self-spilling.
+      //
+      // When our spill handler releases memory, 
`ExecutionMemoryPool#releaseMemory()` will
+      // immediately notify other tasks that memory has been freed, and they 
may acquire the
+      // newly-freed memory before we have a chance to do so (SPARK-35486). In 
that case, we will
+      // try again in the next loop iteration.
+      while (got < required) {
         try {
           long released = consumer.spill(required - got, consumer);
           if (released > 0) {
             logger.debug("Task {} released {} from itself ({})", taskAttemptId,
               Utils.bytesToString(released), consumer);
             got += memoryManager.acquireExecutionMemory(required - got, 
taskAttemptId, mode);
+          } else {
+            // Self-spilling could not free up any more memory.
+            break;

Review comment:
       Shall we break earlier when `got >= required`?




-- 
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to