Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alloc: add force-jemalloc-macos feature #27041

Closed
wants to merge 1 commit into from

Conversation

guswynn
Copy link
Contributor

@guswynn guswynn commented May 10, 2024

Some experiments I am doing would be easier if I could turn on jemalloc stats on macos. Heap profiling doesn't work, but it appears relatively stable.

@benesch unfortunately I couldn't figure out a way to not build tikv-jemallocator if force-jemalloc-macos is off. I don't think you can AND feature and platform's in target.cfg() clauses, so the cost of this is macos users have to build tikv-jemallocator once. One way around this is turning off jemalloc by default in bin/environmentd and adding --features jemalloc for linux users, but that seemed not worth it, because it would also mean we'd have to explicitly enable it everywhere else we build materialize.

context: https://materializeinc.slack.com/archives/C0246GEHL8N/p1715300698582579

Motivation

  • This PR adds a known-desirable feature.

Checklist

@guswynn guswynn requested a review from a team as a code owner May 10, 2024 22:09
@guswynn guswynn requested review from a team May 10, 2024 22:09
@guswynn guswynn requested a review from benesch as a code owner May 10, 2024 22:09
@guswynn guswynn requested a review from ParkMyCar May 10, 2024 22:09
@guswynn guswynn force-pushed the force-jemalloc-macos branch from 58dc8d9 to 3d68e74 Compare May 10, 2024 22:19
@guswynn guswynn requested a review from a team as a code owner May 10, 2024 22:19
@guswynn guswynn force-pushed the force-jemalloc-macos branch from 3d68e74 to 757a2d0 Compare May 10, 2024 23:34
Copy link
Member

@ParkMyCar ParkMyCar left a comment

Choose a reason for hiding this comment

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

To fix the problem of building tikv_jemallocator on macOS could you do [target.'cfg(...).features]`? e.g. something like:

[target.'cfg(not(target_os = "macos"))'.features]
default = ["jemalloc", "workspace-hack"]
jemalloc = ["tikv-jemallocator", "mz-prof/jemalloc", "mz-prof-http/jemalloc"]

[target.'cfg(target_os = "macos")'.features]
default = ["workspace-hack"]
jemalloc = ["tikv-jemallocator"]

approving to clear the block if its needed!

@benesch
Copy link
Member

benesch commented May 13, 2024

Let me ponder this one today. I'd love to find a way to do this that doesn't require introducing another Cargo feature. (Although I know Cargo makes that hard with its lack of support for target-specific features.)

@guswynn
Copy link
Contributor Author

guswynn commented May 13, 2024

@benesch yes I'll wait! I couldn't come up with anything, but let me know!

@ParkMyCar I don't think cargo allows that!

benesch added a commit to benesch/materialize that referenced this pull request May 13, 2024
Twiddle our crates and Cargo configuration for activating jemalloc to
achieve the following ideal developer experience:

  * --no-default-features unequivocally disables jemalloc, regardless of
    platform.
  * --features=jemalloc unequivocally enables jemalloc, regardless of
    platform.
  * --default-features chooses the best allocator for the platform: the
    system allocator on macOS and jemalloc on Linux.

Since Cargo doesn't explicitly support target-specific features, the
trick is to introduce a crate of indirection, as described in [0].
Here's how it works:

  * The `mz-prof`, `mz-prof-http`, and `mz-alloc` crates have a
    straightforward setup: they expose a `jemalloc` feature and
    conditionally enable or disable jemalloc features based on whether
    the `jemalloc` feature is provided or not.

  * The `mz-alloc-default` crate depends on the `mz-alloc` crate and
    enables the best features for the platform: `jemalloc` on Linux, and
    no additional features on macOS. You can think of this crate as
    unconditionally enabling the best allocator for the platform.

  * The `mz-environmentd` and `mz-clusterd` crates unlock the
    conditional behavior. Bothc crates:
      1. depend on `mz-alloc-default` by default, and
      2. expose a `jemalloc` feature that force enables the
         `mz-alloc/jemalloc` feature.

The motivation for all of this is to allow macOS developers to enable
jemalloc upon request, which is useful for certain kinds of testing.

Alternative to MaterializeInc#27041.
Closes MaterializeInc#27041.

[0]: rust-lang/cargo#1197 (comment)
@benesch
Copy link
Member

benesch commented May 13, 2024

I put up #27067, which should address the issues here! AFAICT, it makes --features=jemalloc Just Work on macOS, while also ensuring that you never have to build jemalloc on any platform if jemalloc is disabled, either implicitly or explicitly.

@guswynn
Copy link
Contributor Author

guswynn commented May 13, 2024

@benesch your replacement pr looks good!

@guswynn guswynn closed this May 13, 2024
benesch added a commit to benesch/materialize that referenced this pull request May 13, 2024
Twiddle our crates and Cargo configuration for activating jemalloc to
achieve the following ideal developer experience:

  * --no-default-features unequivocally disables jemalloc, regardless of
    platform.
  * --features=jemalloc unequivocally enables jemalloc, regardless of
    platform.
  * --default-features chooses the best allocator for the platform: the
    system allocator on macOS and jemalloc on Linux.

Since Cargo doesn't explicitly support target-specific features, the
trick is to introduce a crate of indirection, as described in [0].
Here's how it works:

  * The `mz-prof`, `mz-prof-http`, and `mz-alloc` crates have a
    straightforward setup: they expose a `jemalloc` feature and
    conditionally enable or disable jemalloc features based on whether
    the `jemalloc` feature is provided or not.

  * The `mz-alloc-default` crate depends on the `mz-alloc` crate and
    enables the best features for the platform: `jemalloc` on Linux, and
    no additional features on macOS. You can think of this crate as
    unconditionally enabling the best allocator for the platform.

  * The `mz-environmentd` and `mz-clusterd` crates unlock the
    conditional behavior. Bothc crates:
      1. depend on `mz-alloc-default` by default, and
      2. expose a `jemalloc` feature that force enables the
         `mz-alloc/jemalloc` feature.

The motivation for all of this is to allow macOS developers to enable
jemalloc upon request, which is useful for certain kinds of testing.

Alternative to MaterializeInc#27041.
Closes MaterializeInc#27041.

[0]: rust-lang/cargo#1197 (comment)
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.

3 participants