update jemalloc to 5.3.0 (#23)

Signed-off-by: Jay Lee <BusyJayLee@gmail.com>
This commit is contained in:
Jay 2022-05-14 05:19:25 +08:00 committed by Jay Lee
parent 2706fb3874
commit ab0676d77e
No known key found for this signature in database
GPG Key ID: 71E4789CFC80BCFA
33 changed files with 2025 additions and 366 deletions

3
.gitmodules vendored
View File

@ -1,4 +1,3 @@
[submodule "jemalloc-sys/jemalloc"]
path = jemalloc-sys/jemalloc
url = https://github.com/tikv/jemalloc
branch = v5.2.x
url = https://github.com/jemalloc/jemalloc

View File

@ -1,59 +1,2 @@
[package]
name = "tikv-jemallocator"
# Make sure to update the version in the README as well:
version = "0.4.3"
authors = [
"Alex Crichton <alex@alexcrichton.com>",
"Gonzalo Brito Gadeschi <gonzalobg88@gmail.com>",
"Simon Sapin <simon.sapin@exyr.org>",
"Steven Fackler <sfackler@gmail.com>",
"The TiKV Project Developers",
]
license = "MIT/Apache-2.0"
readme = "README.md"
keywords = ["allocator", "jemalloc"]
categories = ["memory-management", "api-bindings"]
repository = "https://github.com/tikv/jemallocator"
homepage = "https://github.com/tikv/jemallocator"
documentation = "https://docs.rs/tikv-jemallocator"
description = """
A Rust allocator backed by jemalloc
"""
edition = "2018"
[badges]
travis-ci = { repository = "tikv/jemallocator" }
codecov = { repository = "tikv/jemallocator" }
is-it-maintained-issue-resolution = { repository = "tikv/jemallocator" }
is-it-maintained-open-issues = { repository = "tikv/jemallocator" }
maintenance = { status = "actively-developed" }
[lib]
test = false
bench = false
[workspace]
members = ["systest", "jemallocator-global", "jemalloc-ctl", "jemalloc-sys" ]
[dependencies]
tikv-jemalloc-sys = { path = "jemalloc-sys", version = "0.4.0", default-features = false }
libc = { version = "^0.2.8", default-features = false }
[dev-dependencies]
paste = "1"
tikv-jemalloc-ctl = { path = "jemalloc-ctl", version = "0.4" }
[features]
default = ["background_threads_runtime_support"]
alloc_trait = []
profiling = ["tikv-jemalloc-sys/profiling"]
debug = ["tikv-jemalloc-sys/debug"]
stats = ["tikv-jemalloc-sys/stats"]
background_threads_runtime_support = ["tikv-jemalloc-sys/background_threads_runtime_support"]
background_threads = ["tikv-jemalloc-sys/background_threads"]
unprefixed_malloc_on_supported_platforms = ["tikv-jemalloc-sys/unprefixed_malloc_on_supported_platforms"]
disable_initial_exec_tls = ["tikv-jemalloc-sys/disable_initial_exec_tls"]
[package.metadata.docs.rs]
features = []
rustdoc-args = [ "--cfg", "jemallocator_docs" ]
members = ["jemallocator", "jemallocator-global", "jemalloc-ctl", "jemalloc-sys"]

View File

@ -28,7 +28,7 @@ To use `tikv-jemallocator` add it as a dependency:
[dependencies]
[target.'cfg(not(target_env = "msvc"))'.dependencies]
tikv-jemallocator = "0.4.0"
tikv-jemallocator = "0.4.3"
```
To set `tikv_jemallocator::Jemalloc` as the global allocator add this to your project:

View File

@ -66,10 +66,6 @@ case "${TARGET}" in
;;
esac
if rustc --version | grep -v nightly >/dev/null; then
# systest can't be built on nightly
cargo test --target "${TARGET}" -p systest
fi
cargo test --target "${TARGET}" --manifest-path jemallocator-global/Cargo.toml
cargo test --target "${TARGET}" \
--manifest-path jemallocator-global/Cargo.toml \

View File

@ -1,6 +1,6 @@
[package]
name = "tikv-jemalloc-ctl"
version = "0.4.2"
version = "0.4.3"
authors = [
"Steven Fackler <sfackler@gmail.com>",
"Gonzalo Brito Gadeschi <gonzalobg88@gmail.com>",
@ -31,7 +31,7 @@ libc = { version = "0.2", default-features = false }
paste = "1"
[dev-dependencies]
tikv-jemallocator = { path = "..", version = "0.4.0" }
tikv-jemallocator = { path = "../jemallocator", version = "0.4.0" }
[features]
default = []

View File

@ -169,8 +169,8 @@ option! {
/// use tikv_jemalloc_ctl::max_background_threads;
/// let m = max_background_threads::mib().unwrap();
/// println!("max_background_threads: {}", m.read().unwrap());
/// m.write(0).unwrap();
/// assert_eq!(m.read().unwrap(), 0);
/// m.write(2).unwrap();
/// assert_eq!(m.read().unwrap(), 2);
/// #
/// # } // #[cfg(..)]
/// # }

View File

@ -26,7 +26,7 @@ macro_rules! types {
Ok([<$id _mib>](Self::NAME.$name_to_mib()?))
}
/// Key [`::keys::Name`].
/// Key [`crate::keys::Name`].
pub fn name() -> &'static crate::keys::Name {
Self::NAME
}

View File

@ -166,7 +166,7 @@ option! {
}
option! {
lg_tcache_max[ str: b"opt.lg_tcache_max\0", non_str: 2 ] => libc::size_t |
tcache_max[ str: b"opt.tcache_max\0", non_str: 2 ] => libc::size_t |
ops: r |
docs:
/// Maximum size class (log base 2) to cache in the thread-specific cache
@ -183,11 +183,11 @@ option! {
/// #
/// # fn main() {
/// use tikv_jemalloc_ctl::opt;
/// let lg_tcache_max = opt::lg_tcache_max::read().unwrap();
/// println!("max cached allocation size: {}", 1 << lg_tcache_max);
/// let tcache_max = opt::tcache_max::read().unwrap();
/// println!("max cached allocation size: {}", tcache_max);
/// # }
/// ```
mib_docs: /// See [`lg_tcache_max`].
mib_docs: /// See [`tcache_max`].
}
option! {

View File

@ -1,7 +1,7 @@
//! Global allocator statistics.
//!
//! `jemalloc` tracks a wide variety of statistics. Many of them are cached, and
//! only refreshed when the `jemalloc` "epoch" is advanced. See the [`::epoch`] type
//! only refreshed when the `jemalloc` "epoch" is advanced. See the [`crate::epoch`] type
//! for more information.
option! {
@ -11,7 +11,7 @@ option! {
/// Total number of bytes allocated by the application.
///
/// This statistic is cached, and is only refreshed when the epoch is
/// advanced. See the [`::epoch`] type for more information.
/// advanced. See the [`crate::epoch`] type for more information.
///
/// This corresponds to `stats.allocated` in jemalloc's API.
///
@ -46,7 +46,7 @@ option! {
/// value returned by [`allocated`].
///
/// This statistic is cached, and is only refreshed when the epoch is
/// advanced. See the [`::epoch`] type for more information.
/// advanced. See the [`crate::epoch`] type for more information.
///
/// This corresponds to `stats.active` in jemalloc's API.
///
@ -78,7 +78,7 @@ option! {
/// Total number of bytes dedicated to `jemalloc` metadata.
///
/// This statistic is cached, and is only refreshed when the epoch is
/// advanced. See the [`::epoch`] type for more information.
/// advanced. See the [`crate::epoch`] type for more information.
///
/// This corresponds to `stats.metadata` in jemalloc's API.
///
@ -116,7 +116,7 @@ option! {
/// value returned by [`active`].
///
/// This statistic is cached, and is only refreshed when the epoch is
/// advanced. See the [`::epoch`] type for more information.
/// advanced. See the [`crate::epoch`] type for more information.
///
/// This corresponds to `stats.resident` in jemalloc's API.
///
@ -151,7 +151,7 @@ option! {
/// larger than the value returned by [`active`].
///
/// This statistic is cached, and is only refreshed when the epoch is
/// advanced. See the [`::epoch`] type for more information.
/// advanced. See the [`crate::epoch`] type for more information.
///
/// This corresponds to `stats.mapped` in jemalloc's API.
///
@ -186,7 +186,7 @@ option! {
/// excluded from mapped memory statistics, e.g. [`mapped`].
///
/// This statistic is cached, and is only refreshed when the epoch is
/// advanced. See the [`::epoch`] type for more information.
/// advanced. See the [`crate::epoch`] type for more information.
///
/// This corresponds to `stats.retained` in jemalloc's API.
///

View File

@ -9,7 +9,7 @@ option! {
docs:
/// Access to the total number of bytes allocated by the current thread.
///
/// Unlike [`::stats::allocated`], the value returned by this type is not the
/// Unlike [`crate::stats::allocated`], the value returned by this type is not the
/// number of bytes *currently* allocated, but rather the number of bytes
/// that have *ever* been allocated by this thread.
///

View File

@ -1,6 +1,6 @@
[package]
name = "tikv-jemalloc-sys"
version = "0.4.3+5.2.1-patched.2"
version = "0.4.3+5.3.0"
authors = [
"Alex Crichton <alex@alexcrichton.com>",
"Gonzalo Brito Gadeschi <gonzalobg88@gmail.com>",
@ -20,16 +20,11 @@ Rust FFI bindings to jemalloc
edition = "2018"
[badges]
travis-ci = { repository = "tikv/jemallocator" }
codecov = { repository = "tikv/jemallocator" }
is-it-maintained-issue-resolution = { repository = "tikv/jemallocator" }
is-it-maintained-open-issues = { repository = "tikv/jemallocator" }
maintenance = { status = "actively-developed" }
[lib]
test = false
bench = false
[dependencies]
libc = { version = "^0.2.8", default-features = false }

View File

@ -13,32 +13,7 @@ use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;
// `jemalloc` is known not to work on these targets:
const UNSUPPORTED_TARGETS: &[&str] = &[
"rumprun",
"bitrig",
"emscripten",
"fuchsia",
"redox",
"wasm32",
];
// `jemalloc-sys` is not tested on these targets in CI:
const UNTESTED_TARGETS: &[&str] = &["openbsd", "msvc"];
// `jemalloc`'s background_thread support is known not to work on these targets:
const NO_BG_THREAD_TARGETS: &[&str] = &["musl"];
// targets that don't support unprefixed `malloc`
//
// “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,
// causing a segfault.”
// https://github.com/rust-lang/rust/commit/e3b414d8612314e74e2b0ebde1ed5c6997d28e8d
// https://github.com/rust-lang/rust/commit/536011d929ecbd1170baf34e09580e567c971f95
// https://github.com/rust-lang/rust/commit/9f3de647326fbe50e0e283b9018ab7c41abccde3
// https://github.com/rust-lang/rust/commit/ed015456a114ae907a36af80c06f81ea93182a24
const NO_UNPREFIXED_MALLOC: &[&str] = &["android", "dragonfly", "musl", "darwin"];
include!("src/env.rs");
macro_rules! info {
($($args:tt)*) => { println!($($args)*) }
@ -78,7 +53,11 @@ fn main() {
let mut use_prefix =
env::var("CARGO_FEATURE_UNPREFIXED_MALLOC_ON_SUPPORTED_PLATFORMS").is_err();
if !use_prefix && NO_UNPREFIXED_MALLOC.iter().any(|i| target.contains(i)) {
if !use_prefix
&& NO_UNPREFIXED_MALLOC_TARGETS
.iter()
.any(|i| target.contains(i))
{
warning!(
"Unprefixed `malloc` requested on unsupported platform `{}` => using prefixed `malloc`",
target
@ -164,7 +143,9 @@ fn main() {
.env("CFLAGS", cflags.clone())
.env("LDFLAGS", cflags.clone())
.env("CPPFLAGS", cflags)
.arg("--disable-cxx");
.arg("--disable-cxx")
.arg("--enable-doc=no")
.arg("--enable-shared=no");
if target.contains("ios") {
// newer iOS deviced have 16kb page sizes:
@ -307,7 +288,7 @@ fn main() {
if target.contains("android") {
println!("cargo:rustc-link-lib=gcc");
} else if !target.contains("windows") {
println!("cargo:rustc-link-lib=pthread");
println!("cargo:rustc-link-arg=-pthread");
}
// GCC may generate a __atomic_exchange_1 library call which requires -latomic
// during the final linking. https://github.com/riscv-collab/riscv-gcc/issues/12

View File

@ -1 +1 @@
5.2.1-2-g172143a2979d9d948035423ce347e35cd1388fc3
5.3.0-0-g54eaed1d8b56b1aa528be3bdd1877e59c56fa90c

File diff suppressed because it is too large Load Diff

@ -1 +1 @@
Subproject commit 172143a2979d9d948035423ce347e35cd1388fc3
Subproject commit 54eaed1d8b56b1aa528be3bdd1877e59c56fa90c

25
jemalloc-sys/src/env.rs Normal file
View File

@ -0,0 +1,25 @@
/// `jemalloc` is known not to work on these targets:
pub static UNSUPPORTED_TARGETS: &[&str] = &[
"rumprun",
"bitrig",
"emscripten",
"fuchsia",
"redox",
"wasm32",
];
/// `jemalloc-sys` is not tested on these targets in CI:
pub static UNTESTED_TARGETS: &[&str] = &["openbsd", "msvc"];
/// `jemalloc`'s background_thread support is known not to work on these targets:
pub static NO_BG_THREAD_TARGETS: &[&str] = &["musl"];
/// targets that don't support unprefixed `malloc`
// “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,
// causing a segfault.”
// https://github.com/rust-lang/rust/commit/e3b414d8612314e74e2b0ebde1ed5c6997d28e8d
// https://github.com/rust-lang/rust/commit/536011d929ecbd1170baf34e09580e567c971f95
// https://github.com/rust-lang/rust/commit/9f3de647326fbe50e0e283b9018ab7c41abccde3
// https://github.com/rust-lang/rust/commit/ed015456a114ae907a36af80c06f81ea93182a24
pub static NO_UNPREFIXED_MALLOC_TARGETS: &[&str] = &["android", "dragonfly", "musl", "darwin"];

View File

@ -59,7 +59,7 @@ type c_bool = c_int;
///
/// It does not validate that `la` is within the valid range.
#[inline]
pub fn MALLOCX_LG_ALIGN(la: usize) -> c_int {
pub const fn MALLOCX_LG_ALIGN(la: usize) -> c_int {
la as c_int
}
@ -70,7 +70,7 @@ pub fn MALLOCX_LG_ALIGN(la: usize) -> c_int {
///
/// This macro does not validate that a is a power of 2.
#[inline]
pub fn MALLOCX_ALIGN(aling: usize) -> c_int {
pub const fn MALLOCX_ALIGN(aling: usize) -> c_int {
aling.trailing_zeros() as c_int
}
@ -90,7 +90,7 @@ pub const MALLOCX_ZERO: c_int = 0x40;
/// `tc` must have been acquired via the `tcache.create mallctl`. This function
/// does not validate that `tc` specifies a valid identifier.
#[inline]
pub fn MALLOCX_TCACHE(tc: usize) -> c_int {
pub const fn MALLOCX_TCACHE(tc: usize) -> c_int {
tc.wrapping_add(2).wrapping_shl(8) as c_int
}
@ -104,10 +104,7 @@ pub fn MALLOCX_TCACHE(tc: usize) -> c_int {
/// This option cannot be used in the same `flags` argument as
/// `MALLOCX_TCACHE(tc)`.
// FIXME: This should just be a const.
#[inline]
pub fn MALLOCX_TCACHE_NONE() -> c_int {
MALLOCX_TCACHE(!0)
}
pub const MALLOCX_TCACHE_NONE: c_int = MALLOCX_TCACHE((-1isize) as usize);
/// Use the arena specified by the index `a`.
///
@ -119,7 +116,7 @@ pub fn MALLOCX_TCACHE_NONE() -> c_int {
/// This function does not validate that `a` specifies an arena index in the
/// valid range.
#[inline]
pub fn MALLOCX_ARENA(a: usize) -> c_int {
pub const fn MALLOCX_ARENA(a: usize) -> c_int {
(a as c_int).wrapping_add(1).wrapping_shl(20)
}
@ -899,3 +896,8 @@ pub extern "C" fn pthread_atfork(
) -> i32 {
0
}
#[allow(missing_docs)]
mod env;
pub use env::*;

View File

@ -1,7 +1,7 @@
[package]
name = "tikv-jemallocator-global"
# Make sure to update the version in the readme as well:
version = "0.4.0"
version = "0.4.3"
authors = [
"Gonzalo Brito Gadeschi <gonzalobg88@gmail.com>",
"The TiKV Project Developers",
@ -26,7 +26,7 @@ is-it-maintained-open-issues = { repository = "tikv/jemallocator" }
maintenance = { status = "actively-developed" }
[dependencies]
tikv-jemallocator = { version = "0.4.0", path = "..", optional = true }
tikv-jemallocator = { version = "0.4.0", path = "../jemallocator", optional = true }
cfg-if = "0.1"
[features]
@ -38,11 +38,11 @@ force_global_jemalloc = [ "tikv-jemallocator" ]
# for a particular target, white-list the target explicitly here:
[target.'cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))'.dependencies]
tikv-jemallocator = { version = "0.4.0", path = "..", optional = false }
tikv-jemallocator = { version = "0.4.0", path = "../jemallocator", optional = false }
# FIXME: https://github.com/gnzlbg/jemallocator/issues/91
# [target.'cfg(target_os = "windows")'.dependencies]
# jemallocator = { path = ".." }
# jemallocator = { path = "../jemallocator" }
# `jemalloc` is known not to work on - see `jemalloc-sys/build.rs`.
# - rumprun

56
jemallocator/Cargo.toml Normal file
View File

@ -0,0 +1,56 @@
[package]
name = "tikv-jemallocator"
# Make sure to update the version in the README as well:
version = "0.4.3"
authors = [
"Alex Crichton <alex@alexcrichton.com>",
"Gonzalo Brito Gadeschi <gonzalobg88@gmail.com>",
"Simon Sapin <simon.sapin@exyr.org>",
"Steven Fackler <sfackler@gmail.com>",
"The TiKV Project Developers",
]
license = "MIT/Apache-2.0"
readme = "README.md"
keywords = ["allocator", "jemalloc"]
categories = ["memory-management", "api-bindings"]
repository = "https://github.com/tikv/jemallocator"
homepage = "https://github.com/tikv/jemallocator"
documentation = "https://docs.rs/jemallocator"
description = """
A Rust allocator backed by jemalloc
"""
edition = "2018"
[badges]
travis-ci = { repository = "tikv/jemallocator" }
codecov = { repository = "tikv/jemallocator" }
is-it-maintained-issue-resolution = { repository = "tikv/jemallocator" }
is-it-maintained-open-issues = { repository = "tikv/jemallocator" }
maintenance = { status = "actively-developed" }
[lib]
test = false
bench = false
[dependencies]
tikv-jemalloc-sys = { path = "../jemalloc-sys", version = "0.4.0", default-features = false }
libc = { version = "^0.2.8", default-features = false }
[dev-dependencies]
paste = "1"
tikv-jemalloc-ctl = { path = "../jemalloc-ctl", version = "0.4.0" }
[features]
default = ["background_threads_runtime_support"]
alloc_trait = []
profiling = ["tikv-jemalloc-sys/profiling"]
debug = ["tikv-jemalloc-sys/debug"]
stats = ["tikv-jemalloc-sys/stats"]
background_threads_runtime_support = ["tikv-jemalloc-sys/background_threads_runtime_support"]
background_threads = ["tikv-jemalloc-sys/background_threads"]
unprefixed_malloc_on_supported_platforms = ["tikv-jemalloc-sys/unprefixed_malloc_on_supported_platforms"]
disable_initial_exec_tls = ["tikv-jemalloc-sys/disable_initial_exec_tls"]
[package.metadata.docs.rs]
features = []
rustdoc-args = [ "--cfg", "jemallocator_docs" ]

View File

@ -1,13 +0,0 @@
[package]
name = "systest"
version = "0.1.0"
authors = ["Alex Crichton <alex@alexcrichton.com>"]
build = "build.rs"
edition = "2018"
[dependencies]
tikv-jemalloc-sys = { path = "../jemalloc-sys" }
libc = "0.2"
[build-dependencies]
ctest = "0.2.22"

View File

@ -1,32 +0,0 @@
use std::env;
use std::path::PathBuf;
const FUNCTION_POINTER: &[&str] = &[
"extent_alloc_t",
"extent_dalloc_t",
"extent_destroy_t",
"extent_commit_t",
"extent_decommit_t",
"extent_purge_t",
"extent_split_t",
"extent_merge_t",
];
fn main() {
let root = PathBuf::from(env::var_os("DEP_JEMALLOC_ROOT").unwrap());
let mut cfg = ctest::TestGenerator::new();
cfg.header("jemalloc/jemalloc.h")
.include(root.join("include"))
.cfg("prefixed", None)
.fn_cname(|rust, link_name| link_name.unwrap_or(rust).to_string())
.skip_signededness(|c| c.ends_with("_t"))
// No need to test pure C function pointer.
.skip_type(|name| FUNCTION_POINTER.contains(&name));
if cfg!(target_os = "linux") {
cfg.skip_fn(|f| f == "malloc_usable_size");
}
cfg.generate("../jemalloc-sys/src/lib.rs", "all.rs");
}

View File

@ -1,13 +0,0 @@
// TODO: remove systest
#![allow(bad_style, improper_ctypes, dead_code, unused_imports, deref_nullptr)]
#![allow(clippy::all)]
use std::alloc::System;
#[global_allocator]
static A: System = System;
use libc::{c_char, c_int, c_void};
use tikv_jemalloc_sys::*;
include!(concat!(env!("OUT_DIR"), "/all.rs"));