Expose more jemalloc configure options
This commit is contained in:
parent
8dede09346
commit
cb0e906dda
96
.travis.yml
96
.travis.yml
|
@ -6,69 +6,97 @@ services: docker
|
|||
matrix:
|
||||
include:
|
||||
# Linux
|
||||
- env: TARGET=aarch64-unknown-linux-gnu
|
||||
- env: TARGET=arm-unknown-linux-gnueabi
|
||||
- env: TARGET=arm-unknown-linux-musleabi
|
||||
- env: TARGET=armv7-unknown-linux-gnueabihf
|
||||
- env: TARGET=armv7-unknown-linux-musleabihf
|
||||
- env: TARGET=i586-unknown-linux-gnu
|
||||
- name: "aarch64-unknown-linux-gnu"
|
||||
env: TARGET=aarch64-unknown-linux-gnu
|
||||
- name: "arm-unknown-linux-gnueabi"
|
||||
env: TARGET=arm-unknown-linux-gnueabi
|
||||
- name: "arm-unknown-linux-musleabi"
|
||||
env: TARGET=arm-unknown-linux-musleabi
|
||||
- name: "armv7-unknown-linux-gnueabihf"
|
||||
env: TARGET=armv7-unknown-linux-gnueabihf
|
||||
- name: "armv7-unknown-linux-musleabihf"
|
||||
env: TARGET=armv7-unknown-linux-musleabihf
|
||||
- name: "i586-unknown-linux-gnu"
|
||||
env: TARGET=i586-unknown-linux-gnu
|
||||
addons: &gcc_multilib
|
||||
apt:
|
||||
packages:
|
||||
- gcc-multilib
|
||||
- env: TARGET=i686-unknown-linux-gnu
|
||||
- name: "i686-unknown-linux-gnu"
|
||||
env: TARGET=i686-unknown-linux-gnu
|
||||
addons: *gcc_multilib
|
||||
- env: TARGET=i686-unknown-linux-gnu
|
||||
- name: "i686-unknown-linux-gnu"
|
||||
env: TARGET=i686-unknown-linux-gnu
|
||||
addons: *gcc_multilib
|
||||
rust: beta
|
||||
- env: TARGET=i686-unknown-linux-musl
|
||||
- env: TARGET=mips-unknown-linux-gnu
|
||||
- env: TARGET=mips64-unknown-linux-gnuabi64
|
||||
- env: TARGET=mips64el-unknown-linux-gnuabi64
|
||||
- env: TARGET=mipsel-unknown-linux-gnu
|
||||
- env: TARGET=powerpc-unknown-linux-gnu
|
||||
- env: TARGET=powerpc64-unknown-linux-gnu
|
||||
- env: TARGET=powerpc64le-unknown-linux-gnu
|
||||
- env: TARGET=sparc64-unknown-linux-gnu
|
||||
- env: TARGET=x86_64-unknown-linux-gnu
|
||||
- env: TARGET=x86_64-unknown-linux-gnu
|
||||
- name: "i686-unknown-linux-musl"
|
||||
env: TARGET=i686-unknown-linux-musl
|
||||
- name: "mips-unknown-linux-gnu"
|
||||
env: TARGET=mips-unknown-linux-gnu
|
||||
- name: "mips64-unknown-linux-gnuabi64"
|
||||
env: TARGET=mips64-unknown-linux-gnuabi64
|
||||
- name: "mips64el-unknown-linux-gnuabi64"
|
||||
env: TARGET=mips64el-unknown-linux-gnuabi64
|
||||
- name: "mipsel-unknown-linux-gnu"
|
||||
env: TARGET=mipsel-unknown-linux-gnu
|
||||
- name: "powerpc-unknown-linux-gnu"
|
||||
env: TARGET=powerpc-unknown-linux-gnu
|
||||
- name: "powerpc64-unknown-linux-gnu"
|
||||
env: TARGET=powerpc64-unknown-linux-gnu
|
||||
- name: "powerpc64le-unknown-linux-gnu"
|
||||
env: TARGET=powerpc64le-unknown-linux-gnu
|
||||
- name: "sparc64-unknown-linux-gnu"
|
||||
env: TARGET=sparc64-unknown-linux-gnu
|
||||
- name: "x86_64-unknown-linux-gnu"
|
||||
env: TARGET=x86_64-unknown-linux-gnu
|
||||
- name: "x86_64-unknown-linux-gnu"
|
||||
env: TARGET=x86_64-unknown-linux-gnu
|
||||
rust: beta
|
||||
- env: TARGET=x86_64-unknown-linux-musl
|
||||
- name: "x86_64-unknown-linux-musl"
|
||||
env: TARGET=x86_64-unknown-linux-musl
|
||||
|
||||
# Android
|
||||
- env: TARGET=aarch64-linux-android
|
||||
- env: TARGET=arm-linux-androideabi
|
||||
- env: TARGET=armv7-linux-androideabi
|
||||
- env: TARGET=x86_64-linux-android
|
||||
- name: "aarch64-linux-android"
|
||||
env: TARGET=aarch64-linux-android
|
||||
- name: "arm-linux-androideabi"
|
||||
env: TARGET=arm-linux-androideabi
|
||||
- name: "armv7-linux-androideabi"
|
||||
env: TARGET=armv7-linux-androideabi
|
||||
- name: "x86_64-linux-android"
|
||||
env: TARGET=x86_64-linux-android
|
||||
|
||||
# OSX
|
||||
- env: TARGET=i686-apple-darwin
|
||||
- name: "i686-apple-darwin"
|
||||
env: TARGET=i686-apple-darwin
|
||||
os: osx
|
||||
osx_image: xcode9.2
|
||||
- env: TARGET=x86_64-apple-darwin
|
||||
- name: "x86_64-apple-darwin"
|
||||
env: TARGET=x86_64-apple-darwin
|
||||
os: osx
|
||||
osx_image: xcode9.2
|
||||
- env: TARGET=i686-apple-darwin
|
||||
- name: "i686-apple-darwin"
|
||||
env: TARGET=i686-apple-darwin
|
||||
os: osx
|
||||
osx_image: xcode9.2
|
||||
rust: beta
|
||||
- env: TARGET=x86_64-apple-darwin
|
||||
- name: "x86_64-apple-darwin"
|
||||
env: TARGET=x86_64-apple-darwin
|
||||
os: osx
|
||||
osx_image: xcode9.2
|
||||
rust: beta
|
||||
|
||||
- env: DOCUMENTATION
|
||||
- name: "Documentation"
|
||||
install: pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH
|
||||
script: cargo doc
|
||||
after_success:
|
||||
- travis-cargo --only nightly doc-upload
|
||||
|
||||
allow_failures:
|
||||
- env: TARGET=arm-linux-androideabi
|
||||
- env: TARGET=armv7-linux-androideabi
|
||||
- env: TARGET=arm-unknown-linux-musleabi
|
||||
- env: TARGET=armv7-unknown-linux-musleabihf
|
||||
- env: TARGET=sparc64-unknown-linux-gnu
|
||||
- name: "arm-linux-androideabi"
|
||||
- name: "armv7-linux-androideabi"
|
||||
- name: "arm-unknown-linux-musleabi"
|
||||
- name: "armv7-unknown-linux-musleabihf"
|
||||
- name: "sparc64-unknown-linux-gnu"
|
||||
|
||||
script: ci/run.sh
|
||||
env:
|
||||
|
|
25
README.md
25
README.md
|
@ -28,29 +28,10 @@ And that's it! Once you've defined this `static` then jemalloc will be used for
|
|||
all allocations requested by Rust code in the same program.
|
||||
|
||||
|
||||
# Feature flags
|
||||
# Features
|
||||
|
||||
This crate has some Cargo feature flags:
|
||||
|
||||
* `profiling`: configure `jemalloc` with `--enable-prof`.
|
||||
|
||||
* `stats`: configure `jemalloc` with `--enable-stats`.
|
||||
|
||||
* `debug`: configure `jemalloc` with `--enable-debug`.
|
||||
|
||||
* `bg_thread` (enabled by default): when disabled, configure `jemalloc` with
|
||||
`--with-malloc-conf=background_thread:false`.
|
||||
|
||||
* `unprefixed_malloc_on_supported_platforms`:
|
||||
when disabled, configure `jemalloc` with `--with-jemalloc-prefix=_rjem_`.
|
||||
Enabling this causes symbols like `malloc` to be emitted without a prefix,
|
||||
overriding the ones defined by libc.
|
||||
This usually causes C and C++ code linked in the same program to use `jemalloc` as well.
|
||||
|
||||
On some platforms prefixes are always used
|
||||
because unprefixing is known to cause segfaults due to allocator mismatches.
|
||||
|
||||
See [`jemalloc/INSTALL.md`](https://github.com/jemalloc/jemalloc/blob/dev/INSTALL.md#advanced-configuration).
|
||||
The `jemallocator` crate re-exports the [features of the `jemalloc-sys`
|
||||
dependency](https://github.com/alexcrichton/jemallocator/blob/master/jemalloc-sys/readme.md).
|
||||
|
||||
# License
|
||||
|
||||
|
|
|
@ -172,12 +172,43 @@ fn main() {
|
|||
cmd.arg("--with-lg-page=14");
|
||||
}
|
||||
|
||||
// collect malloc_conf string:
|
||||
let mut malloc_conf = String::new();
|
||||
|
||||
if disable_bg_thread {
|
||||
cmd.arg("--with-malloc-conf=background_thread:false");
|
||||
malloc_conf += "background_thread:false";
|
||||
}
|
||||
|
||||
let mut use_prefix =
|
||||
env::var_os("CARGO_FEATURE_UNPREFIXED_MALLOC_ON_SUPPORTED_PLATFORMS").is_none();
|
||||
if let Ok(malloc_conf_opts) = env::var("JEMALLOC_SYS_WITH_MALLOC_CONF") {
|
||||
if malloc_conf.is_empty() {
|
||||
malloc_conf += &malloc_conf_opts;
|
||||
} else {
|
||||
malloc_conf += &format!(",{}", malloc_conf_opts);
|
||||
}
|
||||
}
|
||||
|
||||
if !malloc_conf.is_empty() {
|
||||
cmd.arg(format!("--with-malloc-conf={}", malloc_conf));
|
||||
}
|
||||
|
||||
if let Ok(lg_page) = env::var("JEMALLOC_SYS_WITH_LG_PAGE") {
|
||||
cmd.arg(format!("--with-lg-page={}", lg_page));
|
||||
}
|
||||
|
||||
if let Ok(lg_hugepage) = env::var("JEMALLOC_SYS_WITH_LG_HUGEPAGE") {
|
||||
cmd.arg(format!("--with-lg-hugepage={}", lg_hugepage));
|
||||
}
|
||||
|
||||
if let Ok(lg_quantum) = env::var("JEMALLOC_SYS_WITH_LG_QUANTUM") {
|
||||
cmd.arg(format!("--with-lg-quantum={}", lg_quantum));
|
||||
}
|
||||
|
||||
if let Ok(lg_vaddr) = env::var("JEMALLOC_SYS_WITH_LG_VADDR") {
|
||||
cmd.arg(format!("--with-lg-vaddr={}", lg_vaddr));
|
||||
}
|
||||
|
||||
let mut use_prefix
|
||||
= env::var_os("CARGO_FEATURE_UNPREFIXED_MALLOC_ON_SUPPORTED_PLATFORMS").is_none();
|
||||
|
||||
// “it was found that the `realpath` function in libc would allocate with libc malloc
|
||||
// (not jemalloc malloc), and then the standard library would free with jemalloc free,
|
||||
|
@ -280,6 +311,7 @@ fn main() {
|
|||
} else if !target.contains("windows") {
|
||||
println!("cargo:rustc-link-lib=pthread");
|
||||
}
|
||||
println!("cargo:rerun-if-changed=jemalloc");
|
||||
}
|
||||
|
||||
fn run(cmd: &mut Command) {
|
||||
|
|
|
@ -14,25 +14,111 @@
|
|||
|
||||
**Current jemalloc version**: 5.1.
|
||||
|
||||
# Feature flags
|
||||
# Features
|
||||
|
||||
Most features correspond to `jemalloc` features - the reference is
|
||||
[`jemalloc/INSTALL.md`][jemalloc_install].
|
||||
|
||||
## Cargo features
|
||||
|
||||
This crate provides following cargo feature flags:
|
||||
|
||||
* `profiling`: configure `jemalloc` with `--enable-prof`.
|
||||
* `stats`: configure `jemalloc` with `--enable-stats`.
|
||||
* `debug`: configure `jemalloc` with `--enable-debug`.
|
||||
* `bg_thread` (enabled by default): when disabled, configure `jemalloc` with
|
||||
`--with-malloc-conf=background_thread:false`.
|
||||
* `unprefixed_malloc_on_supported_platforms`:
|
||||
when disabled, configure `jemalloc` with `--with-jemalloc-prefix=_rjem_`.
|
||||
Enabling this causes symbols like `malloc` to be emitted without a prefix,
|
||||
overriding the ones defined by libc.
|
||||
This usually causes C and C++ code linked in the same program to use `jemalloc` as well.
|
||||
* `profiling` (configure `jemalloc` with `--enable-prof`): Enable heap profiling
|
||||
and leak detection functionality. See jemalloc's "opt.prof" option
|
||||
documentation for usage details. When enabled, there are several approaches to
|
||||
backtracing, and the configure script chooses the first one in the following
|
||||
list that appears to function correctly:
|
||||
|
||||
On some platforms prefixes are always used
|
||||
because unprefixing is known to cause segfaults due to allocator mismatches.
|
||||
* `libunwind` (requires --enable-prof-libunwind)
|
||||
* `libgcc` (unless --disable-prof-libgcc)
|
||||
* `gcc intrinsics` (unless --disable-prof-gcc)
|
||||
|
||||
See [`jemalloc/INSTALL.md`](https://github.com/jemalloc/jemalloc/blob/dev/INSTALL.md#advanced-configuration).
|
||||
* `stats` (configure `jemalloc` with `--enable-stats`): Enable statistics
|
||||
gathering functionality. See the `jemalloc`'s "opt.stats_print" option documentation for
|
||||
usage details.
|
||||
|
||||
* `debug` (configure `jemalloc` with `--enable-debug`): Enable assertions and
|
||||
validation code. This incurs a substantial performance hit, but is very useful
|
||||
during application development.
|
||||
|
||||
* `bg_thread` (enabled by default - configure `jemalloc` with
|
||||
`--with-malloc-conf=background_thread:false`): When disabled, disable internal
|
||||
background worker threads. When set to true, background threads are created on
|
||||
demand (the number of background threads will be no more than the number of
|
||||
CPUs or active arenas). Threads run periodically, and handle purging
|
||||
asynchronously. When switching off, background threads are terminated
|
||||
synchronously. Note that after `fork(2)` function, the state in the child
|
||||
process will be disabled regardless the state in parent process. See
|
||||
`stats.background_thread` for related stats. `opt.background_thread` can be
|
||||
used to set the default option. The background thread is only available on
|
||||
selected pthread-based platforms.
|
||||
|
||||
* `unprefixed_malloc_on_supported_platforms`: when disabled, configure
|
||||
`jemalloc` with `--with-jemalloc-prefix=_rjem_`. Enabling this causes symbols
|
||||
like `malloc` to be emitted without a prefix, overriding the ones defined by
|
||||
libc. This usually causes C and C++ code linked in the same program to use
|
||||
`jemalloc` as well. On some platforms prefixes are always used because
|
||||
unprefixing is known to cause segfaults due to allocator mismatches.
|
||||
|
||||
## Environment variables
|
||||
|
||||
`jemalloc` options taking values are passed via environment variables using the
|
||||
schema `JEMALLOC_SYS_{KEY}=VALUE` where the `KEY` names correspond to the
|
||||
`./configure` options of `jemalloc` where the words are capitalized and the
|
||||
diphens `-` are replaced with underscores `_`(see
|
||||
[`jemalloc/INSTALL.md`][jemalloc_install]):
|
||||
|
||||
* `JEMALLOC_SYS_WITH_MALLOC_CONF=<malloc_conf>`: Embed `<malloc_conf>` as a
|
||||
run-time options string that is processed prior to the `malloc_conf` global
|
||||
variable, the `/etc/malloc.conf` symlink, and the `MALLOC_CONF` environment
|
||||
variable. For example, to change the default decay time to 30 seconds:
|
||||
|
||||
```
|
||||
JEMALLOC_SYS_WITH_MALLOC_CONF=decay_ms:30000
|
||||
```
|
||||
|
||||
* `JEMALLOC_SYS_WITH_LG_PAGE=<lg-page>`: Specify the base 2 log of the allocator
|
||||
page size, which must in turn be at least as large as the system page size. By
|
||||
default the configure script determines the host's page size and sets the
|
||||
allocator page size equal to the system page size, so this option need not be
|
||||
specified unless the system page size may change between configuration and
|
||||
execution, e.g. when cross compiling.
|
||||
|
||||
* `JEMALLOC_SYS_WITH_LG_HUGEPAGE=<lg-hugepage>`: Specify the base 2 log of the
|
||||
system huge page size. This option is useful when cross compiling, or when
|
||||
overriding the default for systems that do not explicitly support huge pages.
|
||||
|
||||
|
||||
* `JEMALLOC_SYS_WITH_LG_QUANTUM=<lg-quantum>`: Specify the base 2 log of the
|
||||
minimum allocation alignment. jemalloc needs to know the minimum alignment
|
||||
that meets the following C standard requirement (quoted from the April 12,
|
||||
2011 draft of the C11 standard):
|
||||
|
||||
> The pointer returned if the allocation succeeds is suitably aligned so that
|
||||
> it may be assigned to a pointer to any type of object with a fundamental
|
||||
> alignment requirement and then used to access such an object or an array of
|
||||
> such objects in the space allocated [...]
|
||||
|
||||
This setting is architecture-specific, and although jemalloc includes known
|
||||
safe values for the most commonly used modern architectures, there is a
|
||||
wrinkle related to GNU libc (glibc) that may impact your choice of . On most
|
||||
modern architectures, this mandates 16-byte alignment (=4), but the glibc
|
||||
developers chose not to meet this requirement for performance reasons. An old
|
||||
discussion can be found at https://sourceware.org/bugzilla/show_bug.cgi?id=206
|
||||
. Unlike glibc, jemalloc does follow the C standard by default (caveat:
|
||||
jemalloc technically cheats for size classes smaller than the quantum), but
|
||||
the fact that Linux systems already work around this allocator noncompliance
|
||||
means that it is generally safe in practice to let jemalloc's minimum
|
||||
alignment follow glibc's lead. If you specify `JEMALLOC_SYS_WITH_LG_QUANTUM=3`
|
||||
during configuration, jemalloc will provide additional size classes that are
|
||||
not 16-byte-aligned (24, 40, and 56).
|
||||
|
||||
* `JEMALLOC_SYS_WITH_LG_VADDR=<lg-vaddr>`: Specify the number of significant
|
||||
virtual address bits. By default, the configure script attempts to detect
|
||||
virtual address size on those platforms where it knows how, and picks a
|
||||
default otherwise. This option may be useful when cross-compiling.
|
||||
|
||||
[jemalloc_install]: https://github.com/jemalloc/jemalloc/blob/dev/INSTALL.md#advanced-configuration
|
||||
|
||||
# License
|
||||
|
||||
|
|
|
@ -525,7 +525,7 @@ extern "C" {
|
|||
/// completely up to date, since extra locking would be required to merge
|
||||
/// counters that track thread cache operations.
|
||||
#[cfg_attr(prefixed, link_name = "_rjem_malloc_stats_print")]
|
||||
pub fn malloc_stats_print(write_cb: extern "C" fn(*mut c_void, *const c_char),
|
||||
pub fn malloc_stats_print(write_cb: unsafe extern "C" fn(*mut c_void, *const c_char),
|
||||
cbopaque: *mut c_void,
|
||||
opts: *const c_char);
|
||||
|
||||
|
@ -539,9 +539,9 @@ extern "C" {
|
|||
///
|
||||
/// Please note that doing anything which tries to allocate memory in this
|
||||
/// function is likely to result in a crash or deadlock.
|
||||
#[no_mangle]
|
||||
pub static mut malloc_message: unsafe extern fn (cbopaque: *mut c_void,
|
||||
s: *const c_char);
|
||||
#[cfg_attr(prefixed, link_name = "_rjem_malloc_message")]
|
||||
pub static mut malloc_message: unsafe extern "C" fn (cbopaque: *mut c_void,
|
||||
s: *const c_char);
|
||||
}
|
||||
|
||||
/// Extent lifetime management functions.
|
||||
|
|
|
@ -9,4 +9,4 @@ jemalloc-sys = { path = "../jemalloc-sys" }
|
|||
libc = "0.2"
|
||||
|
||||
[build-dependencies]
|
||||
ctest = "0.2"
|
||||
ctest = "0.2"
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#![allow(bad_style, improper_ctypes, dead_code, unused_imports)]
|
||||
#![feature(global_allocator, allocator_api)]
|
||||
|
||||
extern crate jemalloc_sys;
|
||||
extern crate libc;
|
||||
|
@ -9,7 +8,7 @@ use std::alloc::System;
|
|||
#[global_allocator]
|
||||
static A: System = System;
|
||||
|
||||
use libc::{c_int};
|
||||
use libc::{c_int, c_void, c_char};
|
||||
use jemalloc_sys::*;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/all.rs"));
|
||||
|
|
Loading…
Reference in New Issue