Skip to content
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

fix: incorrect memory usage track for sort #2135

Merged
merged 2 commits into from
Apr 4, 2022
Merged

Conversation

yjshen
Copy link
Member

@yjshen yjshen commented Apr 2, 2022

Which issue does this PR close?

Closes #2155.

Rationale for this change

  1. Since we've changed Memory Requesters' memory tracking behavior in Add MemTrackingMetrics to ease memory tracking for non-limited memory consumers #1691:

Consumers push their memory usage to MemoryManager. No more pull from MemoryManagers for usage updates.

The sort memory is not correctly tracked anymore.

  1. The debug log for "sleep on memory insufficient" introduced a deadlock by holding a lock and asking for the lock again.

What changes are included in this PR?

  • Correct sort memory track by manually update usage after sort.
  • Stop trying to acquire the lock while already holding it.

Are there any user-facing changes?

No.

@github-actions github-actions bot added the datafusion Changes in the datafusion crate label Apr 2, 2022
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first fix, return all memory to the manager.

@@ -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 ...",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@@ -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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The third fix: stop releasing memory twice for requesters.

@yjshen yjshen marked this pull request as ready for review April 4, 2022 11:38
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me -- thanks @yjshen

@alamb alamb merged commit 2a4a835 into apache:master Apr 4, 2022
@yjshen yjshen deleted the mm_fix branch April 22, 2022 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datafusion Changes in the datafusion crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent memory tracking for SortExec
2 participants