-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-14363] Fix executor OOM due to memory leak in the Sorter #12285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -215,8 +215,6 @@ private void writeSortedFile(boolean isLastFile) throws IOException { | |
| } | ||
| } | ||
|
|
||
| inMemSorter.reset(); | ||
|
|
||
| if (!isLastFile) { // i.e. this is a spill file | ||
| // The current semantics of `shuffleRecordsWritten` seem to be that it's updated when records | ||
| // are written to disk, not when they enter the shuffle sorting code. DiskBlockObjectWriter | ||
|
|
@@ -255,6 +253,10 @@ public long spill(long size, MemoryConsumer trigger) throws IOException { | |
|
|
||
| writeSortedFile(false); | ||
| final long spillSize = freeMemory(); | ||
| inMemSorter.reset(); | ||
| // Reset the in-memory sorter's pointer array only after freeing up the memory pages holding the | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can move this comment into reset()
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, comment in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I don't have strong opinion on it. |
||
| // records. Otherwise, if the task is over allocated memory, then without freeing the memory pages, | ||
| // we might not be able to get memory for the pointer array. | ||
| taskContext.taskMetrics().incMemoryBytesSpilled(spillSize); | ||
| return spillSize; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to move this call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we need to reset the pointer array only after freeing up the memory pages holding records. Otherwise it might happen that the task might not get memory for the pointer array if it is already holding a lot of memory.