Skip to content

Conversation

@Kobzol
Copy link

@Kobzol Kobzol commented Mar 3, 2025

The jemalloc-sys crate currently does not respect the Make jobserver protocol, and hardcodes -j$NUM_JOBS Make jobs as set by Cargo.

Cargo recommends to use CARGO_MAKEFLAGS instead (https://doc.rust-lang.org/cargo/reference/environment-variables.html), to avoid oversubscribing CPU cores when building Jemalloc C++ code in parallel with other Rust crates.

Here is a small benchmark that I did on hyperqueue with and without jobserver protocol support on AMD Zen 3 with 8 cores enabled:

/pr/it/hyperqueue [main/u]$ hyperfine --warmup 1 --runs 2 --prepare "rm -rf target" "cargo build --release" "JEMALLOC_JOBSERVER=1 cargo build --release" "cargo build" "JEMALLOC_JOBSERVER=1 cargo build"
Benchmark 1: cargo build --release
  Time (mean ± σ):     57.620 s ±  0.010 s    [User: 334.019 s, System: 37.222 s]
  Range (min … max):   57.613 s … 57.626 s    2 runs
 
Benchmark 2: JEMALLOC_JOBSERVER=1 cargo build --release
  Time (mean ± σ):     56.969 s ±  0.017 s    [User: 324.140 s, System: 36.739 s]
  Range (min … max):   56.956 s … 56.981 s    2 runs
 
Benchmark 3: cargo build
  Time (mean ± σ):     45.410 s ±  0.056 s    [User: 193.525 s, System: 37.347 s]
  Range (min … max):   45.371 s … 45.450 s    2 runs
 
Benchmark 4: JEMALLOC_JOBSERVER=1 cargo build
  Time (mean ± σ):     44.039 s ±  0.011 s    [User: 194.451 s, System: 37.357 s]
  Range (min … max):   44.031 s … 44.046 s    2 runs

With jobserver protocol support, the compilation finishes 2-3% faster.

Signed-off-by: Jakub Beránek <[email protected]>
@Kobzol
Copy link
Author

Kobzol commented Mar 3, 2025

Added the signoff.

Copy link
Member

@BusyJay BusyJay left a comment

Choose a reason for hiding this comment

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

Thank you!

@BusyJay BusyJay merged commit 5c5a9f7 into tikv:main Jun 9, 2025
10 checks passed
@Kobzol Kobzol deleted the jobserver branch June 9, 2025 14:01
@reneleonhardt
Copy link

reneleonhardt commented Nov 15, 2025

MAKEFLAGS have not been sanitized, so the jobs fail.
-j and -jN and -j N have to be removed when --jobserver-fds is present.

MAKEFLAGS="-j --jobserver-fds=8,9"

#92 (comment)

│ │ running: cd "$SRC_DIR/src/rust/target/x86_64-unknown-linux-gnu/release/build/tikv-jemalloc-sys-cde55cd13423d9e3/out/build" && MAKEFLAGS=" -- OBJECTS=init.o SHLIB=polars.so -j --jobserver-fds=8,9 --jobserver-auth=8,9" "make"
│ │ make[1]: Entering directory '$SRC_DIR/src/rust/target/x86_64-unknown-linux-gnu/release/build/tikv-jemalloc-sys-cde55cd13423d9e3/out/build'
│ │ make[1]: Leaving directory '$SRC_DIR/src/rust/target/x86_64-unknown-linux-gnu/release/build/tikv-jemalloc-sys-cde55cd13423d9e3/out/build'
│ │ --- stderr
│ │ make[1]: *** No rule to make target '-j'. Stop.
│ │ thread 'main' (6599) panicked at $BUILD_PREFIX/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tikv-jemalloc-sys-0.6.1+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7/build.rs:411:9:
│ │ command did not execute successfully: cd "$SRC_DIR/src/rust/target/x86_64-unknown-linux-gnu/release/build/tikv-jemalloc-sys-cde55cd13423d9e3/out/build" && MAKEFLAGS=" -- OBJECTS=init.o SHLIB=polars.so -j --jobserver-fds=8,9 --jobserver-auth=8,9" "make"

@Kobzol
Copy link
Author

Kobzol commented Nov 24, 2025

Let's discuss in #92.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants