Repository navigation
feat: make jemalloc the default allocator of the native library - #7835
Conversation
6b2284f to
8c58b66
Compare
sunchao
left a comment
There was a problem hiding this comment.
Please update the release scripts along with the default. Both release builds now select jemalloc, and an explicit mimalloc build silently selects the system allocator. The extra allocator test could switch to --no-default-features --features hdfs-opendal,delta to keep exercising the system backend.
Automated review by Codex.
| [features] | ||
| backtrace = ["datafusion/backtrace"] | ||
| default = ["hdfs-opendal", "delta"] | ||
| default = ["hdfs-opendal", "delta", "jemalloc"] |
There was a problem hiding this comment.
The release script builds once with defaults and once with --features jemalloc. Both now select jemalloc. If the libraries match, cmp aborts the release. If they differ, we still ship jemalloc twice, and only the second build pins the page size. Can we set JEMALLOC_SYS_WITH_LG_PAGE=12 before building the default library and update the packaging script to either drop the redundant classifier or explicitly build a system-allocator variant?
There was a problem hiding this comment.
Done in 0692e4d. The release now builds one native library per architecture, with JEMALLOC_SYS_WITH_LG_PAGE=12 exported before the build, and publishes one jar per Spark and Scala combination. The jemalloc classifier jar would only duplicate the artifact, so it is gone, along with the unreleased jemalloc Maven profile. check_native_libs still checks that each jar holds the libraries the script built, and the snapshot workflow pins the page size the same way. Users on 64 KiB-page kernels build from source, as the FAQ and source.md say.
| [features] | ||
| backtrace = ["datafusion/backtrace"] | ||
| default = ["hdfs-opendal", "delta"] | ||
| default = ["hdfs-opendal", "delta", "jemalloc"] |
There was a problem hiding this comment.
The documented macOS command, make release COMET_FEATURES=mimalloc, now enables both features. Make only checks the explicit flags, so it misses the conflict and the Rust cfg silently selects System. Can we preserve the explicit mimalloc choice and test the selected backend? For example, that Make path could pass --no-default-features --features hdfs-opendal,delta,mimalloc.
There was a problem hiding this comment.
Done in 0692e4d. lib.rs now selects mimalloc whenever its feature is on, so make release COMET_FEATURES=mimalloc and a plain cargo build --features mimalloc both get mimalloc while jemalloc stays a default feature. jni_api.rs reads jemalloc's stats only when jemalloc is the selected backend. The new selects_the_requested_allocator_backend test asserts the backend, and the rust-test action now lints and runs the alloc_accounting tests over the system allocator (--no-default-features --features hdfs-opendal,delta) and over mimalloc. The Makefile's jemalloc and mimalloc conflict check is removed, since that combination now resolves to mimalloc.
|
|
||
| The jars with the `jemalloc` classifier are built for 4 KiB memory pages and fail on arm64 kernels that use | ||
| 64 KiB pages, such as the kernel of RHEL 8. On those machines, use the jar with the system allocator or | ||
| The jars use the jemalloc allocator, built for 4 KiB memory pages, and fail on arm64 kernels that |
There was a problem hiding this comment.
Since the default jar now ships the statically linked jemalloc library, can we include its copyright, conditions, and disclaimer in dev/licenses/LICENSE-binary.txt? Clause 2 covers binary redistribution. Maven packages that file as META-INF/LICENSE, and it currently has no jemalloc entry. The existing jar contents check could cover it alongside zstd.
There was a problem hiding this comment.
Done in 0692e4d. LICENSE-binary.txt now has jemalloc 5.3.0's copyright notices, conditions and disclaimer. tikv-jemalloc-sys 0.6.1 vendors 5.3.0 plus one build-script commit, and its COPYING matches the one at 5.3.0. ensure-jars-have-correct-contents.sh reads the vendored version from tikv-jemalloc-sys in Cargo.lock and fails if the LICENSE names another one. test-jar-contents.py covers version drift, an unreadable version and a missing copyright line.
Add jemalloc to the default Cargo features of native/core, so cargo builds, the make targets, CI and the release builds use jemalloc. An explicit mimalloc request now wins over the default jemalloc. The release builds one native library per architecture, with the jemalloc page size pinned to 4 KiB, and publishes one jar per Spark and Scala combination. The unreleased jemalloc classifier jar and jemalloc Maven profile are removed. The binary LICENSE includes jemalloc, and the jar contents check verifies it. Document jemalloc as the default, why, and how to build with the system allocator.
8c58b66 to
0692e4d
Compare
|
LGTM. Thanks @comphead for addressing the release script, mimalloc and license feedback. |
Which issue does this PR close?
Part of #7344.
Rationale for this change
The native library allocates its Rust memory with the system allocator, which is glibc malloc on
Linux. In long-running executors glibc keeps freed memory resident, and executors get OOM-killed
while Comet's pool and allocation counter stay under the limit
(#7108). In
#7344 (comment), building with the
jemallocfeature halved the smallest clean pod size for TPC-H q18 at SF1000, and cut the peakanonymous memory at 20 GiB from 18.5 GiB to 10.4 GiB.
What changes are included in this PR?
native/core/Cargo.toml:jemallocjoins the default features, socargo build, themaketargets, CI and the release builds use jemalloc. A build with
--no-default-features --features hdfs-opendal,deltakeeps the system allocator.native/core/src/lib.rs: an explicitmimallocrequest now wins over the default jemalloc.Before, the two together selected the system allocator.
jni_api.rsreads jemalloc's stats onlywhen jemalloc is the selected backend, and a new test asserts the selected backend.
JEMALLOC_SYS_WITH_LG_PAGE=12set first, and each Spark and Scala combination publishes one jar. The
jemallocclassifier jarand the
jemallocMaven profile are removed. Neither has been released. The snapshot workflowpins the page size too. Users on arm64 kernels with 64 KiB pages, such as RHEL 8, need to build
from source, as the FAQ says.
rust-teststep that covered jemalloc now lints and tests the system allocator andmimalloc.
dev/licenses/LICENSE-binary.txtincludes jemalloc's license, and the jar contents checkverifies it against the version
tikv-jemalloc-sysvendors.source.mdsays that Comet uses jemalloc by default and why, and shows how to build withthe system allocator. The FAQ, the memory tuning guide,
release_process.md,tracing.mdandmemory_management.mdfollow.How are these changes tested?
selects_the_requested_allocator_backendasserts the selected backend. CI runs it over jemalloc,the system allocator and mimalloc.
dev/ci/test-jar-contents.pycovers the jemalloc LICENSE check: version drift, an unreadableversion and a missing copyright line.
cargo clippy --all-targets -- -D warningsfor the three allocator configurations,cargo fmt, prettier, actionlint,check-ci-config.py,bash -non the release scripts, andthe release script's jar check against stand-in jars. The Docker release build and a snapshot
dry run were not run.