Skip to content

feat: add jemalloc as optional custom allocator #1679

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

Merged
merged 7 commits into from
Apr 25, 2025

Conversation

mbutrovich
Copy link
Contributor

@mbutrovich mbutrovich commented Apr 23, 2025

Which issue does this PR close?

Closes #1648.

Rationale for this change

Comet currently supports mimalloc to override the system memory allocator (make release COMET_FEATURES=mimalloc or cargo build --features=mimalloc). We want to explore jemalloc (tikv-jemallocator crate) as an alternative to mimalloc for our custom allocator. I will bring some discussion from #1648:

#1648 (comment)

FYI: We found mimalloc to be unstable for running long term (keeps memory allocated but seems doesn't release it over time => running into OOMs much more easily). Switching to jemalloc fixed this.

#1648 (comment)

We prefer to use jemalloc with Comet by setting LD_PRELOAD, as it returns freed memory to the operating system more aggressively than ptmalloc, resulting in a more predictable RSS for the Spark executor process. Additionally, jemalloc's memory profiler is helpful for diagnosing OOM issues.

However, I'm uncertain whether jemalloc can still be used with LD_PRELOAD when Comet is compiled with mimalloc. The last time I attempted to dynamically override malloc it didn't work.

#1648 (comment)

I've also only ever used jemalloc in the past. I'm not sure what the discussion was at the time to pursue mimalloc for Comet. @mdcallag has some recent writing on the topic, althrough RocksDB is a different workload than what we're doing:

https://smalldatum.blogspot.com/2025/04/battle-of-mallocators.html https://smalldatum.blogspot.com/2025/04/battle-of-mallocators-part-2.html

The Germans 🇩🇪 did a bake-off a few years ago and they chose jemalloc for Umbra (and likely CedarDB): https://www.adms-conf.org/2019-camera-ready/durner_adms19.pdf

Other relevant reading:

What changes are included in this PR?

Add jemalloc as a feature accessible through make release COMET_FEATURES=jemalloc. I had tcmalloc (Google) and snmalloc (Microsoft Research) as well, but the former failed to link at compilation time and the latter didn't like being loaded later as a dynamic library with Comet.

How are these changes tested?

@mbutrovich mbutrovich changed the title ignore: explore jemalloc and snmalloc instead of mimalloc feat: add jemalloc as custom allocator feature Apr 24, 2025
@mbutrovich mbutrovich changed the title feat: add jemalloc as custom allocator feature feat: add jemalloc as optional custom allocator Apr 24, 2025
Copy link
Member

@andygrove andygrove left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @mbutrovich

@codecov-commenter
Copy link

codecov-commenter commented Apr 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 58.81%. Comparing base (f09f8af) to head (2fc309e).
Report is 163 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1679      +/-   ##
============================================
+ Coverage     56.12%   58.81%   +2.68%     
- Complexity      976     1082     +106     
============================================
  Files           119      125       +6     
  Lines         11743    12597     +854     
  Branches       2251     2362     +111     
============================================
+ Hits           6591     7409     +818     
- Misses         4012     4016       +4     
- Partials       1140     1172      +32     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mbutrovich
Copy link
Contributor Author

The Spark SQL test does not seem related to the change.

@parthchandra
Copy link
Contributor

Restarted the test

@mbutrovich mbutrovich requested a review from parthchandra April 24, 2025 17:46
# Conflicts:
#	native/Cargo.lock
#	native/core/Cargo.toml
@andygrove andygrove merged commit 7e2ebab into apache:main Apr 25, 2025
78 checks passed
@mbutrovich mbutrovich deleted the allocators branch May 7, 2025 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate unstable benchmark results on macOS
4 participants