Tom van Bussel created SPARK-32901:
--------------------------------------

             Summary: UnsafeExternalSorter may cause a SparkOutOfMemoryError to 
be thrown while spilling
                 Key: SPARK-32901
                 URL: https://issues.apache.org/jira/browse/SPARK-32901
             Project: Spark
          Issue Type: Bug
          Components: Spark Core
    Affects Versions: 3.0.1, 2.4.7
            Reporter: Tom van Bussel


Consider the following sequence of events:
 # {{UnsafeExternalSorter}} runs out of space in its pointer array and attempts 
to allocate a large array to replace the current one.
 # {{TaskMemoryManager}} tries to allocate the memory backing the large array 
using {{MemoryManager}}, but {{MemoryManager}} is only willing to return most 
but not all of the memory requested.
 # {{TaskMemoryManager}} asksĀ {{UnsafeExternalSorter}} to spill, which causesĀ 
{{UnsafeExternalSorter}} to spill the current run to disk, to free its record 
pages and to reset its {{UnsafeInMemorySorter}}.
 # {{UnsafeInMemorySorter}} frees its pointer array, and tries to allocate a 
new small pointer array.
 # {{TaskMemoryManager}} tries to allocate the memory backing the small array 
using {{MemoryManager}}, but {{MemoryManager}} is unwilling to give it any 
memory, as the {{TaskMemoryManager}} is still holding on to the memory it got 
for the large array.
 # {{TaskMemoryManager}} again asks {{UnsafeExternalSorter}} to spill, but this 
time there is nothing to spill.
 # {{UnsafeInMemorySorter}} receives less memory than it requested, and causes 
a {{SparkOutOfMemoryError}} to be thrown, which causes the current task to fail.

A simple way to fix this is to avoid allocating a new array in 
{{UnsafeInMemorySorter.reset()}} and to do this on-demand instead.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

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

Reply via email to