comphead opened a new pull request, #7835:
URL: https://github.com/apache/datafusion-comet/pull/7835

   ## Which issue does this PR close?
   
   Part of https://github.com/apache/datafusion-comet/issues/7344.
   
   ## Rationale for this change
   
   The native library allocates its Rust memory with the system allocator, 
which is glibc malloc on
   Linux. glibc keeps freed memory in its arenas, and long-running executors 
get OOM-killed while
   Comet's pool and allocation counter stay under the limit
   (https://github.com/apache/datafusion-comet/issues/7108). In
   
https://github.com/apache/datafusion-comet/issues/7344#issuecomment-6830733603, 
changing only the
   allocator to jemalloc halved the smallest clean pod size for TPC-H q18 at 
SF1000 (20 GiB to 10 GiB
   at 75% off-heap). It also cut the peak anonymous memory at 20 GiB from 18.5 
GiB to 10.4 GiB.
   
   https://github.com/apache/datafusion-comet/pull/7356 and
   https://github.com/apache/datafusion-comet/pull/7635 made jemalloc opt-in, 
through a Maven profile
   and a `jemalloc` classifier jar. Neither has been released yet, since both 
landed after
   `branch-1.2`. This PR makes jemalloc the default instead, so users get it 
without swapping jars,
   and CI tests the allocator that the published jar uses. The system allocator 
stays available as a
   classifier jar and a Maven profile.
   
   Known costs:
   
   - With plenty of memory, q18 ran 3% slower at 64 GiB and 5-20% slower at 
24-48 GiB with jemalloc
     
(https://github.com/apache/datafusion-comet/issues/7344#issuecomment-6840376052).
 These were
     single runs, so cost and noise are not separated yet.
   - The published jemalloc is built for 4 KiB pages, as 
https://github.com/apache/datafusion-comet/pull/7635 chose. On arm64 kernels 
with 64 KiB
     pages, such as RHEL 8, every allocation fails and the process aborts when 
the native library
     first allocates. Until now only users who picked the jemalloc jar could 
hit this. Those machines
     now need the `system-allocator` jar, and the user guide and FAQ say so.
   - jemalloc only replaces the allocator of the Rust code. zstd, the JVM and 
other native code in the
     executor still allocate through glibc.
   
   ## What changes are included in this PR?
   
   - `native/core/Cargo.toml`: `jemalloc` joins the default features, so `cargo 
build`, every `make`
     target, CI, snapshots and releases build with it.
   - `native/core/src/lib.rs`: `mimalloc` now takes precedence over `jemalloc`. 
Before, the two
     together selected the system allocator, which would have turned 
`COMET_FEATURES=mimalloc` into a
     system-allocator build. `jni_api.rs` reads jemalloc's stats only when 
jemalloc is the selected
     allocator.
   - `pom.xml`, `Makefile`: the `jemalloc` Maven profile becomes 
`system-allocator`. Cargo cannot turn
     off one default feature, so `make` maps the profile to
     `--no-default-features --features hdfs-opendal,delta`. It stops with an 
error if `COMET_FEATURES`
     also names `jemalloc` or `mimalloc`. A comment on `default` in 
`Cargo.toml` lists the places that
     repeat the default features.
   - Release scripts: the jemalloc jars are the artifacts, and the 
system-allocator jars are installed
     next to them with the `system-allocator` classifier, for example
     `comet-spark-spark4.1_2.13-1.3.0-system-allocator.jar`. The native build 
still pins
     `JEMALLOC_SYS_WITH_LG_PAGE=12`, and still fails if the two libraries are 
identical.
   - `publish_snapshot.yml`: sets `JEMALLOC_SYS_WITH_LG_PAGE=12`, as the 
release builder does.
     Snapshots still publish only the main jar, which now uses jemalloc.
   - `rust-test` action: the step that linted and tested `alloc_accounting` 
over jemalloc now does that
     over the system allocator, with the profile's features. The other steps 
now run over jemalloc.
   - `dev/licenses/LICENSE-binary.txt`: adds jemalloc's BSD-2-Clause license, 
since its binary clause
     requires the notice. `tikv-jemalloc-sys` 0.6.1 vendors jemalloc 5.3.0 plus 
one build-script
     revert, and its `COPYING` matches the one at 5.3.0. The `jemalloc` 
classifier jar from https://github.com/apache/datafusion-comet/pull/7635 was
     missing it too. The version check in 
`dev/ensure-jars-have-correct-contents.sh` does not cover
     jemalloc.
   - Docs: `source.md` (the section is now "Choosing the memory allocator"), 
`faq.md`,
     `release_process.md`, `tuning/memory.md`, `tracing.md` and 
`memory_management.md`.
   
   No config keys change. The public changes are the allocator of the published 
jar, the new
   `system-allocator` classifier and Maven profile, and the removal of the 
unreleased `jemalloc`
   profile and classifier.
   
   ## How are these changes tested?
   
   There are no new tests. CI's Rust and JVM suites now run over jemalloc, and 
the `rust-test` step
   keeps the system allocator covered.
   
   Checked locally on macOS arm64:
   
   - `cargo clippy --all-targets -- -D warnings` passes for the workspace 
defaults (jemalloc), for
     `-p datafusion-comet --no-default-features --features hdfs-opendal,delta`, 
and for
     `-p datafusion-comet --features mimalloc`. `cargo fmt --check` passes.
   - `cargo tree`: the system-allocator flags drop `tikv-jemalloc-sys` and keep 
`hdfs-opendal` and
     `delta`.
   - `make -n` prints the expected cargo flags with and without 
`-Psystem-allocator` (also when it
     comes from the environment, as in the release script) and with 
`COMET_FEATURES=mimalloc`. It
     errors on `-Psystem-allocator` with `COMET_FEATURES=mimalloc`.
   - `dev/ci/test-jar-contents.py`, `dev/ci/check-ci-config.py`, prettier, 
actionlint, and `bash -n`
     on both release scripts pass.
   
   Not run: the Docker release build, a snapshot dry run, and a 64 KiB-page 
kernel. The abort described
   above comes from reading jemalloc's `pages_boot()` and Rust's allocation 
error handler.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to