Skip to content

Use jemalloc as global allocator on unix#2252

Open
briangmilnes wants to merge 1 commit into
verus-lang:mainfrom
briangmilnes:jemalloc-global-allocator
Open

Use jemalloc as global allocator on unix#2252
briangmilnes wants to merge 1 commit into
verus-lang:mainfrom
briangmilnes:jemalloc-global-allocator

Conversation

@briangmilnes
Copy link
Copy Markdown

Summary

  • On Linux, switching from glibc malloc to jemalloc saves avg 12%, peak 14% RSS
    and avg 9%, peak 14% wall time across 6 open-source Verus projects, with zero
    code changes
  • cfg(unix) gated — no effect on Windows builds
  • unprefixed_malloc_on_supported_platforms feature ensures jemalloc replaces
    C-level malloc/free globally, not just Rust's allocator (required because
    librustc_driver.so uses C malloc via LLVM)

Benchmark results

# Project Verified glibc MB jemal MB RSS Δ glibc s jemal s Time Δ
1 human-eval 292 614 537 -13% 5.4s 5.1s -4%
2 ironkv 319 783 706 -10% 5.4s 5.1s -5%
3 node-replication 254 957 854 -11% 6.5s 5.5s -14%
4 vest 496 648 565 -13% 5.7s 5.2s -9%
5 memory-allocator 731 1,629 1,416 -13% 38.7s 35.2s -9%
6 APAS-VERUS 4,265 5,822 5,143 -12% 59.2s 53.2s -10%
Peak -14% -14%
Average -12% -9%

macOS is not yet benchmarked. jemalloc is not available on Windows.

Full analysis: https://github.com/briangmilnes/verus-heaptrack

Test plan

  • vargo build --release succeeds, vstd rebuilds clean (1490 verified)
  • vargo test --package rust_verify_test — 3928 passed, 0 failed
  • Verified 6 open-source Verus projects with jemalloc-built binary

On Linux, switching from glibc malloc to jemalloc saves avg 12%, peak 14%
RSS and avg 9%, peak 14% wall time across 6 open-source Verus projects,
with zero code changes. macOS is not yet benchmarked. jemalloc is not
available on Windows.

The `unprefixed_malloc_on_supported_platforms` feature is required so that
jemalloc replaces C-level malloc/free globally, not just Rust's allocator.
Without it, librustc_driver.so (which uses C malloc via LLVM) fights with
jemalloc over the heap, causing corruption during vstd build.

Benchmarks and analysis: https://github.com/briangmilnes/verus-heaptrack

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@briangmilnes
Copy link
Copy Markdown
Author

Double checked the build and the benchmarks looking for any crashes, and it's clean.

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.

1 participant