Fix datafusion-cli memory leak by using snmalloc#15963
Closed
2010YOUY01 wants to merge 1 commit intoapache:mainfrom
Closed
Fix datafusion-cli memory leak by using snmalloc#159632010YOUY01 wants to merge 1 commit intoapache:mainfrom
datafusion-cli memory leak by using snmalloc#159632010YOUY01 wants to merge 1 commit intoapache:mainfrom
Conversation
Contributor
|
Any reason for snmalloc vs jemalloc? |
Contributor
Author
Experiments show |
Contributor
|
I think it makes sense to run some benchmarks again since also jemalloc has implemented some optimizations over time. |
Contributor
|
I see the benchmarks currently are actually using mimalloc, so can you change them as well, so we can also see whether those might be regressing @2010YOUY01 ? |
Contributor
|
Snmalloc is a bit slower on average for me, although keeping too memory reserved is problematic as well: |
|
Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
datafusion-cli(reported memory size increases over time) #15939Rationale for this change
To be more precise: this is not a memory leak, instead, it's memory retention by the global allocator.
The issue is in
datafusion-cli's REPL, the defaultmimallocglobal allocator will hold memory between queries, and let the memory usage accumulate. I think it will only free the allocation lazily when hitting the physical memory limit.It won't cause OOM errors, but I've observed that some memory-intensive queries slow down when run after the global allocator has retained a significant amount of memory.
The direct fix is to call the purge function https://microsoft.github.io/mimalloc/group__extended.html#ga421430e2226d7d468529cec457396756, however, it's tricky to be done (has to be applied once a while on all worker threads).
I tried
snmalloc, and the result shows:snmallocis also one of the fastest allocators likemimalloc. Additionally, the DataFusion benchmark already supportssnmalloc, so I believe switching tosnmallocis a viable fix.What changes are included in this PR?
Uses
snmallocby default indatafusion-cli,mimallocis still kept as a feature.Are these changes tested?
Tested manually for the reproducer in #15939
Are there any user-facing changes?