From 0cc7b0ef9f4c2bb226a836bafe8e34c2d5b759c7 Mon Sep 17 00:00:00 2001 From: "zhaixiaojuan@loongson.cn" <67671683+zhaixiaojuan@users.noreply.github.com> Date: Tue, 7 Feb 2023 19:30:10 +0800 Subject: [PATCH 1/6] Add loongarch64 support (#42) Signed-off-by: zhaixiaojuan --- jemallocator/benches/roundtrip.rs | 1 + jemallocator/src/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/jemallocator/benches/roundtrip.rs b/jemallocator/benches/roundtrip.rs index 767abe8..30f7bf4 100644 --- a/jemallocator/benches/roundtrip.rs +++ b/jemallocator/benches/roundtrip.rs @@ -31,6 +31,7 @@ const MIN_ALIGN: usize = 8; target_arch = "aarch64", target_arch = "powerpc64", target_arch = "powerpc64le", + target_arch = "loongarch64", target_arch = "mips64", target_arch = "riscv64", target_arch = "s390x", diff --git a/jemallocator/src/lib.rs b/jemallocator/src/lib.rs index 4a93973..65d4783 100644 --- a/jemallocator/src/lib.rs +++ b/jemallocator/src/lib.rs @@ -55,6 +55,7 @@ const ALIGNOF_MAX_ALIGN_T: usize = 8; target_arch = "aarch64", target_arch = "powerpc64", target_arch = "powerpc64le", + target_arch = "loongarch64", target_arch = "mips64", target_arch = "riscv64", target_arch = "s390x", From fd00e12cc531d15a52e1ace32ff33eb3366bc5e4 Mon Sep 17 00:00:00 2001 From: Carlos Galdino Date: Tue, 18 Apr 2023 07:51:21 +0100 Subject: [PATCH 2/6] Add `disable_cache_oblivious` feature (#51) When this feature is used, it will build Jemalloc with `--disable-cache-oblivious`. The feature is disabled by default. Signed-off-by: Carlos Galdino --- jemalloc-sys/Cargo.toml | 1 + jemalloc-sys/README.md | 7 +++++++ jemalloc-sys/build.rs | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/jemalloc-sys/Cargo.toml b/jemalloc-sys/Cargo.toml index 05e762b..75b0670 100644 --- a/jemalloc-sys/Cargo.toml +++ b/jemalloc-sys/Cargo.toml @@ -40,6 +40,7 @@ background_threads = [ "background_threads_runtime_support" ] stats = [] unprefixed_malloc_on_supported_platforms = [] disable_initial_exec_tls = [] +disable_cache_oblivious = [] [package.metadata.docs.rs] rustdoc-args = [ "--cfg", "jemallocator_docs" ] diff --git a/jemalloc-sys/README.md b/jemalloc-sys/README.md index 184f0db..234d96e 100644 --- a/jemalloc-sys/README.md +++ b/jemalloc-sys/README.md @@ -84,6 +84,13 @@ This crate provides following cargo feature flags: the error `yourlib.so: cannot allocate memory in static TLS block`, you'll likely want to enable this. +* `disable_cache_oblivious` (disabled by default): when enabled, jemalloc is + built with the `--disable-cache-oblivious` option. In that case, all large + allocations are page-aligned as an implementation artifact. It may severely + harm CPU cache utilization. However, the cache-oblivious layout has a cost of + one extra page per large allocation which can be unfeasible for certain + applications. + ### Environment variables `jemalloc` options taking values are passed via environment variables using the diff --git a/jemalloc-sys/build.rs b/jemalloc-sys/build.rs index c9e10ff..cf1ff45 100644 --- a/jemalloc-sys/build.rs +++ b/jemalloc-sys/build.rs @@ -262,6 +262,11 @@ fn main() { cmd.arg("--disable-initial-exec-tls"); } + if env::var("CARGO_FEATURE_DISABLE_CACHE_OBLIVIOUS").is_ok() { + info!("CARGO_FEATURE_DISABLE_CACHE_OBLIVIOUS set"); + cmd.arg("--disable-cache-oblivious"); + } + cmd.arg(format!("--host={}", gnu_target(&target))); cmd.arg(format!("--build={}", gnu_target(&host))); cmd.arg(format!("--prefix={}", out_dir.display())); From 0fef73074b57e8b1e6abb3d6beedfb823fce01bc Mon Sep 17 00:00:00 2001 From: Arnav Singh Date: Wed, 10 May 2023 01:28:12 -0700 Subject: [PATCH 3/6] Fix definition of `c_bool` for non-MSVC targets (#54) Fixes #53 Signed-off-by: Arnav Singh --- jemalloc-sys/src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/jemalloc-sys/src/lib.rs b/jemalloc-sys/src/lib.rs index 1344e27..58010af 100644 --- a/jemalloc-sys/src/lib.rs +++ b/jemalloc-sys/src/lib.rs @@ -50,7 +50,14 @@ #![deny(missing_docs, broken_intra_doc_links)] use libc::{c_char, c_int, c_uint, c_void, size_t}; + +// jemalloc uses `stdbool.h` to define `bool` for which the Rust equivalent is `bool`. +// However jemalloc also has its own `stdbool.h` that it uses when compiling with MSVC, +// and this header defines `bool` as `BOOL` which in turn is `int`. +#[cfg(target_env = "msvc")] type c_bool = c_int; +#[cfg(not(target_env = "msvc"))] +type c_bool = bool; /// Align the memory allocation to start at an address that is a /// multiple of `1 << la`. From 61999f26bb7e8b0d43a745c1905a47763960dabd Mon Sep 17 00:00:00 2001 From: Frank <35358771+Frankonly@users.noreply.github.com> Date: Wed, 19 Jul 2023 18:27:19 +0800 Subject: [PATCH 4/6] add disable_initial_exec_tls feature for jemalloc-ctl (#59) Signed-off-by: Likai Feng --- jemalloc-ctl/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/jemalloc-ctl/Cargo.toml b/jemalloc-ctl/Cargo.toml index e837bfe..8db53a3 100644 --- a/jemalloc-ctl/Cargo.toml +++ b/jemalloc-ctl/Cargo.toml @@ -36,6 +36,7 @@ tikv-jemallocator = { path = "../jemallocator", version = "0.5.0" } [features] default = [] use_std = [ "libc/use_std" ] +disable_initial_exec_tls = ["tikv-jemalloc-sys/disable_initial_exec_tls"] [package.metadata.docs.rs] rustdoc-args = [ "--cfg", "jemallocator_docs" ] From 02113e69f13021793ca8fe15d142ec369ced316e Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 27 Jul 2023 13:59:08 +0800 Subject: [PATCH 5/6] *: bump 0.5.4 (#62) Close #56 Signed-off-by: Jay Lee --- CHANGELOG.md | 7 +++++++ README.md | 2 +- jemalloc-ctl/Cargo.toml | 2 +- jemalloc-sys/Cargo.toml | 2 +- jemallocator/Cargo.toml | 2 +- jemallocator/src/lib.rs | 8 ++++---- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bd3917..bcd561b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 0.5.4 - 2023-07-22 + +- Add disable_initial_exec_tls feature for jemalloc-ctl (#59) +- Fix definition of `c_bool` for non-MSVC targets (#54) +- Add `disable_cache_oblivious` feature (#51) +- Add loongarch64 support (#42) + # jemalloc-sys 0.5.3 - 2023-02-03 - Remove fs-extra dependency (#47) diff --git a/README.md b/README.md index 6a253db..e9e13e6 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This project is the successor of [jemallocator](https://github.com/gnzlbg/jemallocator). -The project is published as `tikv-jemallocator` and `jemallocator` for historical reasons. The two crates are the same except names. It's OK to use either crate. But due to lack of permissions, only `jemallocator` and `jemalloc-sys` are updated. If you want to use other crates, `tikv-xxx` versions are still required. +The project is also published as `jemallocator` for historical reasons. The two crates are the same except names. For new projects, it's recommended to use `tikv-xxx` versions instead. > Links against `jemalloc` and provides a `Jemalloc` unit type that implements > the allocator APIs and can be set as the `#[global_allocator]` diff --git a/jemalloc-ctl/Cargo.toml b/jemalloc-ctl/Cargo.toml index 8db53a3..0375ef5 100644 --- a/jemalloc-ctl/Cargo.toml +++ b/jemalloc-ctl/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tikv-jemalloc-ctl" -version = "0.5.0" +version = "0.5.4" authors = [ "Steven Fackler ", "Gonzalo Brito Gadeschi ", diff --git a/jemalloc-sys/Cargo.toml b/jemalloc-sys/Cargo.toml index 75b0670..0e854dd 100644 --- a/jemalloc-sys/Cargo.toml +++ b/jemalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tikv-jemalloc-sys" -version = "0.5.3+5.3.0-patched" +version = "0.5.4+5.3.0-patched" authors = [ "Alex Crichton ", "Gonzalo Brito Gadeschi ", diff --git a/jemallocator/Cargo.toml b/jemallocator/Cargo.toml index 01e9837..010b99c 100644 --- a/jemallocator/Cargo.toml +++ b/jemallocator/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tikv-jemallocator" # Make sure to update the version in the README as well: -version = "0.5.0" +version = "0.5.4" authors = [ "Alex Crichton ", "Gonzalo Brito Gadeschi ", diff --git a/jemallocator/src/lib.rs b/jemallocator/src/lib.rs index 65d4783..165660e 100644 --- a/jemallocator/src/lib.rs +++ b/jemallocator/src/lib.rs @@ -42,14 +42,14 @@ use libc::{c_int, c_void}; // _Alignof(max_align_t), the malloc-APIs return memory whose alignment is // either the requested size if its a power-of-two, or the next smaller // power-of-two. -#[cfg(all(any( +#[cfg(any( target_arch = "arm", target_arch = "mips", target_arch = "mipsel", target_arch = "powerpc" -)))] +))] const ALIGNOF_MAX_ALIGN_T: usize = 8; -#[cfg(all(any( +#[cfg(any( target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64", @@ -60,7 +60,7 @@ const ALIGNOF_MAX_ALIGN_T: usize = 8; target_arch = "riscv64", target_arch = "s390x", target_arch = "sparc64" -)))] +))] const ALIGNOF_MAX_ALIGN_T: usize = 16; /// If `align` is less than `_Alignof(max_align_t)`, and if the requested From 0f8983f71813c6e052c6ab445e965c4b0a7e251e Mon Sep 17 00:00:00 2001 From: Jay Lee Date: Fri, 28 Jul 2023 00:05:57 +0800 Subject: [PATCH 6/6] Move README to jemallocator Signed-off-by: Jay Lee --- README.md | 98 +----------------------------------------- jemallocator/README.md | 97 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 97 deletions(-) mode change 100644 => 120000 README.md create mode 100644 jemallocator/README.md diff --git a/README.md b/README.md deleted file mode 100644 index e9e13e6..0000000 --- a/README.md +++ /dev/null @@ -1,97 +0,0 @@ -# tikv-jemallocator - -[![ci]][github actions] [![Latest Version]][crates.io] [![docs]][docs.rs] - -This project is the successor of [jemallocator](https://github.com/gnzlbg/jemallocator). - -The project is also published as `jemallocator` for historical reasons. The two crates are the same except names. For new projects, it's recommended to use `tikv-xxx` versions instead. - -> Links against `jemalloc` and provides a `Jemalloc` unit type that implements -> the allocator APIs and can be set as the `#[global_allocator]` - -## Overview - -The `jemalloc` support ecosystem consists of the following crates: - -* `tikv-jemalloc-sys`: builds and links against `jemalloc` exposing raw C bindings to it. -* `tikv-jemallocator`: provides the `Jemalloc` type which implements the - `GlobalAlloc` and `Alloc` traits. -* `tikv-jemalloc-ctl`: high-level wrapper over `jemalloc`'s control and introspection - APIs (the `mallctl*()` family of functions and the _MALLCTL NAMESPACE_)' - -## Documentation - -* [Latest release (docs.rs)][docs.rs] - -To use `tikv-jemallocator` add it as a dependency: - -```toml -# Cargo.toml -[dependencies] - -[target.'cfg(not(target_env = "msvc"))'.dependencies] -tikv-jemallocator = "0.5" -``` - -To set `tikv_jemallocator::Jemalloc` as the global allocator add this to your project: - -```rust -# main.rs -#[cfg(not(target_env = "msvc"))] -use tikv_jemallocator::Jemalloc; - -#[cfg(not(target_env = "msvc"))] -#[global_allocator] -static GLOBAL: Jemalloc = Jemalloc; -``` - -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. - -## Platform support - -The following table describes the supported platforms: - -* `build`: does the library compile for the target? -* `run`: do `tikv-jemallocator` and `tikv-jemalloc-sys` tests pass on the target? -* `jemalloc`: do `tikv-jemalloc`'s tests pass on the target? - -Tier 1 targets are tested on all Rust channels (stable, beta, and nightly). All -other targets are only tested on Rust nightly. - -| Linux targets: | build | run | jemalloc | -|-------------------------------------|-----------|---------|--------------| -| `aarch64-unknown-linux-gnu` | ✓ | ✓ | ✗ | -| `powerpc64le-unknown-linux-gnu` | ✓ | ✓ | ✗ | -| `x86_64-unknown-linux-gnu` (tier 1) | ✓ | ✓ | ✓ | -| **MacOSX targets:** | **build** | **run** | **jemalloc** | -| `x86_64-apple-darwin` (tier 1) | ✓ | ✓ | ✗ | - -## Features - -The `tikv-jemallocator` crate re-exports the [features of the `tikv-jemalloc-sys` -dependency](https://github.com/tikv/jemallocator/blob/master/jemalloc-sys/README.md). - -## License - -This project is licensed under either of - - * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or - http://www.apache.org/licenses/LICENSE-2.0) - * MIT license ([LICENSE-MIT](LICENSE-MIT) or - http://opensource.org/licenses/MIT) - -at your option. - -## Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted -for inclusion in `tikv-jemallocator` by you, as defined in the Apache-2.0 license, -shall be dual licensed as above, without any additional terms or conditions. - -[Latest Version]: https://img.shields.io/crates/v/tikv-jemallocator.svg -[crates.io]: https://crates.io/crates/tikv-jemallocator -[docs]: https://docs.rs/tikv-jemallocator/badge.svg -[docs.rs]: https://docs.rs/tikv-jemallocator/ -[ci]: https://github.com/tikv/jemallocator/actions/workflows/main.yml/badge.svg -[github actions]: https://github.com/tikv/jemallocator/actions diff --git a/README.md b/README.md new file mode 120000 index 0000000..39c4a18 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +jemallocator/README.md \ No newline at end of file diff --git a/jemallocator/README.md b/jemallocator/README.md new file mode 100644 index 0000000..e9e13e6 --- /dev/null +++ b/jemallocator/README.md @@ -0,0 +1,97 @@ +# tikv-jemallocator + +[![ci]][github actions] [![Latest Version]][crates.io] [![docs]][docs.rs] + +This project is the successor of [jemallocator](https://github.com/gnzlbg/jemallocator). + +The project is also published as `jemallocator` for historical reasons. The two crates are the same except names. For new projects, it's recommended to use `tikv-xxx` versions instead. + +> Links against `jemalloc` and provides a `Jemalloc` unit type that implements +> the allocator APIs and can be set as the `#[global_allocator]` + +## Overview + +The `jemalloc` support ecosystem consists of the following crates: + +* `tikv-jemalloc-sys`: builds and links against `jemalloc` exposing raw C bindings to it. +* `tikv-jemallocator`: provides the `Jemalloc` type which implements the + `GlobalAlloc` and `Alloc` traits. +* `tikv-jemalloc-ctl`: high-level wrapper over `jemalloc`'s control and introspection + APIs (the `mallctl*()` family of functions and the _MALLCTL NAMESPACE_)' + +## Documentation + +* [Latest release (docs.rs)][docs.rs] + +To use `tikv-jemallocator` add it as a dependency: + +```toml +# Cargo.toml +[dependencies] + +[target.'cfg(not(target_env = "msvc"))'.dependencies] +tikv-jemallocator = "0.5" +``` + +To set `tikv_jemallocator::Jemalloc` as the global allocator add this to your project: + +```rust +# main.rs +#[cfg(not(target_env = "msvc"))] +use tikv_jemallocator::Jemalloc; + +#[cfg(not(target_env = "msvc"))] +#[global_allocator] +static GLOBAL: Jemalloc = Jemalloc; +``` + +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. + +## Platform support + +The following table describes the supported platforms: + +* `build`: does the library compile for the target? +* `run`: do `tikv-jemallocator` and `tikv-jemalloc-sys` tests pass on the target? +* `jemalloc`: do `tikv-jemalloc`'s tests pass on the target? + +Tier 1 targets are tested on all Rust channels (stable, beta, and nightly). All +other targets are only tested on Rust nightly. + +| Linux targets: | build | run | jemalloc | +|-------------------------------------|-----------|---------|--------------| +| `aarch64-unknown-linux-gnu` | ✓ | ✓ | ✗ | +| `powerpc64le-unknown-linux-gnu` | ✓ | ✓ | ✗ | +| `x86_64-unknown-linux-gnu` (tier 1) | ✓ | ✓ | ✓ | +| **MacOSX targets:** | **build** | **run** | **jemalloc** | +| `x86_64-apple-darwin` (tier 1) | ✓ | ✓ | ✗ | + +## Features + +The `tikv-jemallocator` crate re-exports the [features of the `tikv-jemalloc-sys` +dependency](https://github.com/tikv/jemallocator/blob/master/jemalloc-sys/README.md). + +## License + +This project is licensed under either of + + * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or + http://www.apache.org/licenses/LICENSE-2.0) + * MIT license ([LICENSE-MIT](LICENSE-MIT) or + http://opensource.org/licenses/MIT) + +at your option. + +## Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in `tikv-jemallocator` by you, as defined in the Apache-2.0 license, +shall be dual licensed as above, without any additional terms or conditions. + +[Latest Version]: https://img.shields.io/crates/v/tikv-jemallocator.svg +[crates.io]: https://crates.io/crates/tikv-jemallocator +[docs]: https://docs.rs/tikv-jemallocator/badge.svg +[docs.rs]: https://docs.rs/tikv-jemallocator/ +[ci]: https://github.com/tikv/jemallocator/actions/workflows/main.yml/badge.svg +[github actions]: https://github.com/tikv/jemallocator/actions