Skip to content

Make it easier to set static options #15

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

Closed
heftig opened this issue Sep 14, 2021 · 4 comments · Fixed by #31
Closed

Make it easier to set static options #15

heftig opened this issue Sep 14, 2021 · 4 comments · Fixed by #31

Comments

@heftig
Copy link

heftig commented Sep 14, 2021

I've managed to provide static options to jemalloc in my application via this code:

#[no_mangle]
pub static mut malloc_conf: *const libc::c_char =
    b"background_thread:true,metadata_thp:auto\0".as_ptr() as _;

This isn't very nice, is quite unsafe though no unsafe is present, and is dependent on prefixing being disabled. It would be nice if the crate provided a way to set this string in a safe(r) way.

@BusyJay
Copy link
Member

BusyJay commented Sep 14, 2021

You can also set it up using environment variable JEMALLOC_SYS_WITH_MALLOC_CONF.

@seanlinsley
Copy link

In either case, how do you confirm that the settings are being used?

@seanlinsley
Copy link

Okay, I confirmed that it's reaching jemalloc by setting it to an invalid string and then getting <jemalloc>: Conf string ends with key at runtime.

Assuming you've already installed jemalloc at this point cargo clean -p jemalloc-sys is needed because the environment variable is only used when the crate is compiled. Then set the environment variable before the next compile. For example from tokio-rs/tokio#2479 (comment)

cargo clean -p jemalloc-sys
export JEMALLOC_SYS_WITH_MALLOC_CONF="background_thread:true,narenas:1,tcache:false,dirty_decay_ms:0,muzzy_decay_ms:0,abort_conf:true"
cargo build

@BusyJay
Copy link
Member

BusyJay commented Jun 6, 2022

cargo clean -p jemalloc-sys is needed because the environment variable is only used when the crate is compiled

Interesting. I think it should be a bug of jemalloc-sys's build script. It should hint cargo to watch the environment variable.

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 a pull request may close this issue.

3 participants