Skip to content

stalwart-mail: build against system jemalloc [second try]#411265

Merged
happysalada merged 2 commits intoNixOS:masterfrom
yuyuyureka:stalwart-rocksdb
May 31, 2025
Merged

stalwart-mail: build against system jemalloc [second try]#411265
happysalada merged 2 commits intoNixOS:masterfrom
yuyuyureka:stalwart-rocksdb

Conversation

@yuyuyureka
Copy link
Contributor

@yuyuyureka yuyuyureka commented May 27, 2025

The reason we want to build against our own prebuilt jemalloc is that we can centrally manage all the required parameters to build a working jemalloc for many different platforms (e.g. set a fixed max-supported pagesize instead of auto-detecting it) and also it's good practise to unvendor dependencies in distro packaging.
This has previously caused problems: #411146

Stalwart sets the Rust allocator to jemalloc via the jemallocator crate.
But rocksdb does not properly distinguish between pointers it has allocated itself, and pointers which were passed in and might be registered with a different allocator.

Thus, rocksdb with jemalloc can only work properly when the malloc library is globally overridden (as can be obtained by setting the unprefixed_malloc_on_supported_platforms feature of jemalloc-sys, as rust-rocksdb does), but because stalwart never enables the jemalloc feature of the rocksdb crate, this never happens.

I attached a patch to fix this by enabling the jemalloc feature of the rocksdb crate, which also required changing stalwart to the more maintained tikv-jemallocator to match what rust-rocksdb uses, since we can't have two crates attempting to link jemalloc at the same time.

I suggest doing this only on NixOS master/unstable, and implementing a less invasive workaround for the aarch64 pagesize issue on 25.05 stable.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • Nixpkgs 25.11 Release Notes (or backporting 24.11 and 25.05 Nixpkgs Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
  • NixOS 25.11 Release Notes (or backporting 24.11 and 25.05 NixOS Release notes)
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels May 27, 2025
@yuyuyureka yuyuyureka requested a review from provokateurin May 27, 2025 00:22
@yuyuyureka yuyuyureka mentioned this pull request May 27, 2025
3 tasks
@yuyuyureka
Copy link
Contributor Author

Also submitted the jemalloc changes upstream: stalwartlabs/stalwart#1577

@happysalada
Copy link
Contributor

Its good that you submitted this upstream. The maintainer is quite responsive, lets see at least what he says, if it was merged upstream it would be much simpler in nixpkgs.

@yuyuyureka
Copy link
Contributor Author

Sadly they don't want to accept my changes unless I sign a contract with them. If anyone wants to try their luck submitting the same changes under a CLA, I released them into the public domain.

Copy link
Member

Choose a reason for hiding this comment

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

I believe you should update the rocksdb in passthru with rocksdbJemalloc

@yuyuyureka yuyuyureka force-pushed the stalwart-rocksdb branch 2 times, most recently from b570d5e to 87bb56e Compare May 31, 2025 09:50
@ofborg ofborg bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label May 31, 2025
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label May 31, 2025
@yuyuyureka yuyuyureka requested a review from diogotcorreia May 31, 2025 10:30
@yuyuyureka
Copy link
Contributor Author

I changed this to a less invasive approach of enabling the nonprefixed feature using substituteInPlace.
Everyone, please review again :)

Copy link
Contributor

@happysalada happysalada left a comment

Choose a reason for hiding this comment

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

This is much simpler.

Let me know when its good to merge, i see you are pushing new commits.

@yuyuyureka
Copy link
Contributor Author

It's good to merge now

@happysalada happysalada merged commit 24b70d6 into NixOS:master May 31, 2025
15 of 18 checks passed
@yuyuyureka yuyuyureka deleted the stalwart-rocksdb branch June 1, 2025 07:59
diogotcorreia added a commit to diogotcorreia/nixpkgs that referenced this pull request Sep 2, 2025
Since NixOS#411265 and NixOS#412054 were merged at the same time, the test ended
up not waiting for port 80 after the service restart.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants