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



##########
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:
       What did you have in mind?
   - If `got >= required` prior to calling `consumer.spill()`, the loop 
condition `while (got < required)` will not be met and we will not execute the 
loop.
   - If `got >= required` after executing `got += 
memoryManager.acquireExecutionMemory()`, we will finish executing the current 
loop iteration, then exit the loop.




-- 
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:
[email protected]



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

Reply via email to