From 46ab148fe610707f0bd83cf77de17cbbd78938be Mon Sep 17 00:00:00 2001 From: schrodingerzhu Date: Mon, 20 Jan 2020 22:57:22 +0800 Subject: [PATCH 001/145] initial commit of merged repo --- .gitignore | 2 + .gitmodules | 4 ++ Cargo.toml | 15 ++++++ README.md | 25 ++++++++++ snmalloc-sys/Cargo.toml | 19 +++++++ snmalloc-sys/build.rs | 41 +++++++++++++++ snmalloc-sys/snmalloc | 1 + snmalloc-sys/src/lib.rs | 56 +++++++++++++++++++++ src/lib.rs | 107 ++++++++++++++++++++++++++++++++++++++++ 9 files changed, 270 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 Cargo.toml create mode 100644 README.md create mode 100644 snmalloc-sys/Cargo.toml create mode 100644 snmalloc-sys/build.rs create mode 160000 snmalloc-sys/snmalloc create mode 100644 snmalloc-sys/src/lib.rs create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..a9d37c560 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target +Cargo.lock diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..f8caccfec --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "snmalloc-sys/snmalloc"] + path = snmalloc-sys/snmalloc + url = https://github.com/SchrodingerZhu/snmalloc + branch = master diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 000000000..148bbe627 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "snmalloc-rs" +version = "0.1.0" +authors = ["schrodingerzhu "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +snmalloc-sys = {path = "snmalloc-sys"} + +[features] +1mib = ["snmalloc-sys/1mib"] +debug = ["snmalloc-sys/debug"] +cache-friendly = ["snmalloc-sys/cache-friendly"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 000000000..46eb622ab --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# snmalloc-rs +`snmalloc-rs` provides a wrapper for [`microsoft/snmalloc`](https://github.com/microsoft/snmalloc) to make it usable as a global allocator for rust. +snmalloc is a research allocator. Its key design features are: +- Memory that is freed by the same thread that allocated it does not require any synchronising operations. +- Freeing memory in a different thread to initially allocated it, does not take any locks and instead uses a novel message passing scheme to return the memory to the original allocator, where it is recycled. +- The allocator uses large ranges of pages to reduce the amount of meta-data required. + +The benchmark is available at the [paper](https://github.com/microsoft/snmalloc/blob/master/snmalloc.pdf) of `snmalloc` +There are three features defined in this crate: +- `debug`: Enable the `Debug` mode in `snmalloc`. +- `1mib`: Use the `1mib` chunk configuration. +- `cache-friendly`: Make the allocator more cache friendly (setting `CACHE_FRIENDLY_OFFSET` to `64` in building the library). + +To use `snmalloc-rs` add it as a dependency: +```toml +# Cargo.toml +[dependencies] +snmalloc-rs = "0.1.0" +``` + +To set `SnMalloc` as the global allocator add this to your project: +```rust +#[global_allocator] +static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc; +``` \ No newline at end of file diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml new file mode 100644 index 000000000..02d283129 --- /dev/null +++ b/snmalloc-sys/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "snmalloc-sys" +version = "0.1.0" +authors = ["schrodingerzhu "] +edition = "2018" +build = "build.rs" +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[build-dependencies] +cmake = "0.1" + +[dependencies.libc] +version = "*" +default-features = false + +[features] +1mib = [] +debug = [] +cache-friendly = [] \ No newline at end of file diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs new file mode 100644 index 000000000..f2964b2a6 --- /dev/null +++ b/snmalloc-sys/build.rs @@ -0,0 +1,41 @@ +use cmake::Config; +fn main() { + let mut cfg = &mut Config::new("snmalloc"); + + let build_type = if cfg!(feature = "debug") { + "Debug" + } else { + "Release" + }; + + if cfg!(all(windows, target_env = "msvc")) { + cfg = cfg.generator("Visual Studio 15 2017 Win64") + .define("SNMALLOC_RUST_SUPPORT", "ON") + .build_arg("--config") + .build_arg(build_type) + } else { + cfg = cfg.generator("Ninja") + .define("SNMALLOC_RUST_SUPPORT", "ON") + .define("CMAKE_BUILD_TYPE", build_type) + } + + let target = if cfg!(feature = "1mib") { + "snmallocshim-1mib" + } else { + "snmallocshim" + }; + + let mut dst = if cfg!(feature = "cache-friendly") { + cfg.define("CACHE_FRIENDLY_OFFSET", "64").build_target(target).build() + } else { + cfg.build_target(target).build() + }; + + dst.push("./build"); + println!("cargo:rustc-link-search=native={}", dst.display()); + println!("cargo:rustc-link-lib={}", target); + if cfg!(unix) { + println!("cargo:rustc-link-lib=dylib=stdc++"); + println!("cargo:rustc-link-lib=dylib=atomic"); + } +} \ No newline at end of file diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc new file mode 160000 index 000000000..f262deabf --- /dev/null +++ b/snmalloc-sys/snmalloc @@ -0,0 +1 @@ +Subproject commit f262deabf7d9fe94cd5f594cb3ff9a9762194124 diff --git a/snmalloc-sys/src/lib.rs b/snmalloc-sys/src/lib.rs new file mode 100644 index 000000000..c35fc9d44 --- /dev/null +++ b/snmalloc-sys/src/lib.rs @@ -0,0 +1,56 @@ +#![no_std] +#![allow(non_camel_case_types)] +#![feature(static_nobundle)] +use core::ffi::c_void; +use libc::size_t; + +extern "C" { + /// Allocate the memory with the given alignment and size. + /// On success, it returns a pointer pointing to the required memory address. + /// On failure, it returns a null pointer. + /// The client must assure the following things: + /// - `alignment` is greater than zero + /// - `alignment` is less equal to `SUPERSLAB_SIZE` (defined in snmalloc) + /// - `alignment` is of the power of 2 + /// The program may be forced to abort if the constrains are not full-filled. + pub fn rust_alloc(alignment: size_t, size: size_t) -> *mut c_void; + + /// De-allocate the memory at the given address with the given alignment and size. + /// The client must assure the following things: + /// - the memory is acquired using the same allocator and the pointer points to the start position. + /// - `alignment` and `size` is the same as allocation + /// The program may be forced to abort if the constrains are not full-filled. + pub fn rust_dealloc(ptr: *mut c_void, alignment: size_t, size: size_t) -> c_void; + + /// dealloc the memory at the given address with the given alignment and size. + /// On success, it returns a pointer pointing to the required memory address. + /// The memory content within the `new_size` will remains the same as previous. + /// On failure, it returns a null pointer. In this situation, the previous memory is not returned to the allocator. + /// The client must assure the following things: + /// - the memory is acquired using the same allocator and the pointer points to the start position + /// - `alignment` and `old_size` is the same as allocation + /// - `alignment` fulfills all the requirements as `rust_alloc` + /// The program may be forced to abort if the constrains are not full-filled. + pub fn rust_realloc(ptr: *mut c_void, alignment: size_t, old_size: size_t, new_size: size_t) -> *mut c_void; +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_frees_memory_malloc() { + let ptr = unsafe { rust_alloc(8, 8) } as *mut u8; + unsafe {*ptr = 127; assert_eq!(*ptr, 127)}; + unsafe { rust_dealloc(ptr as *mut c_void, 8, 8) }; + } + + #[test] + fn it_reallocs_correctly() { + let mut ptr = unsafe { rust_alloc(8, 8) } as *mut u8; + unsafe {*ptr = 127; assert_eq!(*ptr, 127)}; + ptr = unsafe { rust_realloc(ptr as *mut c_void, 8, 8, 16) } as *mut u8; + unsafe {assert_eq!(*ptr, 127)}; + unsafe { rust_dealloc(ptr as *mut c_void, 8, 16) }; + } +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 000000000..5f3f3a2dd --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,107 @@ +#![no_std] +/// `snmalloc-rs` provides a wrapper for [`microsoft/snmalloc`](https://github.com/microsoft/snmalloc) to make it usable as a global allocator for rust. +/// snmalloc is a research allocator. Its key design features are: +/// - Memory that is freed by the same thread that allocated it does not require any synchronising operations. +/// - Freeing memory in a different thread to initially allocated it, does not take any locks and instead uses a novel message passing scheme to return the memory to the original allocator, where it is recycled. +/// - The allocator uses large ranges of pages to reduce the amount of meta-data required. +/// +/// The benchmark is available at the [paper](https://github.com/microsoft/snmalloc/blob/master/snmalloc.pdf) of `snmalloc` +/// There are three features defined in this crate: +/// - `debug`: Enable the `Debug` mode in `snmalloc`. +/// - `1mib`: Use the `1mib` chunk configuration. +/// - `cache-friendly`: Make the allocator more cache friendly (setting `CACHE_FRIENDLY_OFFSET` to `64` in building the library). +/// +/// The whole library supports `no_std`. +/// +/// To use `snmalloc-rs` add it as a dependency: +/// ```toml +/// # Cargo.toml +/// [dependencies] +/// snmalloc-rs = "0.1.0" +/// ``` +/// +/// To set `SnMalloc` as the global allocator add this to your project: +/// ```rust +/// #[global_allocator] +/// static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc; +/// ``` +extern crate snmalloc_sys as ffi; + +use core::alloc::{GlobalAlloc, Layout}; + +pub struct SnMalloc; + +unsafe impl GlobalAlloc for SnMalloc { + /// Allocate the memory with the given alignment and size. + /// On success, it returns a pointer pointing to the required memory address. + /// On failure, it returns a null pointer. + /// The client must assure the following things: + /// - `alignment` is greater than zero + /// - `alignment` is less equal to `SUPERSLAB_SIZE` (defined in snmalloc) + /// - Other constrains are the same as the rust standard library. + /// The program may be forced to abort if the constrains are not full-filled. + unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + ffi::rust_alloc(layout.align(), layout.size()) as _ + } + + /// De-allocate the memory at the given address with the given alignment and size. + /// The client must assure the following things: + /// - the memory is acquired using the same allocator and the pointer points to the start position. + /// - Other constrains are the same as the rust standard library. + /// The program may be forced to abort if the constrains are not full-filled. + unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { + ffi::rust_dealloc(ptr as _, layout.align(), layout.size()); + } + + /// dealloc the memory at the given address with the given alignment and size. + /// On success, it returns a pointer pointing to the required memory address. + /// The memory content within the `new_size` will remains the same as previous. + /// On failure, it returns a null pointer. In this situation, the previous memory is not returned to the allocator. + /// The client must assure the following things: + /// - the memory is acquired using the same allocator and the pointer points to the start position + /// - `alignment` fulfills all the requirements as `rust_alloc` + /// - Other constrains are the same as the rust standard library. + /// The program may be forced to abort if the constrains are not full-filled. + unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { + ffi::rust_realloc(ptr as _, layout.align(), layout.size(), new_size) as _ + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_frees_allocated_memory() { + unsafe { + let layout = Layout::from_size_align(8, 8).unwrap(); + let alloc = SnMalloc; + + let ptr = alloc.alloc(layout.clone()); + alloc.dealloc(ptr, layout); + } + } + + #[test] + fn it_frees_zero_allocated_memory() { + unsafe { + let layout = Layout::from_size_align(8, 8).unwrap(); + let alloc = SnMalloc; + + let ptr = alloc.alloc_zeroed(layout.clone()); + alloc.dealloc(ptr, layout); + } + } + + #[test] + fn it_frees_reallocated_memory() { + unsafe { + let layout = Layout::from_size_align(8, 8).unwrap(); + let alloc = SnMalloc; + + let ptr = alloc.alloc(layout.clone()); + let ptr = alloc.realloc(ptr, layout.clone(), 16); + alloc.dealloc(ptr, layout); + } + } +} \ No newline at end of file From 5a57c77cf8774657ca550f0ecddb060bb54dc422 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu <118010469@link.cuhk.edu.cn> Date: Mon, 20 Jan 2020 23:05:35 +0800 Subject: [PATCH 002/145] Add MIT LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..7f6c08fe6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 SchrodingerZhu + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 637f891e8dfe263e100fbccc65d501bd067f989b Mon Sep 17 00:00:00 2001 From: schrodingerzhu Date: Mon, 20 Jan 2020 23:10:48 +0800 Subject: [PATCH 003/145] add more info to make it published --- Cargo.toml | 6 +++++- snmalloc-sys/Cargo.toml | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 148bbe627..8f8ded9b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,11 +3,15 @@ name = "snmalloc-rs" version = "0.1.0" authors = ["schrodingerzhu "] edition = "2018" +license = "MIT" +description = "rust bindings of snmalloc." +homepage = "https://github.com/microsoft/snmalloc" +repository = "https://github.com/SchrodingerZhu/snmalloc-rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -snmalloc-sys = {path = "snmalloc-sys"} +snmalloc-sys = {version = "0.1.0", path = "snmalloc-sys"} [features] 1mib = ["snmalloc-sys/1mib"] diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 02d283129..ddbb70a22 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -3,6 +3,10 @@ name = "snmalloc-sys" version = "0.1.0" authors = ["schrodingerzhu "] edition = "2018" +license = "MIT" +description = "rust raw bindings of snmalloc." +homepage = "https://github.com/microsoft/snmalloc" +repository = "https://github.com/SchrodingerZhu/snmalloc-rs" build = "build.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -10,7 +14,7 @@ build = "build.rs" cmake = "0.1" [dependencies.libc] -version = "*" +version = "0.2" default-features = false [features] From cefc5855bca877f67bdc854ea4375b6e3b15685b Mon Sep 17 00:00:00 2001 From: schrodingerzhu Date: Mon, 20 Jan 2020 23:34:45 +0800 Subject: [PATCH 004/145] fix document --- Cargo.toml | 11 ++++++--- snmalloc-sys/Cargo.toml | 4 +++- src/lib.rs | 52 ++++++++++++++++++++--------------------- 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8f8ded9b7..a6e28fec9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,17 +1,22 @@ [package] name = "snmalloc-rs" -version = "0.1.0" +version = "0.1.1" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" description = "rust bindings of snmalloc." +keywords = ["snmalloc", "allocator"] +categories = ["memory-management", "api-bindings"] homepage = "https://github.com/microsoft/snmalloc" repository = "https://github.com/SchrodingerZhu/snmalloc-rs" - +readme = "README.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[workspace] +members = ["snmalloc-sys" ] + [dependencies] -snmalloc-sys = {version = "0.1.0", path = "snmalloc-sys"} +snmalloc-sys = {version = "0.1", path = "snmalloc-sys"} [features] 1mib = ["snmalloc-sys/1mib"] diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index ddbb70a22..42ea45a95 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,10 +1,12 @@ [package] name = "snmalloc-sys" -version = "0.1.0" +version = "0.1.1" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" description = "rust raw bindings of snmalloc." +keywords = ["snmalloc", "allocator"] +categories = ["memory-management", "api-bindings"] homepage = "https://github.com/microsoft/snmalloc" repository = "https://github.com/SchrodingerZhu/snmalloc-rs" build = "build.rs" diff --git a/src/lib.rs b/src/lib.rs index 5f3f3a2dd..48de69974 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,30 +1,30 @@ #![no_std] -/// `snmalloc-rs` provides a wrapper for [`microsoft/snmalloc`](https://github.com/microsoft/snmalloc) to make it usable as a global allocator for rust. -/// snmalloc is a research allocator. Its key design features are: -/// - Memory that is freed by the same thread that allocated it does not require any synchronising operations. -/// - Freeing memory in a different thread to initially allocated it, does not take any locks and instead uses a novel message passing scheme to return the memory to the original allocator, where it is recycled. -/// - The allocator uses large ranges of pages to reduce the amount of meta-data required. -/// -/// The benchmark is available at the [paper](https://github.com/microsoft/snmalloc/blob/master/snmalloc.pdf) of `snmalloc` -/// There are three features defined in this crate: -/// - `debug`: Enable the `Debug` mode in `snmalloc`. -/// - `1mib`: Use the `1mib` chunk configuration. -/// - `cache-friendly`: Make the allocator more cache friendly (setting `CACHE_FRIENDLY_OFFSET` to `64` in building the library). -/// -/// The whole library supports `no_std`. -/// -/// To use `snmalloc-rs` add it as a dependency: -/// ```toml -/// # Cargo.toml -/// [dependencies] -/// snmalloc-rs = "0.1.0" -/// ``` -/// -/// To set `SnMalloc` as the global allocator add this to your project: -/// ```rust -/// #[global_allocator] -/// static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc; -/// ``` +//! `snmalloc-rs` provides a wrapper for [`microsoft/snmalloc`](https://github.com/microsoft/snmalloc) to make it usable as a global allocator for rust. +//! snmalloc is a research allocator. Its key design features are: +//! - Memory that is freed by the same thread that allocated it does not require any synchronising operations. +//! - Freeing memory in a different thread to initially allocated it, does not take any locks and instead uses a novel message passing scheme to return the memory to the original allocator, where it is recycled. +//! - The allocator uses large ranges of pages to reduce the amount of meta-data required. +//! +//! The benchmark is available at the [paper](https://github.com/microsoft/snmalloc/blob/master/snmalloc.pdf) of `snmalloc` +//! There are three features defined in this crate: +//! - `debug`: Enable the `Debug` mode in `snmalloc`. +//! - `1mib`: Use the `1mib` chunk configuration. +//! - `cache-friendly`: Make the allocator more cache friendly (setting `CACHE_FRIENDLY_OFFSET` to `64` in building the library). +//! +//! The whole library supports `no_std`. +//! +//! To use `snmalloc-rs` add it as a dependency: +//! ```toml +//! # Cargo.toml +//! [dependencies] +//! snmalloc-rs = "0.1.0" +//! ``` +//! +//! To set `SnMalloc` as the global allocator add this to your project: +//! ```rust +//! #[global_allocator] +//! static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc; +//! ``` extern crate snmalloc_sys as ffi; use core::alloc::{GlobalAlloc, Layout}; From 6aa381cd8bc7c189eaf735ea5cd05750c032fa61 Mon Sep 17 00:00:00 2001 From: schrodingerzhu Date: Tue, 21 Jan 2020 08:41:19 +0800 Subject: [PATCH 005/145] use default generator on unix --- Cargo.toml | 2 +- snmalloc-sys/Cargo.toml | 2 +- snmalloc-sys/build.rs | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a6e28fec9..8dbe5bfaf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.1.1" +version = "0.1.2" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 42ea45a95..61b867886 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.1.1" +version = "0.1.2" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index f2964b2a6..f54f4fea0 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -14,8 +14,7 @@ fn main() { .build_arg("--config") .build_arg(build_type) } else { - cfg = cfg.generator("Ninja") - .define("SNMALLOC_RUST_SUPPORT", "ON") + cfg = cfg.define("SNMALLOC_RUST_SUPPORT", "ON") .define("CMAKE_BUILD_TYPE", build_type) } From 9c86efd9d035db87d518a4a6721c8e3d456e8338 Mon Sep 17 00:00:00 2001 From: schrodingerzhu Date: Thu, 23 Jan 2020 19:43:17 +0800 Subject: [PATCH 006/145] Update to version 0.2.0 - Use the master branch of microsoft/snmalloc - Fix Documentation --- .gitmodules | 2 +- Cargo.toml | 4 ++-- snmalloc-sys/Cargo.toml | 2 +- snmalloc-sys/build.rs | 4 ++-- snmalloc-sys/snmalloc | 2 +- snmalloc-sys/src/lib.rs | 2 +- src/lib.rs | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.gitmodules b/.gitmodules index f8caccfec..1eb35324f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "snmalloc-sys/snmalloc"] path = snmalloc-sys/snmalloc - url = https://github.com/SchrodingerZhu/snmalloc + url = https://github.com/microsoft/snmalloc branch = master diff --git a/Cargo.toml b/Cargo.toml index 8dbe5bfaf..c397c78de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.1.2" +version = "0.2.0" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.1", path = "snmalloc-sys"} +snmalloc-sys = {version = "0.2", path = "snmalloc-sys"} [features] 1mib = ["snmalloc-sys/1mib"] diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 61b867886..b981b4477 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.1.2" +version = "0.2.0" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index f54f4fea0..b4c4a2d31 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -19,9 +19,9 @@ fn main() { } let target = if cfg!(feature = "1mib") { - "snmallocshim-1mib" + "snmallocshim-1mib-rust" } else { - "snmallocshim" + "snmallocshim-rust" }; let mut dst = if cfg!(feature = "cache-friendly") { diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index f262deabf..2b2ab9153 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit f262deabf7d9fe94cd5f594cb3ff9a9762194124 +Subproject commit 2b2ab91537b7862d514ac458e880d4225379419a diff --git a/snmalloc-sys/src/lib.rs b/snmalloc-sys/src/lib.rs index c35fc9d44..5faa0320f 100644 --- a/snmalloc-sys/src/lib.rs +++ b/snmalloc-sys/src/lib.rs @@ -22,7 +22,7 @@ extern "C" { /// The program may be forced to abort if the constrains are not full-filled. pub fn rust_dealloc(ptr: *mut c_void, alignment: size_t, size: size_t) -> c_void; - /// dealloc the memory at the given address with the given alignment and size. + /// Re-allocate the memory at the given address with the given alignment and size. /// On success, it returns a pointer pointing to the required memory address. /// The memory content within the `new_size` will remains the same as previous. /// On failure, it returns a null pointer. In this situation, the previous memory is not returned to the allocator. diff --git a/src/lib.rs b/src/lib.rs index 48de69974..37bf8d467 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,7 +53,7 @@ unsafe impl GlobalAlloc for SnMalloc { ffi::rust_dealloc(ptr as _, layout.align(), layout.size()); } - /// dealloc the memory at the given address with the given alignment and size. + /// Re-allocate the memory at the given address with the given alignment and size. /// On success, it returns a pointer pointing to the required memory address. /// The memory content within the `new_size` will remains the same as previous. /// On failure, it returns a null pointer. In this situation, the previous memory is not returned to the allocator. From 1139725c30c4c711ecc6d063585f0252fec116ba Mon Sep 17 00:00:00 2001 From: SchrodingerZhu <118010469@link.cuhk.edu.cn> Date: Fri, 24 Jan 2020 16:25:18 +0800 Subject: [PATCH 007/145] fix msvc building --- snmalloc-sys/build.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index b4c4a2d31..37236f189 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -1,4 +1,5 @@ use cmake::Config; + fn main() { let mut cfg = &mut Config::new("snmalloc"); @@ -8,15 +9,8 @@ fn main() { "Release" }; - if cfg!(all(windows, target_env = "msvc")) { - cfg = cfg.generator("Visual Studio 15 2017 Win64") - .define("SNMALLOC_RUST_SUPPORT", "ON") - .build_arg("--config") - .build_arg(build_type) - } else { - cfg = cfg.define("SNMALLOC_RUST_SUPPORT", "ON") - .define("CMAKE_BUILD_TYPE", build_type) - } + cfg = cfg.define("SNMALLOC_RUST_SUPPORT", "ON") + .profile(build_type); let target = if cfg!(feature = "1mib") { "snmallocshim-1mib-rust" @@ -29,12 +23,16 @@ fn main() { } else { cfg.build_target(target).build() }; - + dst.push("./build"); - println!("cargo:rustc-link-search=native={}", dst.display()); + println!("cargo:rustc-link-lib={}", target); if cfg!(unix) { + println!("cargo:rustc-link-search=native={}", dst.display()); println!("cargo:rustc-link-lib=dylib=stdc++"); println!("cargo:rustc-link-lib=dylib=atomic"); + } else { + println!("cargo:rustc-link-search=native={}/{}", dst.display(), build_type); + println!("cargo:rustc-link-lib=dylib=mincore"); } -} \ No newline at end of file +} From 51cc0e12850eb8bebb5d7ce40904189f66cb4815 Mon Sep 17 00:00:00 2001 From: schrodingerzhu Date: Fri, 24 Jan 2020 18:06:57 +0800 Subject: [PATCH 008/145] remove unused unstable feature --- snmalloc-sys/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/src/lib.rs b/snmalloc-sys/src/lib.rs index 5faa0320f..72052cbd4 100644 --- a/snmalloc-sys/src/lib.rs +++ b/snmalloc-sys/src/lib.rs @@ -1,6 +1,6 @@ #![no_std] #![allow(non_camel_case_types)] -#![feature(static_nobundle)] + use core::ffi::c_void; use libc::size_t; From 063cd5f7a64459fefcc52b97ea94f3c4d9d983f8 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Fri, 24 Jan 2020 18:19:00 +0800 Subject: [PATCH 009/145] add travis ci --- .travis.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..547bae35e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +language: rust +rust: + - stable + +os: + - linux + - osx + - windows + +script: + - cargo test --all + - cargo test --all --features 1mib + - cargo test --all --features debug + - cargo test --all --features cache-friendly + From 9eddb05305f7c99223b9fc121ee7066ea61eba37 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu <118010469@link.cuhk.edu.cn> Date: Fri, 24 Jan 2020 20:42:14 +0800 Subject: [PATCH 010/145] Ci (#1) --- .travis.yml | 65 +++++++++++++++++++++++++++++++++++++------ snmalloc-sys/build.rs | 5 +++- 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 547bae35e..9de32bf96 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,60 @@ -language: rust -rust: - - stable - -os: - - linux - - osx - - windows +matrix: + include: + - os: windows + language: rust + rust: + - stable + before_script: + - rustup toolchain install stable-x86_64-pc-windows-msvc + - rustup default stable-msvc + + - os: windows + language: rust + rust: + - nightly + before_script: + - rustup toolchain install nightly-x86_64-pc-windows-msvc + - rustup default nightly-msvc + + - os: linux + language: rust + rust: + - stable + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-9 + env: + - CC=gcc-9 + - CXX=g++-9 + + - os: linux + language: rust + rust: + - nightly + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-9 + env: + - CC=gcc-9 + - CXX=g++-9 + + - os: osx + language: rust + rust: + - stable + + - os: osx + language: rust + rust: + - nightly + + script: - cargo test --all diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 37236f189..9f3709dbe 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -30,9 +30,12 @@ fn main() { if cfg!(unix) { println!("cargo:rustc-link-search=native={}", dst.display()); println!("cargo:rustc-link-lib=dylib=stdc++"); - println!("cargo:rustc-link-lib=dylib=atomic"); } else { println!("cargo:rustc-link-search=native={}/{}", dst.display(), build_type); println!("cargo:rustc-link-lib=dylib=mincore"); } + + if cfg!(target_os = "linux") { + println!("cargo:rustc-link-lib=dylib=atomic"); + } } From 87b3a1d534a04de4ae93db53dca40dbe9d308c8a Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Fri, 24 Jan 2020 20:46:04 +0800 Subject: [PATCH 011/145] bump version to 1.2.1 - update README.md - add ci - fix windows and osx build --- Cargo.toml | 2 +- README.md | 4 +++- snmalloc-sys/Cargo.toml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c397c78de..b63cc7a8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.0" +version = "0.2.1" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" diff --git a/README.md b/README.md index 46eb622ab..9b26904e0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ # snmalloc-rs +![travis ci](https://www.travis-ci.org/SchrodingerZhu/snmalloc-rs.svg?branch=master) + `snmalloc-rs` provides a wrapper for [`microsoft/snmalloc`](https://github.com/microsoft/snmalloc) to make it usable as a global allocator for rust. snmalloc is a research allocator. Its key design features are: - Memory that is freed by the same thread that allocated it does not require any synchronising operations. @@ -15,7 +17,7 @@ To use `snmalloc-rs` add it as a dependency: ```toml # Cargo.toml [dependencies] -snmalloc-rs = "0.1.0" +snmalloc-rs = "0.2" ``` To set `SnMalloc` as the global allocator add this to your project: diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index b981b4477..d50e3547a 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.0" +version = "0.2.1" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" From 6ea52dad9e3eb0333bfc6609006e8a0a5b9b3c54 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Mon, 27 Jan 2020 08:25:04 +0000 Subject: [PATCH 012/145] Minor typos. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b26904e0..d435885f7 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ snmalloc is a research allocator. Its key design features are: - Freeing memory in a different thread to initially allocated it, does not take any locks and instead uses a novel message passing scheme to return the memory to the original allocator, where it is recycled. - The allocator uses large ranges of pages to reduce the amount of meta-data required. -The benchmark is available at the [paper](https://github.com/microsoft/snmalloc/blob/master/snmalloc.pdf) of `snmalloc` +Some old benchmark results are available in the [`snmalloc` paper](https://github.com/microsoft/snmalloc/blob/master/snmalloc.pdf). There are three features defined in this crate: - `debug`: Enable the `Debug` mode in `snmalloc`. - `1mib`: Use the `1mib` chunk configuration. From 1892d89fda25160c45fdca571486f1654f47f0bc Mon Sep 17 00:00:00 2001 From: snf Date: Fri, 31 Jan 2020 16:25:47 +0000 Subject: [PATCH 013/145] inlining allocation calls --- src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 37bf8d467..527186abf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,6 +40,7 @@ unsafe impl GlobalAlloc for SnMalloc { /// - `alignment` is less equal to `SUPERSLAB_SIZE` (defined in snmalloc) /// - Other constrains are the same as the rust standard library. /// The program may be forced to abort if the constrains are not full-filled. + #[inline(always)] unsafe fn alloc(&self, layout: Layout) -> *mut u8 { ffi::rust_alloc(layout.align(), layout.size()) as _ } @@ -49,6 +50,7 @@ unsafe impl GlobalAlloc for SnMalloc { /// - the memory is acquired using the same allocator and the pointer points to the start position. /// - Other constrains are the same as the rust standard library. /// The program may be forced to abort if the constrains are not full-filled. + #[inline(always)] unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { ffi::rust_dealloc(ptr as _, layout.align(), layout.size()); } @@ -62,6 +64,7 @@ unsafe impl GlobalAlloc for SnMalloc { /// - `alignment` fulfills all the requirements as `rust_alloc` /// - Other constrains are the same as the rust standard library. /// The program may be forced to abort if the constrains are not full-filled. + #[inline(always)] unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { ffi::rust_realloc(ptr as _, layout.align(), layout.size(), new_size) as _ } From fd9a15331550a54de12dc20ef543ca1c2fa791a8 Mon Sep 17 00:00:00 2001 From: snf Date: Fri, 31 Jan 2020 16:26:44 +0000 Subject: [PATCH 014/145] overriding CMAKE_CXX_FLAGS_RELEASE and CMAKE_C_FLAGS_RELEASE in Windows to add /DNDEBUG --- snmalloc-sys/build.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 9f3709dbe..597017ab7 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -12,6 +12,11 @@ fn main() { cfg = cfg.define("SNMALLOC_RUST_SUPPORT", "ON") .profile(build_type); + if cfg!(all(windows, target_env = "msvc")) { + cfg = cfg.define("CMAKE_CXX_FLAGS_RELEASE", "/MD /O2 /Ob2 /DNDEBUG"); + cfg = cfg.define("CMAKE_C_FLAGS_RELEASE", "/MD /O2 /Ob2 /DNDEBUG"); + } + let target = if cfg!(feature = "1mib") { "snmallocshim-1mib-rust" } else { From f45ef52a40608b3e0c8ba195a0216a7563a3bcd4 Mon Sep 17 00:00:00 2001 From: schrodingerzhu Date: Sun, 2 Feb 2020 13:28:00 +0800 Subject: [PATCH 015/145] adjust build args order --- snmalloc-sys/build.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 597017ab7..47fdc8fd6 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -32,12 +32,12 @@ fn main() { dst.push("./build"); println!("cargo:rustc-link-lib={}", target); - if cfg!(unix) { - println!("cargo:rustc-link-search=native={}", dst.display()); - println!("cargo:rustc-link-lib=dylib=stdc++"); - } else { + if cfg!(windows) { println!("cargo:rustc-link-search=native={}/{}", dst.display(), build_type); println!("cargo:rustc-link-lib=dylib=mincore"); + } else { + println!("cargo:rustc-link-search=native={}", dst.display()); + println!("cargo:rustc-link-lib=dylib=stdc++"); } if cfg!(target_os = "linux") { From 4cd531fc5586543f96e101ca928af219bd5fee9a Mon Sep 17 00:00:00 2001 From: schrodingerzhu Date: Sun, 2 Feb 2020 13:46:33 +0800 Subject: [PATCH 016/145] update version and sync snmalloc --- .gitmodules | 2 +- Cargo.toml | 4 ++-- snmalloc-sys/Cargo.toml | 2 +- snmalloc-sys/snmalloc | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitmodules b/.gitmodules index 1eb35324f..2bf92f3aa 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ -[submodule "snmalloc-sys/snmalloc"] +[submodule "new"] path = snmalloc-sys/snmalloc url = https://github.com/microsoft/snmalloc branch = master diff --git a/Cargo.toml b/Cargo.toml index b63cc7a8c..b68251ab3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.1" +version = "0.2.2" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -21,4 +21,4 @@ snmalloc-sys = {version = "0.2", path = "snmalloc-sys"} [features] 1mib = ["snmalloc-sys/1mib"] debug = ["snmalloc-sys/debug"] -cache-friendly = ["snmalloc-sys/cache-friendly"] \ No newline at end of file +cache-friendly = ["snmalloc-sys/cache-friendly"] diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index d50e3547a..fa5641058 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.1" +version = "0.2.2" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 2b2ab9153..7e22d302a 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 2b2ab91537b7862d514ac458e880d4225379419a +Subproject commit 7e22d302ad126dbb0cd2cd58ddf2aac915012fd7 From 86cbebe5aa54d5b40b6606c65b939eb8be76cb52 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 6 Feb 2020 07:39:42 +0000 Subject: [PATCH 017/145] Bump snmalloc-sys/snmalloc from `7e22d30` to `1d72024` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `7e22d30` to `1d72024`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/7e22d302ad126dbb0cd2cd58ddf2aac915012fd7...1d72024a9f9e5328a3618508821921b84c2d49c4) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 7e22d302a..1d72024a9 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 7e22d302ad126dbb0cd2cd58ddf2aac915012fd7 +Subproject commit 1d72024a9f9e5328a3618508821921b84c2d49c4 From eaa419e3709117131cc6271b03d51945eca708bd Mon Sep 17 00:00:00 2001 From: schrodingerzhu Date: Thu, 6 Feb 2020 23:19:59 +0800 Subject: [PATCH 018/145] sync the latest snmalloc 4367a0c --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 1d72024a9..4367a0cbd 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 1d72024a9f9e5328a3618508821921b84c2d49c4 +Subproject commit 4367a0cbdc910c435f89c8d013c6b3023ed79f0d From bcdb657894c4c01166f02646ea5f55bbe35691d6 Mon Sep 17 00:00:00 2001 From: schrodingerzhu Date: Thu, 6 Feb 2020 23:24:13 +0800 Subject: [PATCH 019/145] bump version to 0.2.3 --- Cargo.toml | 2 +- snmalloc-sys/Cargo.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b68251ab3..189bf8f2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.2" +version = "0.2.3" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index fa5641058..1decc4e80 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.2" +version = "0.2.3" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -22,4 +22,4 @@ default-features = false [features] 1mib = [] debug = [] -cache-friendly = [] \ No newline at end of file +cache-friendly = [] From 301c8e5a1da4856e1b63c55891fb21ec7a85941d Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Fri, 7 Feb 2020 15:25:48 +0000 Subject: [PATCH 020/145] Remove redundant requirement `snmalloc` now supports alignment of all allocations with https://github.com/microsoft/snmalloc/pull/124 This comment is no longer required. --- snmalloc-sys/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/snmalloc-sys/src/lib.rs b/snmalloc-sys/src/lib.rs index 72052cbd4..ec9d81aa0 100644 --- a/snmalloc-sys/src/lib.rs +++ b/snmalloc-sys/src/lib.rs @@ -10,7 +10,6 @@ extern "C" { /// On failure, it returns a null pointer. /// The client must assure the following things: /// - `alignment` is greater than zero - /// - `alignment` is less equal to `SUPERSLAB_SIZE` (defined in snmalloc) /// - `alignment` is of the power of 2 /// The program may be forced to abort if the constrains are not full-filled. pub fn rust_alloc(alignment: size_t, size: size_t) -> *mut c_void; From 1aef969bfc0d28bf04a78ad4fa3036d1c0e3602b Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Fri, 7 Feb 2020 15:29:06 +0000 Subject: [PATCH 021/145] Typo --- snmalloc-sys/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/src/lib.rs b/snmalloc-sys/src/lib.rs index ec9d81aa0..70fce613a 100644 --- a/snmalloc-sys/src/lib.rs +++ b/snmalloc-sys/src/lib.rs @@ -10,7 +10,7 @@ extern "C" { /// On failure, it returns a null pointer. /// The client must assure the following things: /// - `alignment` is greater than zero - /// - `alignment` is of the power of 2 + /// - `alignment` is a power of 2 /// The program may be forced to abort if the constrains are not full-filled. pub fn rust_alloc(alignment: size_t, size: size_t) -> *mut c_void; From b31dda3a693ea0dbd87aab086f3790894ee68749 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 11 Feb 2020 07:32:54 +0000 Subject: [PATCH 022/145] Bump snmalloc-sys/snmalloc from `4367a0c` to `3775a62` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `4367a0c` to `3775a62`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/4367a0cbdc910c435f89c8d013c6b3023ed79f0d...3775a625a4290bc1c3bddf3ce14ba33f1c324fca) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 4367a0cbd..3775a625a 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 4367a0cbdc910c435f89c8d013c6b3023ed79f0d +Subproject commit 3775a625a4290bc1c3bddf3ce14ba33f1c324fca From e1c18d547da2b67b1e8ced925566b04561e88a83 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Thu, 13 Feb 2020 10:11:35 +0800 Subject: [PATCH 023/145] bump version to 0.2.4 --- Cargo.toml | 2 +- snmalloc-sys/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 189bf8f2e..fe4bfc057 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.3" +version = "0.2.4" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 1decc4e80..1c3691ac4 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.3" +version = "0.2.4" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" From 6036054fdc0db0e67fae8faab0d9aeeb56827149 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 4 Mar 2020 00:27:02 +0000 Subject: [PATCH 024/145] Bump snmalloc-sys/snmalloc from `3775a62` to `ef77bcc` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `3775a62` to `ef77bcc`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/3775a625a4290bc1c3bddf3ce14ba33f1c324fca...ef77bccfc2bb2ab6e37b21f2fa08fd7edc1573b0) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 3775a625a..ef77bccfc 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 3775a625a4290bc1c3bddf3ce14ba33f1c324fca +Subproject commit ef77bccfc2bb2ab6e37b21f2fa08fd7edc1573b0 From 265c3d41427f7b07143212c33c86c23dbd28e6d6 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Wed, 4 Mar 2020 11:32:44 +0800 Subject: [PATCH 025/145] remove wrong item in documentation --- src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 527186abf..c4ad3f6af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,7 +37,6 @@ unsafe impl GlobalAlloc for SnMalloc { /// On failure, it returns a null pointer. /// The client must assure the following things: /// - `alignment` is greater than zero - /// - `alignment` is less equal to `SUPERSLAB_SIZE` (defined in snmalloc) /// - Other constrains are the same as the rust standard library. /// The program may be forced to abort if the constrains are not full-filled. #[inline(always)] @@ -107,4 +106,4 @@ mod tests { alloc.dealloc(ptr, layout); } } -} \ No newline at end of file +} From a358c33f2fa4715d4899949f1bd879db8c820b80 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Wed, 4 Mar 2020 11:35:06 +0800 Subject: [PATCH 026/145] bump version to 0.2.5 --- Cargo.toml | 2 +- snmalloc-sys/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fe4bfc057..d8d927fb7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.4" +version = "0.2.5" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 1c3691ac4..9757d522f 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.4" +version = "0.2.5" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" From d68fb78baaac8cbab108cfec81b2361c019ac06b Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 5 Mar 2020 07:29:47 +0000 Subject: [PATCH 027/145] Bump snmalloc-sys/snmalloc from `ef77bcc` to `51e9193` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `ef77bcc` to `51e9193`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/ef77bccfc2bb2ab6e37b21f2fa08fd7edc1573b0...51e919385fbb30a29e2ab815b9c122e0fbd7cf4b) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index ef77bccfc..51e919385 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit ef77bccfc2bb2ab6e37b21f2fa08fd7edc1573b0 +Subproject commit 51e919385fbb30a29e2ab815b9c122e0fbd7cf4b From 6b0c920a0bb786da89b315b92fc680b3d371c893 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu <118010469@link.cuhk.edu.cn> Date: Sun, 8 Mar 2020 11:25:54 +0800 Subject: [PATCH 028/145] refactor build.rs (#18) * refactor build.rs * try to add windows mingw * try to fix sh * allow mingw failures, will fix later --- .travis.yml | 16 ++++++++++++++++ snmalloc-sys/build.rs | 20 ++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9de32bf96..409a90a6e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ matrix: + env: ALLOW_FAILURES=0 include: - os: windows language: rust @@ -15,7 +16,19 @@ matrix: before_script: - rustup toolchain install nightly-x86_64-pc-windows-msvc - rustup default nightly-msvc + + - os: windows + language: rust + rust: + - stable + env: ALLOW_FAILURES=1 + - os: windows + language: rust + rust: + - nightly + env: ALLOW_FAILURES=1 + - os: linux language: rust rust: @@ -53,6 +66,9 @@ matrix: language: rust rust: - nightly + + allow_failures: + - env: ALLOW_FAILURES=1 diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 47fdc8fd6..43568062d 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -16,6 +16,10 @@ fn main() { cfg = cfg.define("CMAKE_CXX_FLAGS_RELEASE", "/MD /O2 /Ob2 /DNDEBUG"); cfg = cfg.define("CMAKE_C_FLAGS_RELEASE", "/MD /O2 /Ob2 /DNDEBUG"); } + + if cfg!(all(windows, target_env = "gnu")) { + cfg = cfg.define("CMAKE_SH", "CMAKE_SH-NOTFOUND"); + } let target = if cfg!(feature = "1mib") { "snmallocshim-1mib-rust" @@ -32,15 +36,23 @@ fn main() { dst.push("./build"); println!("cargo:rustc-link-lib={}", target); - if cfg!(windows) { + + if cfg!(all(windows, target_env = "msvc")) { println!("cargo:rustc-link-search=native={}/{}", dst.display(), build_type); - println!("cargo:rustc-link-lib=dylib=mincore"); } else { println!("cargo:rustc-link-search=native={}", dst.display()); - println!("cargo:rustc-link-lib=dylib=stdc++"); } - + + if cfg!(target_os = "windows") { + println!("cargo:rustc-link-lib=dylib=mincore"); + } + + if cfg!(target_os = "macos") { + println!("cargo:rustc-link-lib=dylib=c++"); + } + if cfg!(target_os = "linux") { + println!("cargo:rustc-link-lib=dylib=stdc++"); println!("cargo:rustc-link-lib=dylib=atomic"); } } From bef74645feca657477df1dc9a7a972ce4c929267 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu <118010469@link.cuhk.edu.cn> Date: Sun, 8 Mar 2020 12:30:40 +0800 Subject: [PATCH 029/145] Add Bsd Tests (#20) * try to test freebsd * try to test freebsd * try to fix freebsd image * no need of cache * install cmake * workaround oom * checkout Co-authored-by: SchrodingerZhu --- .cirrus.yml | 15 +++++++++++++++ snmalloc-sys/build.rs | 8 ++++++++ 2 files changed, 23 insertions(+) create mode 100644 .cirrus.yml diff --git a/.cirrus.yml b/.cirrus.yml new file mode 100644 index 000000000..a4e525470 --- /dev/null +++ b/.cirrus.yml @@ -0,0 +1,15 @@ +freebsd_instance: + image: freebsd-13-0-current-amd64-v20200220 +task: + name: cargo test (stable) + env: + HOME: /tmp # cargo needs it + install_script: | + pkg install -y rust + pkg install -y cmake + pkg install -y git + build_script: | + git submodule update --init + cargo build --all + test_script: cargo test --all --all-targets + diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 43568062d..03e5f8ec7 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -51,6 +51,14 @@ fn main() { println!("cargo:rustc-link-lib=dylib=c++"); } + if cfg!(target_os = "openbsd") { + println!("cargo:rustc-link-lib=dylib=c++"); + } + + if cfg!(target_os = "freebsd") { + println!("cargo:rustc-link-lib=dylib=c++"); + } + if cfg!(target_os = "linux") { println!("cargo:rustc-link-lib=dylib=stdc++"); println!("cargo:rustc-link-lib=dylib=atomic"); From 6bf9f130de32f6253ac366679c585aeb343ef5e2 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Sun, 8 Mar 2020 12:40:07 +0800 Subject: [PATCH 030/145] bump version to 0.2.6 --- Cargo.toml | 2 +- README.md | 16 ++++++++++++++-- snmalloc-sys/Cargo.toml | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d8d927fb7..a3d744035 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.5" +version = "0.2.6" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" diff --git a/README.md b/README.md index d435885f7..8d162c260 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,14 @@ # snmalloc-rs -![travis ci](https://www.travis-ci.org/SchrodingerZhu/snmalloc-rs.svg?branch=master) + +**Caution: MinGW is not supported currently** + +MSVC/MinGW/Linux/MacOS: [![travis ci](https://www.travis-ci.org/SchrodingerZhu/snmalloc-rs.svg?branch=master)](https://travis-ci.com/SchrodingerZhu/snmalloc-rs) + +FreeBSD: [![Build Status](https://api.cirrus-ci.com/github/SchrodingerZhu/snmalloc-rs.svg)](https://cirrus-ci.com/github/SchrodingerZhu/snmalloc-rs) `snmalloc-rs` provides a wrapper for [`microsoft/snmalloc`](https://github.com/microsoft/snmalloc) to make it usable as a global allocator for rust. snmalloc is a research allocator. Its key design features are: + - Memory that is freed by the same thread that allocated it does not require any synchronising operations. - Freeing memory in a different thread to initially allocated it, does not take any locks and instead uses a novel message passing scheme to return the memory to the original allocator, where it is recycled. - The allocator uses large ranges of pages to reduce the amount of meta-data required. @@ -24,4 +30,10 @@ To set `SnMalloc` as the global allocator add this to your project: ```rust #[global_allocator] static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc; -``` \ No newline at end of file +``` + +## Changelog +### 0.2.6 +- fix `macos`/`freebsd ` support +- add more ci tests +- mark the `mingw` problem diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 9757d522f..da276fa03 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.5" +version = "0.2.6" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" From 51cf70d02e04495ab0aabfca088d7d2778e8ad0e Mon Sep 17 00:00:00 2001 From: SchrodingerZhu <118010469@link.cuhk.edu.cn> Date: Wed, 11 Mar 2020 14:02:51 +0800 Subject: [PATCH 031/145] fix mingw partly (#23) * fix mingw x1 * try msys2 * workaround mingw64 * fix doc * adjust linking order * fix CI config * remove stable --- .travis.yml | 55 +++++++++++++++++++++++++++++++------------ snmalloc-sys/build.rs | 13 ++++++++-- snmalloc-sys/snmalloc | 2 +- 3 files changed, 52 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 409a90a6e..0dfd1c4c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,12 @@ matrix: - env: ALLOW_FAILURES=0 include: + - os: windows + language: rust + rust: + - nightly + env: + - MINGW64_BIN=C:\\tools\\msys64\\mingw64\\bin + - os: windows language: rust rust: @@ -16,19 +22,7 @@ matrix: before_script: - rustup toolchain install nightly-x86_64-pc-windows-msvc - rustup default nightly-msvc - - - os: windows - language: rust - rust: - - stable - env: ALLOW_FAILURES=1 - - os: windows - language: rust - rust: - - nightly - env: ALLOW_FAILURES=1 - - os: linux language: rust rust: @@ -67,11 +61,42 @@ matrix: rust: - nightly - allow_failures: - - env: ALLOW_FAILURES=1 +before_install: +- |- + case $TRAVIS_OS_NAME in + windows) + [[ ! -f C:/tools/msys64/msys2_shell.cmd ]] && rm -rf C:/tools/msys64 + choco uninstall -y mingw + choco upgrade --no-progress -y msys2 + export msys2='cmd //C RefreshEnv.cmd ' + export msys2+='& set MSYS=winsymlinks:nativestrict ' + export msys2+='& C:\\tools\\msys64\\msys2_shell.cmd -defterm -no-start' + export mingw64="$msys2 -mingw64 -full-path -here -c "\"\$@"\" --" + export msys2+=" -msys2 -c "\"\$@"\" --" + $msys2 pacman --sync --noconfirm --needed mingw-w64-x86_64-toolchain + ## Install more MSYS2 packages from https://packages.msys2.org/base here + taskkill //IM gpg-agent.exe //F # https://travis-ci.community/t/4967 + export PATH=/C/tools/msys64/mingw64/bin:$PATH + export MAKE=mingw32-make # so that Autotools can find it + ;; + esac +before_cache: +- |- + case $TRAVIS_OS_NAME in + windows) + # https://unix.stackexchange.com/a/137322/107554 + $msys2 pacman --sync --clean --noconfirm + ;; + esac + +cache: + directories: + - $HOME/AppData/Local/Temp/chocolatey + - /C/tools/msys64 + script: - cargo test --all - cargo test --all --features 1mib diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 03e5f8ec7..5d7e42179 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -38,13 +38,22 @@ fn main() { println!("cargo:rustc-link-lib={}", target); if cfg!(all(windows, target_env = "msvc")) { + println!("cargo:rustc-link-lib=dylib=mincore"); println!("cargo:rustc-link-search=native={}/{}", dst.display(), build_type); } else { println!("cargo:rustc-link-search=native={}", dst.display()); } - if cfg!(target_os = "windows") { - println!("cargo:rustc-link-lib=dylib=mincore"); + if cfg!(all(windows, target_env = "gnu")) { + let path = std::env::var("MINGW64_BIN").unwrap_or_else(|_| { + eprintln!("please set MINGW64_BIN so that we can link atomic library"); + std::process::exit(1); + }); + println!("cargo:rustc-link-search=native={}", path); + println!("cargo:rustc-link-lib=dylib=stdc++"); + println!("cargo:rustc-link-lib=dylib=atomic-1"); // TODO: fix me + println!("cargo:rustc-link-lib=dylib=pthread"); + println!("cargo:rustc-link-lib=dylib=gcc_s"); } if cfg!(target_os = "macos") { diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 51e919385..31da639f4 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 51e919385fbb30a29e2ab815b9c122e0fbd7cf4b +Subproject commit 31da639f496cbb5f0b561602fecaec63cf702a16 From d349e7530e1881e1b57874f7bd98bdaaf3dc53ac Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 11 Mar 2020 06:05:14 +0000 Subject: [PATCH 032/145] Bump snmalloc-sys/snmalloc from `31da639` to `76eaf1a` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `31da639` to `76eaf1a`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/31da639f496cbb5f0b561602fecaec63cf702a16...76eaf1adad66edcdf02510eef4168198e4ea11f5) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 31da639f4..76eaf1ada 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 31da639f496cbb5f0b561602fecaec63cf702a16 +Subproject commit 76eaf1adad66edcdf02510eef4168198e4ea11f5 From d964b7290787d201f3812110cf2dfbf135a68f5e Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 12 Mar 2020 07:27:21 +0000 Subject: [PATCH 033/145] Bump snmalloc-sys/snmalloc from `76eaf1a` to `8e3efcb` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `76eaf1a` to `8e3efcb`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/76eaf1adad66edcdf02510eef4168198e4ea11f5...8e3efcb1dcb27a5b43b66778a6c61681365f945f) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 76eaf1ada..8e3efcb1d 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 76eaf1adad66edcdf02510eef4168198e4ea11f5 +Subproject commit 8e3efcb1dcb27a5b43b66778a6c61681365f945f From da92e5a9c1365f303fe2ba5d07b79b0622431ba0 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Fri, 13 Mar 2020 15:49:58 +0800 Subject: [PATCH 034/145] bump version to 0.2.7 --- Cargo.toml | 2 +- README.md | 18 ++++++++++++++---- snmalloc-sys/Cargo.toml | 2 +- snmalloc-sys/build.rs | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a3d744035..038ca010a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.6" +version = "0.2.7" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" diff --git a/README.md b/README.md index 8d162c260..a6a65bacf 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,4 @@ # snmalloc-rs - -**Caution: MinGW is not supported currently** - MSVC/MinGW/Linux/MacOS: [![travis ci](https://www.travis-ci.org/SchrodingerZhu/snmalloc-rs.svg?branch=master)](https://travis-ci.com/SchrodingerZhu/snmalloc-rs) FreeBSD: [![Build Status](https://api.cirrus-ci.com/github/SchrodingerZhu/snmalloc-rs.svg)](https://cirrus-ci.com/github/SchrodingerZhu/snmalloc-rs) @@ -31,8 +28,21 @@ To set `SnMalloc` as the global allocator add this to your project: #[global_allocator] static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc; ``` - +## For MinGW Users +`mingw` version is only tested on nighly branch. Due to the complexity of locating GNU libraries on Windows environment, +the library requests you to provide a `MINGW64_BIN` environment variable during compiling. Since `GCC` does not provide a option for us +to link `libatomic` statically, I have to use dynamic linking. Hence, please make sure the following libs are in your `PATH`: +- `winpthread` +- `atomic` +- `stdc++` +- `gcc_s` +This is the best thing I can do for current stage, if you have any better solution, please do help me to provide a better support for +`MinGW` ## Changelog +### 0.2.7 +- partially fixed `mingw` +- **upstream** remote dealloc refactor (higher performance) +- **upstream** remove extra assertions ### 0.2.6 - fix `macos`/`freebsd ` support - add more ci tests diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index da276fa03..da89b89ae 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.6" +version = "0.2.7" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 5d7e42179..6bdb8ae74 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -52,7 +52,7 @@ fn main() { println!("cargo:rustc-link-search=native={}", path); println!("cargo:rustc-link-lib=dylib=stdc++"); println!("cargo:rustc-link-lib=dylib=atomic-1"); // TODO: fix me - println!("cargo:rustc-link-lib=dylib=pthread"); + println!("cargo:rustc-link-lib=dylib=winpthread"); println!("cargo:rustc-link-lib=dylib=gcc_s"); } From 35f89afa81fd7772e8151024110cdef94e8deef0 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu <118010469@link.cuhk.edu.cn> Date: Fri, 13 Mar 2020 15:55:00 +0800 Subject: [PATCH 035/145] [ci skip] small fix on README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a6a65bacf..fbb1f640a 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ to link `libatomic` statically, I have to use dynamic linking. Hence, please mak - `atomic` - `stdc++` - `gcc_s` + This is the best thing I can do for current stage, if you have any better solution, please do help me to provide a better support for `MinGW` ## Changelog From 46e3208688d69ce8bf44fd65d001532e1863d1a4 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 18 Mar 2020 00:24:24 +0000 Subject: [PATCH 036/145] Bump snmalloc-sys/snmalloc from `8e3efcb` to `8d33e1b` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `8e3efcb` to `8d33e1b`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/8e3efcb1dcb27a5b43b66778a6c61681365f945f...8d33e1bb0f473d167cd3b0ae9df3917515e0d381) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 8e3efcb1d..8d33e1bb0 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 8e3efcb1dcb27a5b43b66778a6c61681365f945f +Subproject commit 8d33e1bb0f473d167cd3b0ae9df3917515e0d381 From 45d87ce378fc35795ecd0c8b4f75cda61f323727 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Wed, 18 Mar 2020 08:46:27 +0800 Subject: [PATCH 037/145] try arm64 --- .travis.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.travis.yml b/.travis.yml index 0dfd1c4c4..3cd6ee47b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,6 +51,36 @@ matrix: - CC=gcc-9 - CXX=g++-9 + - os: linux + arch: arm64 + language: rust + rust: + - stable + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-9 + env: + - CC=gcc-9 + - CXX=g++-9 + + - os: linux + arch: arm64 + language: rust + rust: + - nightly + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-9 + env: + - CC=gcc-9 + - CXX=g++-9 + - os: osx language: rust rust: From 5a16d2a76b12d683478a93c2bb40e876decf68be Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Wed, 18 Mar 2020 09:04:12 +0800 Subject: [PATCH 038/145] try arm64: bionic --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 3cd6ee47b..3460e36a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,7 @@ matrix: - rustup default nightly-msvc - os: linux + dist: bionic language: rust rust: - stable @@ -38,6 +39,7 @@ matrix: - CXX=g++-9 - os: linux + dist: bionic language: rust rust: - nightly @@ -52,6 +54,7 @@ matrix: - CXX=g++-9 - os: linux + dist: bionic arch: arm64 language: rust rust: @@ -67,6 +70,7 @@ matrix: - CXX=g++-9 - os: linux + dist: bionic arch: arm64 language: rust rust: From 5c54b8d407160b24479ed8d3e09f22bfb04648f8 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 19 Mar 2020 12:46:12 +0000 Subject: [PATCH 039/145] Bump snmalloc-sys/snmalloc from `8d33e1b` to `4246d9a` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `8d33e1b` to `4246d9a`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/8d33e1bb0f473d167cd3b0ae9df3917515e0d381...4246d9a06563462076e000feb0241515187d99f3) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 8d33e1bb0..4246d9a06 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 8d33e1bb0f473d167cd3b0ae9df3917515e0d381 +Subproject commit 4246d9a06563462076e000feb0241515187d99f3 From d6c7ee408ef5a7b2c6120c67afce3ebe54154cf6 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 20 Mar 2020 16:30:31 +0000 Subject: [PATCH 040/145] Bump snmalloc-sys/snmalloc from `4246d9a` to `60861ee` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `4246d9a` to `60861ee`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/4246d9a06563462076e000feb0241515187d99f3...60861eef445c309af0ea4dec4ffaf76b3c47adb6) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 4246d9a06..60861eef4 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 4246d9a06563462076e000feb0241515187d99f3 +Subproject commit 60861eef445c309af0ea4dec4ffaf76b3c47adb6 From bb16e4a642ce8356b3e8ab45f6400ef924dd4f73 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Sat, 21 Mar 2020 12:15:04 +0800 Subject: [PATCH 041/145] bump version to 0.2.8 --- Cargo.toml | 2 +- README.md | 7 +++++++ snmalloc-sys/Cargo.toml | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 038ca010a..d0b320cfb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.7" +version = "0.2.8" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" diff --git a/README.md b/README.md index fbb1f640a..6e7f6030b 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,13 @@ to link `libatomic` statically, I have to use dynamic linking. Hence, please mak This is the best thing I can do for current stage, if you have any better solution, please do help me to provide a better support for `MinGW` ## Changelog + +### 0.2.8 + +- More CI (**ARM64 on QEMU**) +- **upstream** ARM(32/64) support +- **upstream** x86-SGX support + ### 0.2.7 - partially fixed `mingw` - **upstream** remote dealloc refactor (higher performance) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index da89b89ae..87eea7b15 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.7" +version = "0.2.8" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" From c35e3b4dcdbf4d36d8f7e54aec7817a78dc8a0de Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 26 Mar 2020 07:30:33 +0000 Subject: [PATCH 042/145] Bump snmalloc-sys/snmalloc from `60861ee` to `77c4536` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `60861ee` to `77c4536`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/60861eef445c309af0ea4dec4ffaf76b3c47adb6...77c453600b458f42b39797d0a0c856b9bd1873c5) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 60861eef4..77c453600 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 60861eef445c309af0ea4dec4ffaf76b3c47adb6 +Subproject commit 77c453600b458f42b39797d0a0c856b9bd1873c5 From 1dabd0ae30449796545306cd4a0e2b1abf616f21 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 1 Apr 2020 07:45:59 +0000 Subject: [PATCH 043/145] Bump snmalloc-sys/snmalloc from `77c4536` to `d900e29` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `77c4536` to `d900e29`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/77c453600b458f42b39797d0a0c856b9bd1873c5...d900e294243ede0c1f4ccd2f04a8dd6fab78e1ed) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 77c453600..d900e2942 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 77c453600b458f42b39797d0a0c856b9bd1873c5 +Subproject commit d900e294243ede0c1f4ccd2f04a8dd6fab78e1ed From a88b7ebf8d05c89be266fbe14fe3ca270305654d Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Wed, 1 Apr 2020 16:01:17 +0800 Subject: [PATCH 044/145] version 0.2.9 --- .gitignore | 1 + CHANGELOG.md | 19 +++++++++++++++++++ Cargo.toml | 2 +- README.md | 10 +++++----- snmalloc-sys/Cargo.toml | 2 +- 5 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 CHANGELOG.md diff --git a/.gitignore b/.gitignore index a9d37c560..64f40ab29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ target Cargo.lock +.idea diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..fb43943bf --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,19 @@ +## Changelog +### 0.2.9 +- **upstream** fix OpenEnclave +- **upstream** adjust remote batch size (performance improved dramatically, see [benchmark](https://github.com/microsoft/snmalloc/pull/158#issuecomment-605816017) +- **upstream** improve slow path performance for allocation +### 0.2.8 + +- More CI (**ARM64 on QEMU**) +- **upstream** ARM(32/64) support +- **upstream** x86-SGX support + +### 0.2.7 +- partially fixed `mingw` +- **upstream** remote dealloc refactor (higher performance) +- **upstream** remove extra assertions +### 0.2.6 +- fix `macos`/`freebsd ` support +- add more ci tests +- mark the `mingw` problem diff --git a/Cargo.toml b/Cargo.toml index d0b320cfb..6bbda54f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.8" +version = "0.2.9" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" diff --git a/README.md b/README.md index 6e7f6030b..ae8c23f09 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,9 @@ to link `libatomic` statically, I have to use dynamic linking. Hence, please mak This is the best thing I can do for current stage, if you have any better solution, please do help me to provide a better support for `MinGW` ## Changelog - +### 0.2.9 - **upstream** fix OpenEnclave +- **upstream** adjust remote batch size (performance improved dramatically, see [benchmark](https://github.com/microsoft/snmalloc/pull/158#issuecomment-605816017) +- **upstream** improve slow path performance for allocation ### 0.2.8 - More CI (**ARM64 on QEMU**) @@ -51,7 +53,5 @@ This is the best thing I can do for current stage, if you have any better soluti - partially fixed `mingw` - **upstream** remote dealloc refactor (higher performance) - **upstream** remove extra assertions -### 0.2.6 -- fix `macos`/`freebsd ` support -- add more ci tests -- mark the `mingw` problem + +for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 87eea7b15..acb22260c 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.8" +version = "0.2.9" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" From f26b67ede27565167922dfa8a915d448f17f0b45 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 7 Apr 2020 14:43:13 +0000 Subject: [PATCH 045/145] Bump snmalloc-sys/snmalloc from `d900e29` to `74657d9` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `d900e29` to `74657d9`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/d900e294243ede0c1f4ccd2f04a8dd6fab78e1ed...74657d9dbc776a54f78b77896a9955ebce5c8076) Signed-off-by: dependabot-preview[bot] --- .travis.yml | 25 ++++--------------------- snmalloc-sys/snmalloc | 2 +- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3460e36a3..3f9c9a9d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,10 +48,11 @@ matrix: sources: - ubuntu-toolchain-r-test packages: - - g++-9 + - gcc-10 + - g++-10 env: - - CC=gcc-9 - - CXX=g++-9 + - CC=gcc-10 + - CXX=g++-10 - os: linux dist: bionic @@ -59,15 +60,6 @@ matrix: language: rust rust: - stable - addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-9 - env: - - CC=gcc-9 - - CXX=g++-9 - os: linux dist: bionic @@ -75,15 +67,6 @@ matrix: language: rust rust: - nightly - addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-9 - env: - - CC=gcc-9 - - CXX=g++-9 - os: osx language: rust diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index d900e2942..74657d9db 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit d900e294243ede0c1f4ccd2f04a8dd6fab78e1ed +Subproject commit 74657d9dbc776a54f78b77896a9955ebce5c8076 From 35d15393e32a3cff5c4a109a50009d1098f1874b Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 10 Apr 2020 23:06:57 +0000 Subject: [PATCH 046/145] Bump snmalloc-sys/snmalloc from `74657d9` to `cf9c2eb` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `74657d9` to `cf9c2eb`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/74657d9dbc776a54f78b77896a9955ebce5c8076...cf9c2eb9d95c5857dca552a6b10eb943528969fd) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 74657d9db..cf9c2eb9d 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 74657d9dbc776a54f78b77896a9955ebce5c8076 +Subproject commit cf9c2eb9d95c5857dca552a6b10eb943528969fd From 52f1bc1ae903b538cbde6508de25975ed3840509 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 13 Apr 2020 23:10:58 +0000 Subject: [PATCH 047/145] Bump snmalloc-sys/snmalloc from `cf9c2eb` to `cbaf0f7` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `cf9c2eb` to `cbaf0f7`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/cf9c2eb9d95c5857dca552a6b10eb943528969fd...cbaf0f78f2aca03e10a28c068a470f3ab9562917) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index cf9c2eb9d..cbaf0f78f 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit cf9c2eb9d95c5857dca552a6b10eb943528969fd +Subproject commit cbaf0f78f2aca03e10a28c068a470f3ab9562917 From 43260baf70ad19c7dad32069eaf14d906b4de72b Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Tue, 14 Apr 2020 07:43:35 +0800 Subject: [PATCH 048/145] bump version 0.2.10 --- CHANGELOG.md | 9 +++++++++ Cargo.toml | 4 ++-- README.md | 16 ++++++++++------ snmalloc-sys/Cargo.toml | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb43943bf..5c9265d87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,17 @@ ## Changelog +### 0.2.10 + +- follow upstream 0.4.0 +- **upstream** defense TLS teardown +- **upstream** adjust GCC warning +- **upstream** other release optimizations + ### 0.2.9 + - **upstream** fix OpenEnclave - **upstream** adjust remote batch size (performance improved dramatically, see [benchmark](https://github.com/microsoft/snmalloc/pull/158#issuecomment-605816017) - **upstream** improve slow path performance for allocation + ### 0.2.8 - More CI (**ARM64 on QEMU**) diff --git a/Cargo.toml b/Cargo.toml index 6bbda54f3..64845c039 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.9" +version = "0.2.10" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2", path = "snmalloc-sys"} +snmalloc-sys = {version = "0.2.10", path = "snmalloc-sys"} [features] 1mib = ["snmalloc-sys/1mib"] diff --git a/README.md b/README.md index ae8c23f09..045cd299f 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,16 @@ to link `libatomic` statically, I have to use dynamic linking. Hence, please mak This is the best thing I can do for current stage, if you have any better solution, please do help me to provide a better support for `MinGW` ## Changelog -### 0.2.9 - **upstream** fix OpenEnclave +## 0.2.10 + +- follow upstream 0.4.0 +- **upstream** defense TLS teardown +- **upstream** adjust GCC warning +- **upstream** other release optimizations + +### 0.2.9 + +- **upstream** fix OpenEnclave - **upstream** adjust remote batch size (performance improved dramatically, see [benchmark](https://github.com/microsoft/snmalloc/pull/158#issuecomment-605816017) - **upstream** improve slow path performance for allocation ### 0.2.8 @@ -49,9 +58,4 @@ This is the best thing I can do for current stage, if you have any better soluti - **upstream** ARM(32/64) support - **upstream** x86-SGX support -### 0.2.7 -- partially fixed `mingw` -- **upstream** remote dealloc refactor (higher performance) -- **upstream** remove extra assertions - for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index acb22260c..6ab2b340e 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.9" +version = "0.2.10" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" From b0c29cb815b48b1b135ce90770682ff7b52f44b2 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 16 Apr 2020 07:24:28 +0000 Subject: [PATCH 049/145] Bump snmalloc-sys/snmalloc from `cbaf0f7` to `0f5cc16` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `cbaf0f7` to `0f5cc16`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/cbaf0f78f2aca03e10a28c068a470f3ab9562917...0f5cc165e8f6dcb244c71cc89e35271dc53e0039) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index cbaf0f78f..0f5cc165e 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit cbaf0f78f2aca03e10a28c068a470f3ab9562917 +Subproject commit 0f5cc165e8f6dcb244c71cc89e35271dc53e0039 From ba724c217ffc63e70fcb80d7f11340963381a23a Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Thu, 16 Apr 2020 20:45:02 +0800 Subject: [PATCH 050/145] android build script --- snmalloc-sys/build.rs | 21 ++++++++++++++++++++- snmalloc-sys/snmalloc | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 6bdb8ae74..9dfa7a16b 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -12,6 +12,25 @@ fn main() { cfg = cfg.define("SNMALLOC_RUST_SUPPORT", "ON") .profile(build_type); + let triple = std::env::var("TARGET").unwrap(); + if triple.contains("android") { + if let Ok(ndk) = std::env::var("ANDROID_NDK") { + cfg = cfg.define("CMAKE_TOOLCHAIN_FILE", format!("{}/build/cmake/android.toolchain.cmake", ndk)); + } else { + eprintln!("please set ANDROID_NDK environment variable"); + std::process::abort(); + } + if cfg!(target_arch="aarch64") { + cfg = cfg.define("ANDROID_ABI", "arm64-v8a"); + } else if cfg!(target_arch="arm") { + cfg = cfg.define("ANDROID_ABI", "armeabi-v7a"); + } else if cfg!(target_arch="x86") { + cfg = cfg.define("ANDROID_ABI", "x86"); + } else if cfg!(target_arch="x86_64") { + cfg = cfg.define("ANDROID_ABI", "x86_64"); + } + } + if cfg!(all(windows, target_env = "msvc")) { cfg = cfg.define("CMAKE_CXX_FLAGS_RELEASE", "/MD /O2 /Ob2 /DNDEBUG"); cfg = cfg.define("CMAKE_C_FLAGS_RELEASE", "/MD /O2 /Ob2 /DNDEBUG"); @@ -47,7 +66,7 @@ fn main() { if cfg!(all(windows, target_env = "gnu")) { let path = std::env::var("MINGW64_BIN").unwrap_or_else(|_| { eprintln!("please set MINGW64_BIN so that we can link atomic library"); - std::process::exit(1); + std::process::abort(); }); println!("cargo:rustc-link-search=native={}", path); println!("cargo:rustc-link-lib=dylib=stdc++"); diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 0f5cc165e..a43773c5b 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 0f5cc165e8f6dcb244c71cc89e35271dc53e0039 +Subproject commit a43773c5b7e1fc291ddd1580fec04a574ef886e1 From 30e5f56e88873c6e2e2cd77c3896882891b254a3 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Tue, 21 Apr 2020 09:41:00 +0800 Subject: [PATCH 051/145] use TARGET to detect all --- Cargo.toml | 2 ++ snmalloc-sys/Cargo.toml | 2 ++ snmalloc-sys/build.rs | 31 +++++++++++++++++++++++++------ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 64845c039..72fc9da6d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,3 +22,5 @@ snmalloc-sys = {version = "0.2.10", path = "snmalloc-sys"} 1mib = ["snmalloc-sys/1mib"] debug = ["snmalloc-sys/debug"] cache-friendly = ["snmalloc-sys/cache-friendly"] +android-lld = ["snmalloc-sys/android-lld"] +android-shared-stl = ["snmalloc-sys/android-shared-stl"] diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 6ab2b340e..809594bdd 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -23,3 +23,5 @@ default-features = false 1mib = [] debug = [] cache-friendly = [] +android-lld = [] +android-shared-stl = [] \ No newline at end of file diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 9dfa7a16b..9ce6509de 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -20,14 +20,33 @@ fn main() { eprintln!("please set ANDROID_NDK environment variable"); std::process::abort(); } - if cfg!(target_arch="aarch64") { + + if let Ok(platform) = std::env::var("ANDROID_PLATFORM") { + cfg = cfg.define("ANDROID_PLATFORM", platform); + } + + if cfg!(feature = "android-lld") { + cfg = cfg.define("ANDROID_LD", "lld"); + } + + if cfg!(feature = "android-shared-stl") { + println!("cargo:rustc-link-lib=dylib=c++_shared"); + cfg = cfg.define("ANDROID_STL", "c++_shared"); + } + + if triple.contains("aarch64") { cfg = cfg.define("ANDROID_ABI", "arm64-v8a"); - } else if cfg!(target_arch="arm") { - cfg = cfg.define("ANDROID_ABI", "armeabi-v7a"); - } else if cfg!(target_arch="x86") { - cfg = cfg.define("ANDROID_ABI", "x86"); - } else if cfg!(target_arch="x86_64") { + } else if triple.contains("armv7") { + cfg = cfg.define("ANDROID_ABI", "armeabi-v7a") + .define("ANDROID_ARM_MODE", "arm"); + } else if triple.contains("x86_64") { cfg = cfg.define("ANDROID_ABI", "x86_64"); + } else if triple.contains("i686") { + cfg = cfg.define("ANDROID_ABI", "x86_64"); + } else if triple.contains("neon") { + cfg = cfg.define("ANDROID_ABI", "armeabi-v7a with NEON") + } else if triple.contains("arm") { + cfg = cfg.define("ANDROID_ABI", "armeabi-v7a"); } } From b4ce1588359547e235cf9ddcf37e1991375806d8 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Tue, 21 Apr 2020 10:16:26 +0800 Subject: [PATCH 052/145] [ci skip] bump version to 0.2.11 --- CHANGELOG.md | 7 +++++++ Cargo.toml | 4 ++-- README.md | 21 +++++++++++++++++---- snmalloc-sys/Cargo.toml | 2 +- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c9265d87..f41bad4c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,11 @@ ## Changelog +## 0.2.11 + +- add android support +- **upstream** support x86 +- **upstream** support android +- **upstream** fix callback + ### 0.2.10 - follow upstream 0.4.0 diff --git a/Cargo.toml b/Cargo.toml index 72fc9da6d..5906ab0ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.10" +version = "0.2.11" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.10", path = "snmalloc-sys"} +snmalloc-sys = {version = "0.2.11", path = "snmalloc-sys"} [features] 1mib = ["snmalloc-sys/1mib"] diff --git a/README.md b/README.md index 045cd299f..7763e1702 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,24 @@ to link `libatomic` statically, I have to use dynamic linking. Hence, please mak This is the best thing I can do for current stage, if you have any better solution, please do help me to provide a better support for `MinGW` + +## For Androud Cross-Compilation + +- `ANDROID_NDK` must be provided as an environment variable +- `ANDROID_PLATFORM` can be passed as an optional environment variable +- `ANDROID_ABI` used by CMake is detected automatically +- feature `android-lld` can be used to set the linker of `snmalloc` to `lld` +- feature `androud-shared-std` can be used to set the STL library of `snmalloc` to `c++_shared` (it uses `c++_static` by default) + ## Changelog + +## 0.2.11 + +- add android support +- **upstream** support x86 +- **upstream** support android +- **upstream** fix callback + ## 0.2.10 - follow upstream 0.4.0 @@ -52,10 +69,6 @@ This is the best thing I can do for current stage, if you have any better soluti - **upstream** fix OpenEnclave - **upstream** adjust remote batch size (performance improved dramatically, see [benchmark](https://github.com/microsoft/snmalloc/pull/158#issuecomment-605816017) - **upstream** improve slow path performance for allocation -### 0.2.8 -- More CI (**ARM64 on QEMU**) -- **upstream** ARM(32/64) support -- **upstream** x86-SGX support for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 809594bdd..bc8dde153 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.10" +version = "0.2.11" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" From 46e278e031ade640889c175ccc7bbebc05b8e9a5 Mon Sep 17 00:00:00 2001 From: imkiva Date: Tue, 28 Apr 2020 18:05:40 +0800 Subject: [PATCH 053/145] mingw: try to detect lib search dirs --- snmalloc-sys/build.rs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 9ce6509de..28f350d90 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -83,13 +83,30 @@ fn main() { } if cfg!(all(windows, target_env = "gnu")) { - let path = std::env::var("MINGW64_BIN").unwrap_or_else(|_| { - eprintln!("please set MINGW64_BIN so that we can link atomic library"); - std::process::abort(); - }); - println!("cargo:rustc-link-search=native={}", path); + let stdout = std::process::Command::new("gcc") + .args(&["-print-search-dirs"]) + .output().unwrap_or_else(|_| { + eprintln!("Cannot run gcc.exe"); + std::process::abort(); + }) + .stdout; + + let outputs = String::from_utf8(stdout) + .unwrap_or_else(|_| { + eprintln!("gcc output contains non-utf8 characters"); + std::process::abort(); + }); + + outputs.lines() + .filter(|line| line.starts_with("libraries: =")) + .map(|line| line.split_at("libraries: =".len()).1) + .flat_map(|line| line.split(";")) + .for_each(|path| { + println!("cargo:rustc-link-search=native={}", path); + }); + println!("cargo:rustc-link-lib=dylib=stdc++"); - println!("cargo:rustc-link-lib=dylib=atomic-1"); // TODO: fix me + println!("cargo:rustc-link-lib=dylib=atomic-1"); println!("cargo:rustc-link-lib=dylib=winpthread"); println!("cargo:rustc-link-lib=dylib=gcc_s"); } From 584e18ad6d882c7efbfaaaf64cf7fa327077afc7 Mon Sep 17 00:00:00 2001 From: imkiva Date: Tue, 28 Apr 2020 19:50:26 +0800 Subject: [PATCH 054/145] mingw: link against atomic instead of atomic-1 --- snmalloc-sys/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 28f350d90..242c226a5 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -106,7 +106,7 @@ fn main() { }); println!("cargo:rustc-link-lib=dylib=stdc++"); - println!("cargo:rustc-link-lib=dylib=atomic-1"); + println!("cargo:rustc-link-lib=dylib=atomic"); println!("cargo:rustc-link-lib=dylib=winpthread"); println!("cargo:rustc-link-lib=dylib=gcc_s"); } From 95e34525adf7bf4477ccd9cbf1760fce7f3a60f8 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Wed, 29 Apr 2020 14:01:19 +0800 Subject: [PATCH 055/145] update version and docs --- CHANGELOG.md | 10 +++++++++- Cargo.toml | 4 ++-- README.md | 34 ++++++++++++++++++---------------- snmalloc-sys/Cargo.toml | 4 ++-- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f41bad4c5..16c167a11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Changelog -## 0.2.11 + +### 0.2.12 + +- improve mingw support + +### 0.2.11 - add android support - **upstream** support x86 @@ -26,10 +31,13 @@ - **upstream** x86-SGX support ### 0.2.7 + - partially fixed `mingw` - **upstream** remote dealloc refactor (higher performance) - **upstream** remove extra assertions + ### 0.2.6 + - fix `macos`/`freebsd ` support - add more ci tests - mark the `mingw` problem diff --git a/Cargo.toml b/Cargo.toml index 5906ab0ed..b148e4c75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.11" +version = "0.2.12" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.11", path = "snmalloc-sys"} +snmalloc-sys = {version = "0.2.12", path = "snmalloc-sys"} [features] 1mib = ["snmalloc-sys/1mib"] diff --git a/README.md b/README.md index 7763e1702..aa169fb94 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,16 @@ snmalloc is a research allocator. Its key design features are: - Freeing memory in a different thread to initially allocated it, does not take any locks and instead uses a novel message passing scheme to return the memory to the original allocator, where it is recycled. - The allocator uses large ranges of pages to reduce the amount of meta-data required. -Some old benchmark results are available in the [`snmalloc` paper](https://github.com/microsoft/snmalloc/blob/master/snmalloc.pdf). +Some old benchmark results are available in the [`snmalloc` paper](https://github.com/microsoft/snmalloc/blob/master/snmalloc.pdf). Some recent benchmark results are listed at +[bench_suite](https://github.com/SchrodingerZhu/bench_suite). There are three features defined in this crate: + - `debug`: Enable the `Debug` mode in `snmalloc`. - `1mib`: Use the `1mib` chunk configuration. - `cache-friendly`: Make the allocator more cache friendly (setting `CACHE_FRIENDLY_OFFSET` to `64` in building the library). To use `snmalloc-rs` add it as a dependency: + ```toml # Cargo.toml [dependencies] @@ -24,21 +27,23 @@ snmalloc-rs = "0.2" ``` To set `SnMalloc` as the global allocator add this to your project: + ```rust #[global_allocator] static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc; ``` + ## For MinGW Users -`mingw` version is only tested on nighly branch. Due to the complexity of locating GNU libraries on Windows environment, -the library requests you to provide a `MINGW64_BIN` environment variable during compiling. Since `GCC` does not provide a option for us -to link `libatomic` statically, I have to use dynamic linking. Hence, please make sure the following libs are in your `PATH`: + +`mingw` version is only tested on nightly branch with MSYS environment. We are using dynamic linking method. +Hence, please make sure the following libs are in your `PATH`: + - `winpthread` - `atomic` - `stdc++` - `gcc_s` -This is the best thing I can do for current stage, if you have any better solution, please do help me to provide a better support for -`MinGW` +**Notice:** since version `0.2.12`, we no longer require you to provide additional environment variables for `mingw` target. ## For Androud Cross-Compilation @@ -46,29 +51,26 @@ This is the best thing I can do for current stage, if you have any better soluti - `ANDROID_PLATFORM` can be passed as an optional environment variable - `ANDROID_ABI` used by CMake is detected automatically - feature `android-lld` can be used to set the linker of `snmalloc` to `lld` -- feature `androud-shared-std` can be used to set the STL library of `snmalloc` to `c++_shared` (it uses `c++_static` by default) +- feature `android-shared-std` can be used to set the STL library of `snmalloc` to `c++_shared` (it uses `c++_static` by default) ## Changelog -## 0.2.11 +### 0.2.12 + +- improve mingw support + +### 0.2.11 - add android support - **upstream** support x86 - **upstream** support android - **upstream** fix callback -## 0.2.10 +### 0.2.10 - follow upstream 0.4.0 - **upstream** defense TLS teardown - **upstream** adjust GCC warning - **upstream** other release optimizations -### 0.2.9 - -- **upstream** fix OpenEnclave -- **upstream** adjust remote batch size (performance improved dramatically, see [benchmark](https://github.com/microsoft/snmalloc/pull/158#issuecomment-605816017) -- **upstream** improve slow path performance for allocation - - for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index bc8dde153..81494307d 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.11" +version = "0.2.12" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -24,4 +24,4 @@ default-features = false debug = [] cache-friendly = [] android-lld = [] -android-shared-stl = [] \ No newline at end of file +android-shared-stl = [] From cd7959844ff0242bc0484ceb3a3954066a610019 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 7 May 2020 06:02:05 +0000 Subject: [PATCH 056/145] Bump snmalloc-sys/snmalloc from `a43773c` to `c899ee7` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `a43773c` to `c899ee7`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/a43773c5b7e1fc291ddd1580fec04a574ef886e1...c899ee7ab22362935bb5b16687096346703ef02a) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index a43773c5b..c899ee7ab 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit a43773c5b7e1fc291ddd1580fec04a574ef886e1 +Subproject commit c899ee7ab22362935bb5b16687096346703ef02a From cbd27e65336dd7273036e35462efba33fab0b614 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 7 May 2020 14:58:54 +0000 Subject: [PATCH 057/145] Bump snmalloc-sys/snmalloc from `c899ee7` to `4347701` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `c899ee7` to `4347701`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/c899ee7ab22362935bb5b16687096346703ef02a...4347701d33f96e42eaf4d4914ca6da4a9a006c51) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index c899ee7ab..4347701d3 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit c899ee7ab22362935bb5b16687096346703ef02a +Subproject commit 4347701d33f96e42eaf4d4914ca6da4a9a006c51 From e09ffe22205fe98e58eaa8fd5e87024415dd0015 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Sat, 9 May 2020 14:03:44 +0800 Subject: [PATCH 058/145] bump the version to 0.2.13 --- CHANGELOG.md | 4 ++++ Cargo.toml | 4 ++-- README.md | 12 +++++------- snmalloc-sys/Cargo.toml | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16c167a11..5ae756b98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +### 0.2.13 + +- **upstream** large realloc fix and minor updates + ### 0.2.12 - improve mingw support diff --git a/Cargo.toml b/Cargo.toml index b148e4c75..752356f75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.12" +version = "0.2.13" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.12", path = "snmalloc-sys"} +snmalloc-sys = {version = "0.2.13", path = "snmalloc-sys"} [features] 1mib = ["snmalloc-sys/1mib"] diff --git a/README.md b/README.md index aa169fb94..2df06412f 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Hence, please make sure the following libs are in your `PATH`: **Notice:** since version `0.2.12`, we no longer require you to provide additional environment variables for `mingw` target. -## For Androud Cross-Compilation +## For Android Cross-Compilation - `ANDROID_NDK` must be provided as an environment variable - `ANDROID_PLATFORM` can be passed as an optional environment variable @@ -55,6 +55,10 @@ Hence, please make sure the following libs are in your `PATH`: ## Changelog +### 0.2.13 + +- **upstream** large realloc fix and minor updates + ### 0.2.12 - improve mingw support @@ -66,11 +70,5 @@ Hence, please make sure the following libs are in your `PATH`: - **upstream** support android - **upstream** fix callback -### 0.2.10 - -- follow upstream 0.4.0 -- **upstream** defense TLS teardown -- **upstream** adjust GCC warning -- **upstream** other release optimizations for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 81494307d..0574d4adc 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.12" +version = "0.2.13" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" From a58874930b07a02474a860615c96daa4c571612d Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 20 May 2020 00:25:34 +0000 Subject: [PATCH 059/145] Bump snmalloc-sys/snmalloc from `4347701` to `958de73` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `4347701` to `958de73`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/4347701d33f96e42eaf4d4914ca6da4a9a006c51...958de73f5bfb5ab28b798031627af5400e048edc) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 4347701d3..958de73f5 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 4347701d33f96e42eaf4d4914ca6da4a9a006c51 +Subproject commit 958de73f5bfb5ab28b798031627af5400e048edc From 8f3b91b7cc209703f173bd990c1e44cb233cf423 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 25 May 2020 07:43:23 +0000 Subject: [PATCH 060/145] Bump snmalloc-sys/snmalloc from `958de73` to `87dfd41` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `958de73` to `87dfd41`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/958de73f5bfb5ab28b798031627af5400e048edc...87dfd41553198974fa70bc265b111492e1602289) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 958de73f5..87dfd4155 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 958de73f5bfb5ab28b798031627af5400e048edc +Subproject commit 87dfd41553198974fa70bc265b111492e1602289 From afbae5c4601162b35e512168fb738cf56bb1b07e Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 29 May 2020 07:18:41 +0000 Subject: [PATCH 061/145] Bump snmalloc-sys/snmalloc from `87dfd41` to `c7736a2` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `87dfd41` to `c7736a2`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/87dfd41553198974fa70bc265b111492e1602289...c7736a2defd718debf0317d6507ebb5177954d75) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 87dfd4155..c7736a2de 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 87dfd41553198974fa70bc265b111492e1602289 +Subproject commit c7736a2defd718debf0317d6507ebb5177954d75 From 6b0f8a1f2514b8050840f2207b97da4cd732a961 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu <118010469@link.cuhk.edu.cn> Date: Fri, 29 May 2020 23:12:41 +0800 Subject: [PATCH 062/145] sync w/ upstream and seperate CPU features (#62) * sync w/ upstream and seperate CPU features * turn off native-cpu --- CHANGELOG.md | 6 ++++++ Cargo.toml | 5 +++-- README.md | 15 +++++++-------- snmalloc-sys/Cargo.toml | 3 ++- snmalloc-sys/build.rs | 4 ++++ 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ae756b98..02420d4f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## Changelog +### 0.2.14 + +- **upstream** refactor ptr representation. +- **upstream** improve for more targets and architectures. +- seperate native CPU feature + ### 0.2.13 - **upstream** large realloc fix and minor updates diff --git a/Cargo.toml b/Cargo.toml index 752356f75..d2895c562 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.13" +version = "0.2.14" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.13", path = "snmalloc-sys"} +snmalloc-sys = {version = "0.2.14", path = "snmalloc-sys"} [features] 1mib = ["snmalloc-sys/1mib"] @@ -24,3 +24,4 @@ debug = ["snmalloc-sys/debug"] cache-friendly = ["snmalloc-sys/cache-friendly"] android-lld = ["snmalloc-sys/android-lld"] android-shared-stl = ["snmalloc-sys/android-shared-stl"] +native-cpu = ["snmalloc-sys/native-cpu"] diff --git a/README.md b/README.md index 2df06412f..928f9b8d8 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ There are three features defined in this crate: - `debug`: Enable the `Debug` mode in `snmalloc`. - `1mib`: Use the `1mib` chunk configuration. - `cache-friendly`: Make the allocator more cache friendly (setting `CACHE_FRIENDLY_OFFSET` to `64` in building the library). +- `native-cpu`: Optimize `snmalloc` for the native CPU of the host machine. (this is not a default behavior since `0.2.14`) To use `snmalloc-rs` add it as a dependency: @@ -55,6 +56,12 @@ Hence, please make sure the following libs are in your `PATH`: ## Changelog +### 0.2.14 + +- **upstream** refactor ptr representation. +- **upstream** improve for more targets and architectures. +- seperate native CPU feature + ### 0.2.13 - **upstream** large realloc fix and minor updates @@ -63,12 +70,4 @@ Hence, please make sure the following libs are in your `PATH`: - improve mingw support -### 0.2.11 - -- add android support -- **upstream** support x86 -- **upstream** support android -- **upstream** fix callback - - for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 0574d4adc..ad8231303 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.13" +version = "0.2.14" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -25,3 +25,4 @@ debug = [] cache-friendly = [] android-lld = [] android-shared-stl = [] +native-cpu = [] diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 242c226a5..08564902b 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -64,6 +64,10 @@ fn main() { } else { "snmallocshim-rust" }; + + if cfg!(feature = "native-cpu") { + cfg = cfg.define("SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE", "ON") + } let mut dst = if cfg!(feature = "cache-friendly") { cfg.define("CACHE_FRIENDLY_OFFSET", "64").build_target(target).build() From e45ff8f12c3162782b91d0f4694f1fe9a33a6d9e Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Mon, 8 Jun 2020 19:22:52 +0800 Subject: [PATCH 063/145] fix windows and sync w/ upstream --- .travis.yml | 40 ++++++---------------------------------- snmalloc-sys/snmalloc | 2 +- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3f9c9a9d1..f0fba0b2e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,14 +4,15 @@ matrix: language: rust rust: - nightly - env: - - MINGW64_BIN=C:\\tools\\msys64\\mingw64\\bin - os: windows language: rust rust: - stable before_script: + - choco install visualstudio2019community + - choco install visualstudio2019-workload-nativedesktop + - export VS160COMNTOOLS="/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools" - rustup toolchain install stable-x86_64-pc-windows-msvc - rustup default stable-msvc @@ -20,6 +21,9 @@ matrix: rust: - nightly before_script: + - choco install visualstudio2019community + - choco install visualstudio2019-workload-nativedesktop + - export VS160COMNTOOLS="/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools" - rustup toolchain install nightly-x86_64-pc-windows-msvc - rustup default nightly-msvc @@ -78,41 +82,9 @@ matrix: rust: - nightly - - -before_install: -- |- - case $TRAVIS_OS_NAME in - windows) - [[ ! -f C:/tools/msys64/msys2_shell.cmd ]] && rm -rf C:/tools/msys64 - choco uninstall -y mingw - choco upgrade --no-progress -y msys2 - export msys2='cmd //C RefreshEnv.cmd ' - export msys2+='& set MSYS=winsymlinks:nativestrict ' - export msys2+='& C:\\tools\\msys64\\msys2_shell.cmd -defterm -no-start' - export mingw64="$msys2 -mingw64 -full-path -here -c "\"\$@"\" --" - export msys2+=" -msys2 -c "\"\$@"\" --" - $msys2 pacman --sync --noconfirm --needed mingw-w64-x86_64-toolchain - ## Install more MSYS2 packages from https://packages.msys2.org/base here - taskkill //IM gpg-agent.exe //F # https://travis-ci.community/t/4967 - export PATH=/C/tools/msys64/mingw64/bin:$PATH - export MAKE=mingw32-make # so that Autotools can find it - ;; - esac - -before_cache: -- |- - case $TRAVIS_OS_NAME in - windows) - # https://unix.stackexchange.com/a/137322/107554 - $msys2 pacman --sync --clean --noconfirm - ;; - esac - cache: directories: - $HOME/AppData/Local/Temp/chocolatey - - /C/tools/msys64 script: - cargo test --all diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index c7736a2de..61afa7789 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit c7736a2defd718debf0317d6507ebb5177954d75 +Subproject commit 61afa77898d233586acf8567fd2dcc24caa611ab From 71b79522ce96cc1a1dd93078b888c80c4ee0341c Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Mon, 8 Jun 2020 19:36:57 +0800 Subject: [PATCH 064/145] bump version to 0.2.15 --- CHANGELOG.md | 5 +++++ Cargo.toml | 4 ++-- README.md | 9 +++++---- snmalloc-sys/Cargo.toml | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02420d4f4..02363d2dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Changelog +### 0.2.15 + +- **upstream** fix VS2019 build +- **upstream** fix wrong realloc behavior and performance issue + ### 0.2.14 - **upstream** refactor ptr representation. diff --git a/Cargo.toml b/Cargo.toml index d2895c562..828da94de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.14" +version = "0.2.15" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.14", path = "snmalloc-sys"} +snmalloc-sys = {version = "0.2.15", path = "snmalloc-sys"} [features] 1mib = ["snmalloc-sys/1mib"] diff --git a/README.md b/README.md index 928f9b8d8..cdacf0267 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,11 @@ Hence, please make sure the following libs are in your `PATH`: ## Changelog +### 0.2.15 + +- **upstream** fix VS2019 build +- **upstream** fix wrong realloc behavior and performance issue + ### 0.2.14 - **upstream** refactor ptr representation. @@ -66,8 +71,4 @@ Hence, please make sure the following libs are in your `PATH`: - **upstream** large realloc fix and minor updates -### 0.2.12 - -- improve mingw support - for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index ad8231303..30d3ec216 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.14" +version = "0.2.15" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" From ebd7f98bf7404eb7debc0bc1aef48bb18a6218fe Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 19 Jun 2020 15:40:52 +0800 Subject: [PATCH 065/145] Bump snmalloc-sys/snmalloc from `61afa77` to `e393ac8` (#65) Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `61afa77` to `e393ac8`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/61afa77898d233586acf8567fd2dcc24caa611ab...e393ac882f57d3d645df9a9f6eb3839e3d231271) Signed-off-by: dependabot-preview[bot] Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 61afa7789..e393ac882 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 61afa77898d233586acf8567fd2dcc24caa611ab +Subproject commit e393ac882f57d3d645df9a9f6eb3839e3d231271 From 09f34da82ff879c3851b85329f9e4370c7fc87a1 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Sun, 28 Jun 2020 19:57:33 +0800 Subject: [PATCH 066/145] sync w/ upstream --- CHANGELOG.md | 7 +++++++ Cargo.toml | 2 +- README.md | 13 +++++++++---- snmalloc-sys/Cargo.toml | 2 +- snmalloc-sys/snmalloc | 2 +- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02363d2dc..e931a39cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ ## Changelog +### 0.2.16 + +- **upstream** New implementation of address space reservation leading to + - better integration with transparent huge pages; and + - lower address space requirements and fragmentation. +- Notice MinGW broken state + ### 0.2.15 - **upstream** fix VS2019 build diff --git a/Cargo.toml b/Cargo.toml index 828da94de..02153065f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.15", path = "snmalloc-sys"} +snmalloc-sys = {version = "0.2.16", path = "snmalloc-sys"} [features] 1mib = ["snmalloc-sys/1mib"] diff --git a/README.md b/README.md index cdacf0267..54c991e93 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ # snmalloc-rs +**Notice: MinGW Build is broken and may not be fixed in a near futture. See [this PR](https://github.com/microsoft/snmalloc/pull/217) in the upstream.** + MSVC/MinGW/Linux/MacOS: [![travis ci](https://www.travis-ci.org/SchrodingerZhu/snmalloc-rs.svg?branch=master)](https://travis-ci.com/SchrodingerZhu/snmalloc-rs) FreeBSD: [![Build Status](https://api.cirrus-ci.com/github/SchrodingerZhu/snmalloc-rs.svg)](https://cirrus-ci.com/github/SchrodingerZhu/snmalloc-rs) @@ -56,6 +58,13 @@ Hence, please make sure the following libs are in your `PATH`: ## Changelog +### 0.2.16 + +- **upstream** New implementation of address space reservation leading to + - better integration with transparent huge pages; and + - lower address space requirements and fragmentation. +- Notice MinGW broken state + ### 0.2.15 - **upstream** fix VS2019 build @@ -67,8 +76,4 @@ Hence, please make sure the following libs are in your `PATH`: - **upstream** improve for more targets and architectures. - seperate native CPU feature -### 0.2.13 - -- **upstream** large realloc fix and minor updates - for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 30d3ec216..be434c4b9 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.15" +version = "0.2.16" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index e393ac882..94a2ba4ed 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit e393ac882f57d3d645df9a9f6eb3839e3d231271 +Subproject commit 94a2ba4eda931cd4d4fc1c786a748888b3fc982b From 07f41eb2609592c6917c39675bce04e497043fc6 Mon Sep 17 00:00:00 2001 From: Schrodinger ZHU Yifan <118010469@link.cuhk.edu.cn> Date: Sun, 28 Jun 2020 20:29:28 +0800 Subject: [PATCH 067/145] ci allow failure mingw (#69) * ci allow failure mingw * fix ci * [ci skip] typo --- .travis.yml | 6 ++++++ Cargo.toml | 2 +- README.md | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f0fba0b2e..25e5cc8fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ matrix: include: - os: windows language: rust + env: + - TOOLCHAIN=MinGW rust: - nightly @@ -81,6 +83,8 @@ matrix: language: rust rust: - nightly + allow_failures: + env: TOOLCHAIN=MinGW cache: directories: @@ -92,3 +96,5 @@ script: - cargo test --all --features debug - cargo test --all --features cache-friendly + + diff --git a/Cargo.toml b/Cargo.toml index 02153065f..d09af6bc5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.15" +version = "0.2.16" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" diff --git a/README.md b/README.md index 54c991e93..d1afb57b0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # snmalloc-rs -**Notice: MinGW Build is broken and may not be fixed in a near futture. See [this PR](https://github.com/microsoft/snmalloc/pull/217) in the upstream.** +**Notice: MinGW Build is broken and may not be fixed in a near future. See [this PR](https://github.com/microsoft/snmalloc/pull/217) in the upstream.** MSVC/MinGW/Linux/MacOS: [![travis ci](https://www.travis-ci.org/SchrodingerZhu/snmalloc-rs.svg?branch=master)](https://travis-ci.com/SchrodingerZhu/snmalloc-rs) From f93ed67d4614440c21eda445c48117d26b60efce Mon Sep 17 00:00:00 2001 From: Schrodinger ZHU Yifan <118010469@link.cuhk.edu.cn> Date: Thu, 9 Jul 2020 21:41:37 +0800 Subject: [PATCH 068/145] New memory configuration (#72) * update to snmalloc/4e1f582 * adjust feature flags * bump version to 0.2.17 --- CHANGELOG.md | 6 ++++++ Cargo.toml | 8 ++++++-- README.md | 19 ++++++++++++------- snmalloc-sys/Cargo.toml | 6 +++++- snmalloc-sys/build.rs | 34 ++++++++++++++++++++++------------ snmalloc-sys/snmalloc | 2 +- 6 files changed, 52 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e931a39cb..463a820d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## Changelog +### 0.2.17 + +- **upstream** add backoff for large reservation +- **upstream** default chunk configuration to 1mib +- add new feature flags + ### 0.2.16 - **upstream** New implementation of address space reservation leading to diff --git a/Cargo.toml b/Cargo.toml index d09af6bc5..1641731e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.16" +version = "0.2.17" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -16,10 +16,14 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.16", path = "snmalloc-sys"} +snmalloc-sys = {version = "0.2.17", path = "snmalloc-sys"} [features] +default = ["1mib"] 1mib = ["snmalloc-sys/1mib"] +16mib = ["snmalloc-sys/16mib"] +qemu = ["snmalloc-sys/qemu"] +stats = ["snmalloc-sys/stats"] debug = ["snmalloc-sys/debug"] cache-friendly = ["snmalloc-sys/cache-friendly"] android-lld = ["snmalloc-sys/android-lld"] diff --git a/README.md b/README.md index d1afb57b0..ada752153 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,14 @@ Some old benchmark results are available in the [`snmalloc` paper](https://githu There are three features defined in this crate: - `debug`: Enable the `Debug` mode in `snmalloc`. -- `1mib`: Use the `1mib` chunk configuration. +- `1mib`: Use the `1mib` chunk configuration. From `0.2.17`, this is set as a default feature +- `16mib`: Use the `16mib` chunk configuration. - `cache-friendly`: Make the allocator more cache friendly (setting `CACHE_FRIENDLY_OFFSET` to `64` in building the library). - `native-cpu`: Optimize `snmalloc` for the native CPU of the host machine. (this is not a default behavior since `0.2.14`) +- `qemu`: workaround `madvise` problem of QEMU environment +- `stats`: enable statistics + +**To get the crates compiled, you need to choose either `1mib` or `16mib` to determine the chunk configuration** To use `snmalloc-rs` add it as a dependency: @@ -58,6 +63,12 @@ Hence, please make sure the following libs are in your `PATH`: ## Changelog +### 0.2.17 + +- **upstream** add backoff for large reservation +- **upstream** default chunk configuration to 1mib +- add new feature flags + ### 0.2.16 - **upstream** New implementation of address space reservation leading to @@ -70,10 +81,4 @@ Hence, please make sure the following libs are in your `PATH`: - **upstream** fix VS2019 build - **upstream** fix wrong realloc behavior and performance issue -### 0.2.14 - -- **upstream** refactor ptr representation. -- **upstream** improve for more targets and architectures. -- seperate native CPU feature - for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index be434c4b9..ee2545569 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.16" +version = "0.2.17" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -20,7 +20,11 @@ version = "0.2" default-features = false [features] +default = ["1mib"] 1mib = [] +16mib = [] +qemu = [] +stats = [] debug = [] cache-friendly = [] android-lld = [] diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 08564902b..505b2bd26 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -54,21 +54,31 @@ fn main() { cfg = cfg.define("CMAKE_CXX_FLAGS_RELEASE", "/MD /O2 /Ob2 /DNDEBUG"); cfg = cfg.define("CMAKE_C_FLAGS_RELEASE", "/MD /O2 /Ob2 /DNDEBUG"); } - + if cfg!(all(windows, target_env = "gnu")) { cfg = cfg.define("CMAKE_SH", "CMAKE_SH-NOTFOUND"); } let target = if cfg!(feature = "1mib") { "snmallocshim-1mib-rust" + } else if cfg!(feature = "16mib") { + "snmallocshim-16mib-rust" } else { - "snmallocshim-rust" + panic!("please set a chunk configuration"); }; - + if cfg!(feature = "native-cpu") { cfg = cfg.define("SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE", "ON") } + if cfg!(feature = "stats") { + cfg = cfg.define("USE_SNMALLOC_STATS", "ON") + } + + if cfg!(feature = "qemu") { + cfg = cfg.define("SNMALLOC_QEMU_WORKAROUND", "ON") + } + let mut dst = if cfg!(feature = "cache-friendly") { cfg.define("CACHE_FRIENDLY_OFFSET", "64").build_target(target).build() } else { @@ -78,21 +88,21 @@ fn main() { dst.push("./build"); println!("cargo:rustc-link-lib={}", target); - + if cfg!(all(windows, target_env = "msvc")) { println!("cargo:rustc-link-lib=dylib=mincore"); println!("cargo:rustc-link-search=native={}/{}", dst.display(), build_type); } else { println!("cargo:rustc-link-search=native={}", dst.display()); } - + if cfg!(all(windows, target_env = "gnu")) { let stdout = std::process::Command::new("gcc") .args(&["-print-search-dirs"]) .output().unwrap_or_else(|_| { - eprintln!("Cannot run gcc.exe"); - std::process::abort(); - }) + eprintln!("Cannot run gcc.exe"); + std::process::abort(); + }) .stdout; let outputs = String::from_utf8(stdout) @@ -114,19 +124,19 @@ fn main() { println!("cargo:rustc-link-lib=dylib=winpthread"); println!("cargo:rustc-link-lib=dylib=gcc_s"); } - + if cfg!(target_os = "macos") { println!("cargo:rustc-link-lib=dylib=c++"); } - + if cfg!(target_os = "openbsd") { println!("cargo:rustc-link-lib=dylib=c++"); } - + if cfg!(target_os = "freebsd") { println!("cargo:rustc-link-lib=dylib=c++"); } - + if cfg!(target_os = "linux") { println!("cargo:rustc-link-lib=dylib=stdc++"); println!("cargo:rustc-link-lib=dylib=atomic"); diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 94a2ba4ed..4e1f5829a 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 94a2ba4eda931cd4d4fc1c786a748888b3fc982b +Subproject commit 4e1f5829a754ab9c170ec090979d3a670d2d5d1a From 56afdaed4cd31abf24451e5f87b66fe64460e25d Mon Sep 17 00:00:00 2001 From: kylixs Date: Thu, 30 Jul 2020 01:56:29 +0800 Subject: [PATCH 069/145] add msvc flag /EHsc to fix warning C4530 --- snmalloc-sys/build.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 505b2bd26..ea87a5a0c 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -51,8 +51,8 @@ fn main() { } if cfg!(all(windows, target_env = "msvc")) { - cfg = cfg.define("CMAKE_CXX_FLAGS_RELEASE", "/MD /O2 /Ob2 /DNDEBUG"); - cfg = cfg.define("CMAKE_C_FLAGS_RELEASE", "/MD /O2 /Ob2 /DNDEBUG"); + cfg = cfg.define("CMAKE_CXX_FLAGS_RELEASE", "/MD /O2 /Ob2 /DNDEBUG /EHsc"); + cfg = cfg.define("CMAKE_C_FLAGS_RELEASE", "/MD /O2 /Ob2 /DNDEBUG /EHsc"); } if cfg!(all(windows, target_env = "gnu")) { From 3b8be552e1335c7982a785519ae519f47ad560e3 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Thu, 30 Jul 2020 16:15:48 +0800 Subject: [PATCH 070/145] bump version to 0.2.18 --- CHANGELOG.md | 4 ++++ Cargo.toml | 4 ++-- README.md | 9 ++++----- snmalloc-sys/Cargo.toml | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 463a820d9..207dea807 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +### 0.2.18 + +- add msvc flag /EHsc to fix warning C4530 + ### 0.2.17 - **upstream** add backoff for large reservation diff --git a/Cargo.toml b/Cargo.toml index 1641731e6..226f02204 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.17" +version = "0.2.18" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.17", path = "snmalloc-sys"} +snmalloc-sys = {version = "0.2.18", path = "snmalloc-sys"} [features] default = ["1mib"] diff --git a/README.md b/README.md index ada752153..bd63d85b7 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,10 @@ Hence, please make sure the following libs are in your `PATH`: ## Changelog +### 0.2.18 + +- add msvc flag /EHsc to fix warning C4530 + ### 0.2.17 - **upstream** add backoff for large reservation @@ -76,9 +80,4 @@ Hence, please make sure the following libs are in your `PATH`: - lower address space requirements and fragmentation. - Notice MinGW broken state -### 0.2.15 - -- **upstream** fix VS2019 build -- **upstream** fix wrong realloc behavior and performance issue - for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index ee2545569..e6097f1ab 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.17" +version = "0.2.18" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" From f6cfb1d44da7d0bc5becf85a334017c3cf9dd817 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 6 Aug 2020 07:12:14 +0000 Subject: [PATCH 071/145] Bump snmalloc-sys/snmalloc from `4e1f582` to `c9b023b` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `4e1f582` to `c9b023b`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/4e1f5829a754ab9c170ec090979d3a670d2d5d1a...c9b023be239a8e2656d08735481ccce609df3b77) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 4e1f5829a..c9b023be2 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 4e1f5829a754ab9c170ec090979d3a670d2d5d1a +Subproject commit c9b023be239a8e2656d08735481ccce609df3b77 From 752008b70c0e6900bce10b5e02be338cd466ecb2 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Wed, 2 Sep 2020 17:17:46 +0800 Subject: [PATCH 072/145] update freebsd image --- .cirrus.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.cirrus.yml b/.cirrus.yml index a4e525470..f662c1406 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,5 +1,5 @@ freebsd_instance: - image: freebsd-13-0-current-amd64-v20200220 + image_family: freebsd-13-0-snap task: name: cargo test (stable) env: From 9e68ec5d88097a27caff252144a19a52e7c2b931 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Sat, 19 Sep 2020 22:24:03 +0800 Subject: [PATCH 073/145] workaround macos issue --- .travis.yml | 2 ++ snmalloc-sys/snmalloc | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 25e5cc8fb..ee5f101c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -75,11 +75,13 @@ matrix: - nightly - os: osx + osx_image: xcode12 language: rust rust: - stable - os: osx + osx_image: xcode12 language: rust rust: - nightly diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index c9b023be2..e615c33f7 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit c9b023be239a8e2656d08735481ccce609df3b77 +Subproject commit e615c33f7a1002d0209beaa4282c3981233f1fb1 From 964a296dd78557e91a6ca2629dd2c26eaedb1041 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Sat, 19 Sep 2020 22:45:05 +0800 Subject: [PATCH 074/145] bump version to 0.2.19 --- CHANGELOG.md | 7 +++++++ Cargo.toml | 4 ++-- README.md | 14 ++++++++------ snmalloc-sys/Cargo.toml | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 207dea807..5746db688 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ ## Changelog +### 0.2.19 + +- **upstream** stats +- **upstream** PAL updates and concepts +- **upstream** ddd constexpr annotation to align_up/down +- change macOS CI to follow xcode 12 + ### 0.2.18 - add msvc flag /EHsc to fix warning C4530 diff --git a/Cargo.toml b/Cargo.toml index 226f02204..a4c6add64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.18" +version = "0.2.19" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.18", path = "snmalloc-sys"} +snmalloc-sys = {version = "0.2.19", path = "snmalloc-sys"} [features] default = ["1mib"] diff --git a/README.md b/README.md index bd63d85b7..cf87c9f02 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,14 @@ Hence, please make sure the following libs are in your `PATH`: ## Changelog +### 0.2.19 + +- **upstream** stats +- **upstream** PAL updates and concepts +- **upstream** ddd constexpr annotation to align_up/down +- change macOS CI to follow xcode 12 + + ### 0.2.18 - add msvc flag /EHsc to fix warning C4530 @@ -73,11 +81,5 @@ Hence, please make sure the following libs are in your `PATH`: - **upstream** default chunk configuration to 1mib - add new feature flags -### 0.2.16 - -- **upstream** New implementation of address space reservation leading to - - better integration with transparent huge pages; and - - lower address space requirements and fragmentation. -- Notice MinGW broken state for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index e6097f1ab..71dd34e79 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.18" +version = "0.2.19" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" From 7f5e23ef0e2760d74354e8e475d2f810dc58ec3c Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 29 Sep 2020 06:12:40 +0000 Subject: [PATCH 075/145] Bump snmalloc-sys/snmalloc from `e615c33` to `923705e` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `e615c33` to `923705e`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/e615c33f7a1002d0209beaa4282c3981233f1fb1...923705e514e850ee0070cef470fca9d9c47ca3da) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index e615c33f7..923705e51 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit e615c33f7a1002d0209beaa4282c3981233f1fb1 +Subproject commit 923705e514e850ee0070cef470fca9d9c47ca3da From 3e4ce060d8be11ffbfa0767f9b8c0c33a78bbf68 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 6 Oct 2020 06:08:43 +0000 Subject: [PATCH 076/145] Bump snmalloc-sys/snmalloc from `923705e` to `49b9856` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `923705e` to `49b9856`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/923705e514e850ee0070cef470fca9d9c47ca3da...49b9856ed0f4681e41e16576aff968c817f19368) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 923705e51..49b9856ed 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 923705e514e850ee0070cef470fca9d9c47ca3da +Subproject commit 49b9856ed0f4681e41e16576aff968c817f19368 From 89efca143556cf9578bae1b71a7f2ce6af15ec0e Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 13 Oct 2020 01:44:36 +0000 Subject: [PATCH 077/145] Bump snmalloc-sys/snmalloc from `49b9856` to `0db4633` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `49b9856` to `0db4633`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/49b9856ed0f4681e41e16576aff968c817f19368...0db4633ee71fedecff7e774209a25250b7fd1e19) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 49b9856ed..0db4633ee 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 49b9856ed0f4681e41e16576aff968c817f19368 +Subproject commit 0db4633ee71fedecff7e774209a25250b7fd1e19 From ad553bcdb4f640706801089c3f9dbdbc5548e4dc Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 19 Oct 2020 06:11:17 +0000 Subject: [PATCH 078/145] Bump snmalloc-sys/snmalloc from `0db4633` to `8990c34` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `0db4633` to `8990c34`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/0db4633ee71fedecff7e774209a25250b7fd1e19...8990c349119bc848fe3c776ce02888d82abdef7f) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 0db4633ee..8990c3491 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 0db4633ee71fedecff7e774209a25250b7fd1e19 +Subproject commit 8990c349119bc848fe3c776ce02888d82abdef7f From 4b0a88e74acee2bf4d47c35d11027c5f60610931 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Sat, 24 Oct 2020 19:55:18 +0800 Subject: [PATCH 079/145] bump version to 0.2.20 --- CHANGELOG.md | 8 ++++++++ Cargo.toml | 4 ++-- README.md | 13 ++++++++----- snmalloc-sys/Cargo.toml | 2 +- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5746db688..e5410cbc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ ## Changelog +### 0.2.20 +- **upstream** pass through Haiku build fix. +- **upstream** fix typo in macro definition for 16MiB shared library shim. +- **upstream** DragonFly support (userland). +- **upstream** natural alignment for USE_MALLOC +- **upstream** fix bug in pagemap when index has many level +- **upstream** add constexpr annotation to align_up/down. + ### 0.2.19 - **upstream** stats diff --git a/Cargo.toml b/Cargo.toml index a4c6add64..b1a6ffff0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.19" +version = "0.2.20" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.19", path = "snmalloc-sys"} +snmalloc-sys = {version = "0.2.20", path = "snmalloc-sys"} [features] default = ["1mib"] diff --git a/README.md b/README.md index cf87c9f02..c0d858805 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,14 @@ Hence, please make sure the following libs are in your `PATH`: ## Changelog +### 0.2.20 +- **upstream** pass through Haiku build fix. +- **upstream** fix typo in macro definition for 16MiB shared library shim. +- **upstream** DragonFly support (userland). +- **upstream** natural alignment for USE_MALLOC +- **upstream** fix bug in pagemap when index has many level +- **upstream** add constexpr annotation to align_up/down. + ### 0.2.19 - **upstream** stats @@ -75,11 +83,6 @@ Hence, please make sure the following libs are in your `PATH`: - add msvc flag /EHsc to fix warning C4530 -### 0.2.17 - -- **upstream** add backoff for large reservation -- **upstream** default chunk configuration to 1mib -- add new feature flags for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 71dd34e79..2fd8641cb 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.19" +version = "0.2.20" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" From a8929272e4a74b4f66c8892494a44f153a5c169d Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 11 Nov 2020 06:11:02 +0000 Subject: [PATCH 080/145] Bump snmalloc-sys/snmalloc from `8990c34` to `2385eb2` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `8990c34` to `2385eb2`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/8990c349119bc848fe3c776ce02888d82abdef7f...2385eb2bc1956ccc7b6dc2cf7c52f61ffb7d08cf) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 8990c3491..2385eb2bc 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 8990c349119bc848fe3c776ce02888d82abdef7f +Subproject commit 2385eb2bc1956ccc7b6dc2cf7c52f61ffb7d08cf From 24f189b511c57e5b8b9e11b69d8bcbe371f3a5df Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Thu, 12 Nov 2020 14:19:45 +0800 Subject: [PATCH 081/145] bump version to 0.2.21 --- CHANGELOG.md | 5 +++++ Cargo.toml | 4 ++-- README.md | 12 +++++------- snmalloc-sys/Cargo.toml | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5410cbc9..16a6997cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ ## Changelog +### 0.2.21 + +- **upstream** bug fix for using failing to initialise meta-data + ### 0.2.20 + - **upstream** pass through Haiku build fix. - **upstream** fix typo in macro definition for 16MiB shared library shim. - **upstream** DragonFly support (userland). diff --git a/Cargo.toml b/Cargo.toml index b1a6ffff0..d4abe43f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.20" +version = "0.2.21" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.20", path = "snmalloc-sys"} +snmalloc-sys = {version = "0.2.21", path = "snmalloc-sys"} [features] default = ["1mib"] diff --git a/README.md b/README.md index c0d858805..bfdf9e036 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,12 @@ Hence, please make sure the following libs are in your `PATH`: ## Changelog +### 0.2.21 + +- **upstream** bug fix for using failing to initialise meta-data + ### 0.2.20 + - **upstream** pass through Haiku build fix. - **upstream** fix typo in macro definition for 16MiB shared library shim. - **upstream** DragonFly support (userland). @@ -78,11 +83,4 @@ Hence, please make sure the following libs are in your `PATH`: - **upstream** ddd constexpr annotation to align_up/down - change macOS CI to follow xcode 12 - -### 0.2.18 - -- add msvc flag /EHsc to fix warning C4530 - - - for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 2fd8641cb..287f77e30 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.20" +version = "0.2.21" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" From a3e8f0f923bdc2fbcb9cdf49acafb6714f36234d Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 3 Dec 2020 05:55:43 +0000 Subject: [PATCH 082/145] Bump snmalloc-sys/snmalloc from `2385eb2` to `3e7ea1a` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `2385eb2` to `3e7ea1a`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/2385eb2bc1956ccc7b6dc2cf7c52f61ffb7d08cf...3e7ea1a85f9620adccf48b31c67cd427fdd4321a) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 2385eb2bc..3e7ea1a85 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 2385eb2bc1956ccc7b6dc2cf7c52f61ffb7d08cf +Subproject commit 3e7ea1a85f9620adccf48b31c67cd427fdd4321a From 2e90d73515feaa9e9c92c58face5053add8d7b19 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 22 Dec 2020 05:56:37 +0000 Subject: [PATCH 083/145] Bump snmalloc-sys/snmalloc from `3e7ea1a` to `975a2bd` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `3e7ea1a` to `975a2bd`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/3e7ea1a85f9620adccf48b31c67cd427fdd4321a...975a2bd6db79adfc66b65ba11cffc83d5a10ba6c) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 3e7ea1a85..975a2bd6d 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 3e7ea1a85f9620adccf48b31c67cd427fdd4321a +Subproject commit 975a2bd6db79adfc66b65ba11cffc83d5a10ba6c From 882aad3263b2ae8305278207f3a39d5781dc7205 Mon Sep 17 00:00:00 2001 From: Schrodinger ZHU Date: Wed, 30 Dec 2020 16:47:13 +0800 Subject: [PATCH 084/145] bump version: 0.2.22 --- CHANGELOG.md | 8 ++++++++ Cargo.toml | 4 ++-- README.md | 17 +++++++++-------- snmalloc-sys/Cargo.toml | 2 +- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16a6997cf..e71caf2c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ ## Changelog +### 0.2.22 + +- **upstream** avoid amplification when routing +- **upstream** remotely store sizeclass +- **upstream** limit flat pagemap size +- **upstream** limit medium slab header +- **upstream** solaris support fix + ### 0.2.21 - **upstream** bug fix for using failing to initialise meta-data diff --git a/Cargo.toml b/Cargo.toml index d4abe43f3..52698409f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.21" +version = "0.2.22" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.21", path = "snmalloc-sys"} +snmalloc-sys = {version = "0.2.22", path = "snmalloc-sys"} [features] default = ["1mib"] diff --git a/README.md b/README.md index bfdf9e036..fd8372af0 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,14 @@ Hence, please make sure the following libs are in your `PATH`: ## Changelog +### 0.2.22 + +- **upstream** avoid amplification when routing +- **upstream** remotely store sizeclass +- **upstream** limit flat pagemap size +- **upstream** limit medium slab header +- **upstream** solaris support fix + ### 0.2.21 - **upstream** bug fix for using failing to initialise meta-data @@ -74,13 +82,6 @@ Hence, please make sure the following libs are in your `PATH`: - **upstream** DragonFly support (userland). - **upstream** natural alignment for USE_MALLOC - **upstream** fix bug in pagemap when index has many level -- **upstream** add constexpr annotation to align_up/down. - -### 0.2.19 - -- **upstream** stats -- **upstream** PAL updates and concepts -- **upstream** ddd constexpr annotation to align_up/down -- change macOS CI to follow xcode 12 +- **upstream** add constexpr annotation to align_up/down. for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 287f77e30..09e7bf0f1 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.21" +version = "0.2.22" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" From 9639c37469235a85db1bc48d2b1a4b310253d526 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 11 Jan 2021 06:16:56 +0000 Subject: [PATCH 085/145] Bump snmalloc-sys/snmalloc from `975a2bd` to `4837c82` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `975a2bd` to `4837c82`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/975a2bd6db79adfc66b65ba11cffc83d5a10ba6c...4837c8248912f3dda3df84e1b1345bcb4c29d2ab) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 975a2bd6d..4837c8248 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 975a2bd6db79adfc66b65ba11cffc83d5a10ba6c +Subproject commit 4837c8248912f3dda3df84e1b1345bcb4c29d2ab From c5c62e9b9c99ee3b78343b26b86a46c42c910dc6 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 14 Jan 2021 06:03:24 +0000 Subject: [PATCH 086/145] Bump snmalloc-sys/snmalloc from `4837c82` to `db3580a` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `4837c82` to `db3580a`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/4837c8248912f3dda3df84e1b1345bcb4c29d2ab...db3580a9d8fac394afa3efd6cc55027f269cd9dc) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 4837c8248..db3580a9d 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 4837c8248912f3dda3df84e1b1345bcb4c29d2ab +Subproject commit db3580a9d8fac394afa3efd6cc55027f269cd9dc From c071a20d0f700e841a3f648943962397c2396ae7 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Sun, 24 Jan 2021 16:17:11 +0800 Subject: [PATCH 087/145] bump version to 0.2.23 --- CHANGELOG.md | 4 ++++ Cargo.toml | 4 ++-- README.md | 13 ++++--------- snmalloc-sys/Cargo.toml | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e71caf2c1..6df761550 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +### 0.2.23 + +- **upstream** fix external pagemap usage + ### 0.2.22 - **upstream** avoid amplification when routing diff --git a/Cargo.toml b/Cargo.toml index 52698409f..e5486138a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.22" +version = "0.2.23" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.22", path = "snmalloc-sys"} +snmalloc-sys = {version = "0.2.23", path = "snmalloc-sys"} [features] default = ["1mib"] diff --git a/README.md b/README.md index fd8372af0..5a2b7a186 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,10 @@ Hence, please make sure the following libs are in your `PATH`: ## Changelog +### 0.2.23 + +- **upstream** fix external pagemap usage + ### 0.2.22 - **upstream** avoid amplification when routing @@ -75,13 +79,4 @@ Hence, please make sure the following libs are in your `PATH`: - **upstream** bug fix for using failing to initialise meta-data -### 0.2.20 - -- **upstream** pass through Haiku build fix. -- **upstream** fix typo in macro definition for 16MiB shared library shim. -- **upstream** DragonFly support (userland). -- **upstream** natural alignment for USE_MALLOC -- **upstream** fix bug in pagemap when index has many level -- **upstream** add constexpr annotation to align_up/down. - for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 09e7bf0f1..59436282a 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.22" +version = "0.2.23" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" From e24dc25f9fa3f8fa2a27f241b19a183c81ec72c0 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Tue, 2 Feb 2021 22:06:29 +0800 Subject: [PATCH 088/145] fix: remove /MD from cmake config --- snmalloc-sys/build.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index ea87a5a0c..533415b41 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -51,8 +51,8 @@ fn main() { } if cfg!(all(windows, target_env = "msvc")) { - cfg = cfg.define("CMAKE_CXX_FLAGS_RELEASE", "/MD /O2 /Ob2 /DNDEBUG /EHsc"); - cfg = cfg.define("CMAKE_C_FLAGS_RELEASE", "/MD /O2 /Ob2 /DNDEBUG /EHsc"); + cfg = cfg.define("CMAKE_CXX_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc"); + cfg = cfg.define("CMAKE_C_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc"); } if cfg!(all(windows, target_env = "gnu")) { From d87e93c8bab1ac6d7007eda8e47e93bd2612ea69 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 28 Jan 2021 05:51:39 +0000 Subject: [PATCH 089/145] Bump snmalloc-sys/snmalloc from `db3580a` to `a3660c4` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `db3580a` to `a3660c4`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/db3580a9d8fac394afa3efd6cc55027f269cd9dc...a3660c40690252e6bab884108f82e1ca822bc458) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index db3580a9d..a3660c406 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit db3580a9d8fac394afa3efd6cc55027f269cd9dc +Subproject commit a3660c40690252e6bab884108f82e1ca822bc458 From 2cbd2c30a38c71109b1f7dac8adaca840b33770b Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Wed, 3 Feb 2021 02:44:56 +0800 Subject: [PATCH 090/145] bump version to 0.2.24 --- CHANGELOG.md | 5 +++++ Cargo.toml | 4 ++-- README.md | 9 +++++---- snmalloc-sys/Cargo.toml | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6df761550..8c7d00caa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Changelog +### 0.2.24 + +- **upstream** update to use a more efficient power of 2 check +- fix msvc support w/ crt-static + ### 0.2.23 - **upstream** fix external pagemap usage diff --git a/Cargo.toml b/Cargo.toml index e5486138a..b3be1406d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.23" +version = "0.2.24" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.23", path = "snmalloc-sys"} +snmalloc-sys = {version = "0.2.24", path = "snmalloc-sys"} [features] default = ["1mib"] diff --git a/README.md b/README.md index 5a2b7a186..63933f14b 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,11 @@ Hence, please make sure the following libs are in your `PATH`: ## Changelog +### 0.2.24 + +- **upstream** update to use a more efficient power of 2 check +- fix msvc support w/ crt-static + ### 0.2.23 - **upstream** fix external pagemap usage @@ -75,8 +80,4 @@ Hence, please make sure the following libs are in your `PATH`: - **upstream** limit medium slab header - **upstream** solaris support fix -### 0.2.21 - -- **upstream** bug fix for using failing to initialise meta-data - for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 59436282a..74077e100 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.23" +version = "0.2.24" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" From c83b7bd79569db4ff74fa9ca01fc56438fab5a76 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Tue, 2 Feb 2021 17:40:47 +0000 Subject: [PATCH 091/145] Create rust.yml --- .github/workflows/rust.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/rust.yml diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 000000000..3c13d1be2 --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,22 @@ +name: Rust + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose From 874cc25a30069fc2681d5f867f3ca100ba36fb0d Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Tue, 2 Feb 2021 17:44:50 +0000 Subject: [PATCH 092/145] Pull submodule. --- .github/workflows/rust.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 3c13d1be2..a0cbdb4d4 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -15,7 +15,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: recursive - name: Build run: cargo build --verbose - name: Run tests From d55d893f374c7b39dad2bb410ffb2013922613f3 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Tue, 2 Feb 2021 17:48:12 +0000 Subject: [PATCH 093/145] Add platforms --- .github/workflows/rust.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a0cbdb4d4..e01d1ee8f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -12,7 +12,10 @@ env: jobs: build: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] steps: - name: Checkout From cd1f711c52c60cea8de7d8391956ae414ef9d3a2 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Tue, 2 Feb 2021 18:04:40 +0000 Subject: [PATCH 094/145] More options --- .github/workflows/rust.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e01d1ee8f..0a9bba795 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -16,8 +16,11 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] - + rust: [stable, nightly] steps: + - uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} - name: Checkout uses: actions/checkout@v2 with: @@ -25,4 +28,10 @@ jobs: - name: Build run: cargo build --verbose - name: Run tests - run: cargo test --verbose + run: cargo test --all + - name: Run tests 1mib + run: cargo test --all --features 1mib + - name: Run tests debug + run: cargo test --all --features debug + - name: Run tests cache-friendly + run: cargo test --all --features cache-friendly \ No newline at end of file From ab395b57b51c1a8d1cb320458b3a982a8ffdbad8 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 10 Feb 2021 05:59:36 +0000 Subject: [PATCH 095/145] Bump snmalloc-sys/snmalloc from `a3660c4` to `e3b3596` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `a3660c4` to `e3b3596`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/a3660c40690252e6bab884108f82e1ca822bc458...e3b3596e32768d80b46811f4c7cb75689fabfe5f) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index a3660c406..e3b3596e3 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit a3660c40690252e6bab884108f82e1ca822bc458 +Subproject commit e3b3596e32768d80b46811f4c7cb75689fabfe5f From fb21fc2ecbad8c15c197081e94da0f5a6090a756 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 12 Feb 2021 05:52:32 +0000 Subject: [PATCH 096/145] Bump snmalloc-sys/snmalloc from `e3b3596` to `ee470c5` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `e3b3596` to `ee470c5`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/e3b3596e32768d80b46811f4c7cb75689fabfe5f...ee470c535e258d93590488a4e1266bbe24dc90f1) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index e3b3596e3..ee470c535 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit e3b3596e32768d80b46811f4c7cb75689fabfe5f +Subproject commit ee470c535e258d93590488a4e1266bbe24dc90f1 From 3d63731ca5d284b904c1133cc4ce2c8f7a2bd25e Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 24 Feb 2021 05:52:00 +0000 Subject: [PATCH 097/145] Bump snmalloc-sys/snmalloc from `ee470c5` to `8840b38` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `ee470c5` to `8840b38`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/ee470c535e258d93590488a4e1266bbe24dc90f1...8840b386bc9af30503a7e3afbaa570b2dde87af7) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index ee470c535..8840b386b 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit ee470c535e258d93590488a4e1266bbe24dc90f1 +Subproject commit 8840b386bc9af30503a7e3afbaa570b2dde87af7 From a94dc54c17047d223042198704f23416a0ac647b Mon Sep 17 00:00:00 2001 From: ryancinsight <55164720+ryancinsight@users.noreply.github.com> Date: Tue, 2 Mar 2021 16:40:45 -0500 Subject: [PATCH 098/145] Addition of non-allocation tracking functions This is to enable use in pyoxidizer without rust dependent allocation tracking. --- snmalloc-sys/src/lib.rs | 46 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/snmalloc-sys/src/lib.rs b/snmalloc-sys/src/lib.rs index 70fce613a..28ef476cb 100644 --- a/snmalloc-sys/src/lib.rs +++ b/snmalloc-sys/src/lib.rs @@ -31,6 +31,36 @@ extern "C" { /// - `alignment` fulfills all the requirements as `rust_alloc` /// The program may be forced to abort if the constrains are not full-filled. pub fn rust_realloc(ptr: *mut c_void, alignment: size_t, old_size: size_t, new_size: size_t) -> *mut c_void; + + /// Allocate `count` items of `size` length each. + /// + /// Returns `null` if `count * size` overflows or on out-of-memory. + /// + /// All items are initialized to zero. + pub fn sn_calloc(count: usize, size: usize) -> *mut c_void; + + /// Allocate `size` bytes. + /// + /// Returns pointer to the allocated memory or null if out of memory. + /// Returns a unique pointer if called with `size` 0. + pub fn sn_malloc(size: usize) -> *mut c_void; + + /// Re-allocate memory to `newsize` bytes. + /// + /// Return pointer to the allocated memory or null if out of memory. If null + /// is returned, the pointer `p` is not freed. Otherwise the original + /// pointer is either freed or returned as the reallocated result (in case + /// it fits in-place with the new size). + /// + /// If `p` is null, it behaves as [`mi_malloc`]. If `newsize` is larger than + /// the original `size` allocated for `p`, the bytes after `size` are + /// uninitialized. + pub fn sn_realloc(p: *mut c_void, newsize: usize) -> *mut c_void; + + /// Free previously allocated memory. + /// + /// The pointer `p` must have been allocated before (or be null). + pub fn sn_free(p: *mut c_void); } #[cfg(test)] @@ -43,7 +73,19 @@ mod tests { unsafe {*ptr = 127; assert_eq!(*ptr, 127)}; unsafe { rust_dealloc(ptr as *mut c_void, 8, 8) }; } - + #[test] + fn it_frees_memory_sn_malloc() { + let ptr = unsafe { sn_malloc(8) } as *mut u8; + unsafe { sn_free(ptr as *mut c_void) }; + } + + #[test] + fn it_frees_memory_sn_realloc() { + let ptr = unsafe { sn_malloc(8) } as *mut u8; + let ptr = unsafe { sn_realloc(ptr as *mut c_void, 8) } as *mut u8; + unsafe { sn_free(ptr as *mut c_void) }; + } + #[test] fn it_reallocs_correctly() { let mut ptr = unsafe { rust_alloc(8, 8) } as *mut u8; @@ -52,4 +94,4 @@ mod tests { unsafe {assert_eq!(*ptr, 127)}; unsafe { rust_dealloc(ptr as *mut c_void, 8, 16) }; } -} \ No newline at end of file +} From c5be3f7b75ecb51264f54a36735b969fb2e292fa Mon Sep 17 00:00:00 2001 From: ryancinsight <55164720+ryancinsight@users.noreply.github.com> Date: Tue, 2 Mar 2021 17:09:29 -0500 Subject: [PATCH 099/145] Update lib.rs --- snmalloc-sys/snmalloc | 2 +- snmalloc-sys/src/lib.rs | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 8840b386b..7b8cac793 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 8840b386bc9af30503a7e3afbaa570b2dde87af7 +Subproject commit 7b8cac7931edce44c3b4f4eb2ac22fefe36484a4 diff --git a/snmalloc-sys/src/lib.rs b/snmalloc-sys/src/lib.rs index 28ef476cb..0a20b9d17 100644 --- a/snmalloc-sys/src/lib.rs +++ b/snmalloc-sys/src/lib.rs @@ -33,34 +33,31 @@ extern "C" { pub fn rust_realloc(ptr: *mut c_void, alignment: size_t, old_size: size_t, new_size: size_t) -> *mut c_void; /// Allocate `count` items of `size` length each. - /// /// Returns `null` if `count * size` overflows or on out-of-memory. - /// /// All items are initialized to zero. pub fn sn_calloc(count: usize, size: usize) -> *mut c_void; /// Allocate `size` bytes. - /// /// Returns pointer to the allocated memory or null if out of memory. /// Returns a unique pointer if called with `size` 0. pub fn sn_malloc(size: usize) -> *mut c_void; /// Re-allocate memory to `newsize` bytes. - /// /// Return pointer to the allocated memory or null if out of memory. If null /// is returned, the pointer `p` is not freed. Otherwise the original /// pointer is either freed or returned as the reallocated result (in case /// it fits in-place with the new size). - /// - /// If `p` is null, it behaves as [`mi_malloc`]. If `newsize` is larger than + /// If `p` is null, it behaves as [`sn_malloc`]. If `newsize` is larger than /// the original `size` allocated for `p`, the bytes after `size` are /// uninitialized. pub fn sn_realloc(p: *mut c_void, newsize: usize) -> *mut c_void; /// Free previously allocated memory. - /// /// The pointer `p` must have been allocated before (or be null). pub fn sn_free(p: *mut c_void); + + /// Return the available bytes in a memory block. + pub fn sn_malloc_usable_size(p: *const c_void) -> usize; } #[cfg(test)] @@ -94,4 +91,14 @@ mod tests { unsafe {assert_eq!(*ptr, 127)}; unsafe { rust_dealloc(ptr as *mut c_void, 8, 16) }; } + + #[test] + fn it_calculates_usable_size() { + let ptr = unsafe { sn_malloc(32) } as *mut u8; + let usable_size = unsafe { sn_malloc_usable_size(ptr as *mut c_void) }; + assert!( + usable_size >= 32, + "usable_size should at least equal to the allocated size" + ); + } } From f1d27afe0c5a300aca435a8cd3df64bf35faaadd Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Fri, 5 Mar 2021 10:55:14 +0800 Subject: [PATCH 100/145] bump submodule --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 7b8cac793..35346e72c 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 7b8cac7931edce44c3b4f4eb2ac22fefe36484a4 +Subproject commit 35346e72c36e5208b2bb0cb2631a3e3ed7e68fc2 From 17454b0d9a5a93e3f0fe8a2cbc493ebe910ed866 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Fri, 5 Mar 2021 11:04:30 +0800 Subject: [PATCH 101/145] update version and readme --- CHANGELOG.md | 7 +++++++ Cargo.toml | 4 ++-- README.md | 15 ++++++--------- snmalloc-sys/Cargo.toml | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c7d00caa..7db427275 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ ## Changelog +### 0.2.25 + +- **upstream** Apple M1 support +- **upstream** Building adjust +- non-allocation tracking functions + + ### 0.2.24 - **upstream** update to use a more efficient power of 2 check diff --git a/Cargo.toml b/Cargo.toml index b3be1406d..104ecdc55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.24" +version = "0.2.25" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.24", path = "snmalloc-sys"} +snmalloc-sys = {version = "0.2.25", path = "snmalloc-sys"} [features] default = ["1mib"] diff --git a/README.md b/README.md index 63933f14b..df480be42 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # snmalloc-rs **Notice: MinGW Build is broken and may not be fixed in a near future. See [this PR](https://github.com/microsoft/snmalloc/pull/217) in the upstream.** -MSVC/MinGW/Linux/MacOS: [![travis ci](https://www.travis-ci.org/SchrodingerZhu/snmalloc-rs.svg?branch=master)](https://travis-ci.com/SchrodingerZhu/snmalloc-rs) +MSVC/MinGW/Linux/MacOS: [![Actions Status](https://github.com/schrodingerzhu/snmalloc-rs/workflows/Rust/badge.svg)](https://github.com/schrodingerzhu/snmalloc-rs/actions) FreeBSD: [![Build Status](https://api.cirrus-ci.com/github/SchrodingerZhu/snmalloc-rs.svg)](https://cirrus-ci.com/github/SchrodingerZhu/snmalloc-rs) @@ -62,6 +62,11 @@ Hence, please make sure the following libs are in your `PATH`: - feature `android-shared-std` can be used to set the STL library of `snmalloc` to `c++_shared` (it uses `c++_static` by default) ## Changelog +### 0.2.25 + +- **upstream** Apple M1 support +- **upstream** Building adjust +- non-allocation tracking functions ### 0.2.24 @@ -72,12 +77,4 @@ Hence, please make sure the following libs are in your `PATH`: - **upstream** fix external pagemap usage -### 0.2.22 - -- **upstream** avoid amplification when routing -- **upstream** remotely store sizeclass -- **upstream** limit flat pagemap size -- **upstream** limit medium slab header -- **upstream** solaris support fix - for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 74077e100..b46f55c05 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.24" +version = "0.2.25" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" From f4e4de7b49ab83be09e89703fda4cee004131643 Mon Sep 17 00:00:00 2001 From: Ryan Clanton Date: Thu, 11 Mar 2021 13:18:41 -0500 Subject: [PATCH 102/145] use cc instead of cmake --- snmalloc-sys/Cargo.toml | 3 +- snmalloc-sys/build.rs | 155 ++++++++++++++++++---------------------- snmalloc-sys/snmalloc | 2 +- snmalloc-sys/src/lib.rs | 39 ++++++---- 4 files changed, 99 insertions(+), 100 deletions(-) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index b46f55c05..38d5267a0 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -13,7 +13,7 @@ build = "build.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [build-dependencies] -cmake = "0.1" +cc = {version = "1.0.67"} [dependencies.libc] version = "0.2" @@ -30,3 +30,4 @@ cache-friendly = [] android-lld = [] android-shared-stl = [] native-cpu = [] +local_dynamic_tls = [] diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 533415b41..f520bdac7 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -1,62 +1,75 @@ -use cmake::Config; - fn main() { - let mut cfg = &mut Config::new("snmalloc"); - - let build_type = if cfg!(feature = "debug") { - "Debug" - } else { - "Release" - }; - - cfg = cfg.define("SNMALLOC_RUST_SUPPORT", "ON") - .profile(build_type); + let mut build = cc::Build::new(); + build.include("snmalloc/src"); + build.file("snmalloc/src/override/rust.cc".to_string()); + build.flag_if_supported("/O2"); + build.flag_if_supported("/W4"); + build.flag_if_supported("/WX"); + build.flag_if_supported("/wd4127"); + build.flag_if_supported("/wd4324"); + build.flag_if_supported("/wd4201"); + build.flag_if_supported("/Ob2"); + build.flag_if_supported("/DNDEBUG"); + build.flag_if_supported("/EHsc"); + build.flag_if_supported("/std:c++17"); + build.flag_if_supported("-O3"); + build.flag_if_supported("-Wc++17-extensions"); + build.flag_if_supported("-std=c++1z"); + build.flag_if_supported("-std=gnu++1z"); + build.flag_if_supported("-mcx16"); + build.flag_if_supported("-fno-exceptions"); + build.flag_if_supported("-fno-rtti"); + build.flag_if_supported("-g"); + build.flag_if_supported("-fomit-frame-pointer"); + build.cpp(true); + build.debug(false); let triple = std::env::var("TARGET").unwrap(); - if triple.contains("android") { - if let Ok(ndk) = std::env::var("ANDROID_NDK") { - cfg = cfg.define("CMAKE_TOOLCHAIN_FILE", format!("{}/build/cmake/android.toolchain.cmake", ndk)); - } else { - eprintln!("please set ANDROID_NDK environment variable"); - std::process::abort(); - } - - if let Ok(platform) = std::env::var("ANDROID_PLATFORM") { - cfg = cfg.define("ANDROID_PLATFORM", platform); - } + let target_os = std::env::var("CARGO_CFG_TARGET_OS").expect("target_os not defined!"); + let target_env = std::env::var("CARGO_CFG_TARGET_ENV").expect("target_env not defined!"); + let target_family = std::env::var("CARGO_CFG_TARGET_FAMILY").expect("target family not set"); + + if triple.contains("android") { if cfg!(feature = "android-lld") { - cfg = cfg.define("ANDROID_LD", "lld"); + build.define("ANDROID_LD", "lld"); } if cfg!(feature = "android-shared-stl") { - println!("cargo:rustc-link-lib=dylib=c++_shared"); - cfg = cfg.define("ANDROID_STL", "c++_shared"); + build.define("ANDROID_STL", "c++_shared"); } if triple.contains("aarch64") { - cfg = cfg.define("ANDROID_ABI", "arm64-v8a"); + build.define("ANDROID_ABI", "arm64-v8a"); } else if triple.contains("armv7") { - cfg = cfg.define("ANDROID_ABI", "armeabi-v7a") - .define("ANDROID_ARM_MODE", "arm"); + build.define("ANDROID_ABI", "armeabi-v7a"); + build.define("ANDROID_ARM_MODE", "arm"); } else if triple.contains("x86_64") { - cfg = cfg.define("ANDROID_ABI", "x86_64"); + build.define("ANDROID_ABI", "x86_64"); } else if triple.contains("i686") { - cfg = cfg.define("ANDROID_ABI", "x86_64"); + build.define("ANDROID_ABI", "x86_64"); } else if triple.contains("neon") { - cfg = cfg.define("ANDROID_ABI", "armeabi-v7a with NEON") + build.define("ANDROID_ABI", "armeabi-v7a with NEON"); } else if triple.contains("arm") { - cfg = cfg.define("ANDROID_ABI", "armeabi-v7a"); + build.define("ANDROID_ABI", "armeabi-v7a"); } } - - if cfg!(all(windows, target_env = "msvc")) { - cfg = cfg.define("CMAKE_CXX_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc"); - cfg = cfg.define("CMAKE_C_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc"); + + if target_os=="windows" && target_env == "gnu" { + build.define("CMAKE_SH", "CMAKE_SH-NOTFOUND"); + if cfg!(feature = "local_dynamic_tls") { + build.flag_if_supported("-ftls-model=local-dynamic"); + } else { + build.flag_if_supported("-ftls-model=initial-exec"); + } } - - if cfg!(all(windows, target_env = "gnu")) { - cfg = cfg.define("CMAKE_SH", "CMAKE_SH-NOTFOUND"); + + if target_family == "unix" && target_os != "haiku" { + if cfg!(feature = "local_dynamic_tls") { + build.flag_if_supported("-ftls-model=local-dynamic"); + } else { + build.flag_if_supported("-ftls-model=initial-exec"); + } } let target = if cfg!(feature = "1mib") { @@ -68,77 +81,51 @@ fn main() { }; if cfg!(feature = "native-cpu") { - cfg = cfg.define("SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE", "ON") + build.define("SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE", "ON"); + build.flag_if_supported("-march=native"); } if cfg!(feature = "stats") { - cfg = cfg.define("USE_SNMALLOC_STATS", "ON") + build.define("USE_SNMALLOC_STATS", "ON"); } if cfg!(feature = "qemu") { - cfg = cfg.define("SNMALLOC_QEMU_WORKAROUND", "ON") + build.define("SNMALLOC_QEMU_WORKAROUND", "ON"); } - let mut dst = if cfg!(feature = "cache-friendly") { - cfg.define("CACHE_FRIENDLY_OFFSET", "64").build_target(target).build() - } else { - cfg.build_target(target).build() - }; + if cfg!(feature = "cache-friendly") { + build.define("CACHE_FRIENDLY_OFFSET", "64"); + } - dst.push("./build"); + build.compile(target); - println!("cargo:rustc-link-lib={}", target); + if cfg!(feature = "android-shared-stl") { + println!("cargo:rustc-link-lib=dylib=c++_shared"); + } - if cfg!(all(windows, target_env = "msvc")) { + if target_env == "msvc" { println!("cargo:rustc-link-lib=dylib=mincore"); - println!("cargo:rustc-link-search=native={}/{}", dst.display(), build_type); - } else { - println!("cargo:rustc-link-search=native={}", dst.display()); } - if cfg!(all(windows, target_env = "gnu")) { - let stdout = std::process::Command::new("gcc") - .args(&["-print-search-dirs"]) - .output().unwrap_or_else(|_| { - eprintln!("Cannot run gcc.exe"); - std::process::abort(); - }) - .stdout; - - let outputs = String::from_utf8(stdout) - .unwrap_or_else(|_| { - eprintln!("gcc output contains non-utf8 characters"); - std::process::abort(); - }); - - outputs.lines() - .filter(|line| line.starts_with("libraries: =")) - .map(|line| line.split_at("libraries: =".len()).1) - .flat_map(|line| line.split(";")) - .for_each(|path| { - println!("cargo:rustc-link-search=native={}", path); - }); - + if target_os=="windows" && target_env == "gnu" { println!("cargo:rustc-link-lib=dylib=stdc++"); println!("cargo:rustc-link-lib=dylib=atomic"); - println!("cargo:rustc-link-lib=dylib=winpthread"); - println!("cargo:rustc-link-lib=dylib=gcc_s"); } - if cfg!(target_os = "macos") { + if target_os == "macos" { println!("cargo:rustc-link-lib=dylib=c++"); } - if cfg!(target_os = "openbsd") { + if target_os == "openbsd" { println!("cargo:rustc-link-lib=dylib=c++"); } - if cfg!(target_os = "freebsd") { + if target_os == "freebsd" { println!("cargo:rustc-link-lib=dylib=c++"); } - if cfg!(target_os = "linux") { + if target_os == "linux" { println!("cargo:rustc-link-lib=dylib=stdc++"); println!("cargo:rustc-link-lib=dylib=atomic"); - } + }; } diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 35346e72c..1d12e34b9 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 35346e72c36e5208b2bb0cb2631a3e3ed7e68fc2 +Subproject commit 1d12e34b9f616da2ad5665f72818cca0a804f478 diff --git a/snmalloc-sys/src/lib.rs b/snmalloc-sys/src/lib.rs index 0a20b9d17..a421c7ad4 100644 --- a/snmalloc-sys/src/lib.rs +++ b/snmalloc-sys/src/lib.rs @@ -5,8 +5,8 @@ use core::ffi::c_void; use libc::size_t; extern "C" { - /// Allocate the memory with the given alignment and size. - /// On success, it returns a pointer pointing to the required memory address. + /// Allocate the memory with the given alignment and size. + /// On success, it returns a pointer pointing to the required memory address. /// On failure, it returns a null pointer. /// The client must assure the following things: /// - `alignment` is greater than zero @@ -14,15 +14,15 @@ extern "C" { /// The program may be forced to abort if the constrains are not full-filled. pub fn rust_alloc(alignment: size_t, size: size_t) -> *mut c_void; - /// De-allocate the memory at the given address with the given alignment and size. + /// De-allocate the memory at the given address with the given alignment and size. /// The client must assure the following things: /// - the memory is acquired using the same allocator and the pointer points to the start position. /// - `alignment` and `size` is the same as allocation /// The program may be forced to abort if the constrains are not full-filled. pub fn rust_dealloc(ptr: *mut c_void, alignment: size_t, size: size_t) -> c_void; - /// Re-allocate the memory at the given address with the given alignment and size. - /// On success, it returns a pointer pointing to the required memory address. + /// Re-allocate the memory at the given address with the given alignment and size. + /// On success, it returns a pointer pointing to the required memory address. /// The memory content within the `new_size` will remains the same as previous. /// On failure, it returns a null pointer. In this situation, the previous memory is not returned to the allocator. /// The client must assure the following things: @@ -30,13 +30,18 @@ extern "C" { /// - `alignment` and `old_size` is the same as allocation /// - `alignment` fulfills all the requirements as `rust_alloc` /// The program may be forced to abort if the constrains are not full-filled. - pub fn rust_realloc(ptr: *mut c_void, alignment: size_t, old_size: size_t, new_size: size_t) -> *mut c_void; - + pub fn rust_realloc( + ptr: *mut c_void, + alignment: size_t, + old_size: size_t, + new_size: size_t, + ) -> *mut c_void; + /// Allocate `count` items of `size` length each. /// Returns `null` if `count * size` overflows or on out-of-memory. /// All items are initialized to zero. pub fn sn_calloc(count: usize, size: usize) -> *mut c_void; - + /// Allocate `size` bytes. /// Returns pointer to the allocated memory or null if out of memory. /// Returns a unique pointer if called with `size` 0. @@ -55,7 +60,7 @@ extern "C" { /// Free previously allocated memory. /// The pointer `p` must have been allocated before (or be null). pub fn sn_free(p: *mut c_void); - + /// Return the available bytes in a memory block. pub fn sn_malloc_usable_size(p: *const c_void) -> usize; } @@ -67,7 +72,10 @@ mod tests { #[test] fn it_frees_memory_malloc() { let ptr = unsafe { rust_alloc(8, 8) } as *mut u8; - unsafe {*ptr = 127; assert_eq!(*ptr, 127)}; + unsafe { + *ptr = 127; + assert_eq!(*ptr, 127) + }; unsafe { rust_dealloc(ptr as *mut c_void, 8, 8) }; } #[test] @@ -75,20 +83,23 @@ mod tests { let ptr = unsafe { sn_malloc(8) } as *mut u8; unsafe { sn_free(ptr as *mut c_void) }; } - + #[test] fn it_frees_memory_sn_realloc() { let ptr = unsafe { sn_malloc(8) } as *mut u8; let ptr = unsafe { sn_realloc(ptr as *mut c_void, 8) } as *mut u8; unsafe { sn_free(ptr as *mut c_void) }; } - + #[test] fn it_reallocs_correctly() { let mut ptr = unsafe { rust_alloc(8, 8) } as *mut u8; - unsafe {*ptr = 127; assert_eq!(*ptr, 127)}; + unsafe { + *ptr = 127; + assert_eq!(*ptr, 127) + }; ptr = unsafe { rust_realloc(ptr as *mut c_void, 8, 8, 16) } as *mut u8; - unsafe {assert_eq!(*ptr, 127)}; + unsafe { assert_eq!(*ptr, 127) }; unsafe { rust_dealloc(ptr as *mut c_void, 8, 16) }; } From d541d9d53902366b5fadfc548eda60788fc525e8 Mon Sep 17 00:00:00 2001 From: Ryan Clanton Date: Fri, 12 Mar 2021 12:53:32 -0500 Subject: [PATCH 103/145] Allow specification of cc as a feature --- .github/workflows/rust.yml | 2 + .travis.yml | 1 + Cargo.toml | 3 +- snmalloc-sys/Cargo.toml | 7 +- snmalloc-sys/build.rs | 193 ++++++++++++++++++++++++++++++++++--- src/lib.rs | 18 ++-- 6 files changed, 200 insertions(+), 24 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 0a9bba795..b8048ff20 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -31,6 +31,8 @@ jobs: run: cargo test --all - name: Run tests 1mib run: cargo test --all --features 1mib + - name: Run tests 1mib build_cc + run: cargo test --all --features build_cc - name: Run tests debug run: cargo test --all --features debug - name: Run tests cache-friendly diff --git a/.travis.yml b/.travis.yml index ee5f101c5..3cde1c9c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -95,6 +95,7 @@ cache: script: - cargo test --all - cargo test --all --features 1mib + - cargo test --all --features build_cc - cargo test --all --features debug - cargo test --all --features cache-friendly diff --git a/Cargo.toml b/Cargo.toml index 104ecdc55..4c9ec9b63 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,10 +16,11 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.25", path = "snmalloc-sys"} +snmalloc-sys = {version = "0.2.25", path = "snmalloc-sys",default-features = false } [features] default = ["1mib"] +build_cc = ["snmalloc-sys/build_cc","1mib"] 1mib = ["snmalloc-sys/1mib"] 16mib = ["snmalloc-sys/16mib"] qemu = ["snmalloc-sys/qemu"] diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 38d5267a0..053bf5abd 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -13,14 +13,17 @@ build = "build.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [build-dependencies] -cc = {version = "1.0.67"} +cc = {version = "1.0",optional=true} +cmake = {version = "0.1",optional=true} + [dependencies.libc] version = "0.2" default-features = false [features] -default = ["1mib"] +default = ["1mib","cmake"] +build_cc = ["cc"] 1mib = [] 16mib = [] qemu = [] diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index f520bdac7..fe16b8efa 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -1,8 +1,11 @@ +#[cfg(feature = "build_cc")] fn main() { let mut build = cc::Build::new(); build.include("snmalloc/src"); build.file("snmalloc/src/override/rust.cc".to_string()); build.flag_if_supported("/O2"); + build.flag_if_supported("/Zi"); + build.flag_if_supported("/nologo"); build.flag_if_supported("/W4"); build.flag_if_supported("/WX"); build.flag_if_supported("/wd4127"); @@ -12,24 +15,32 @@ fn main() { build.flag_if_supported("/DNDEBUG"); build.flag_if_supported("/EHsc"); build.flag_if_supported("/std:c++17"); + build.flag_if_supported("/Gd"); + build.flag_if_supported("/TP"); + build.flag_if_supported("/Gm-"); + build.flag_if_supported("/GS"); + build.flag_if_supported("/fp:precise"); + build.flag_if_supported("/Zc:wchar_t"); + build.flag_if_supported("/Zc:forScope"); + build.flag_if_supported("/Zc:inline"); build.flag_if_supported("-O3"); build.flag_if_supported("-Wc++17-extensions"); build.flag_if_supported("-std=c++1z"); build.flag_if_supported("-std=gnu++1z"); build.flag_if_supported("-mcx16"); - build.flag_if_supported("-fno-exceptions"); - build.flag_if_supported("-fno-rtti"); - build.flag_if_supported("-g"); - build.flag_if_supported("-fomit-frame-pointer"); + build.flag_if_supported("-fno-exceptions"); + build.flag_if_supported("-fno-rtti"); + build.flag_if_supported("-g"); + build.flag_if_supported("-fomit-frame-pointer"); + build.flag_if_supported("-fpermissive"); build.cpp(true); build.debug(false); let triple = std::env::var("TARGET").unwrap(); let target_os = std::env::var("CARGO_CFG_TARGET_OS").expect("target_os not defined!"); let target_env = std::env::var("CARGO_CFG_TARGET_ENV").expect("target_env not defined!"); - let target_family = std::env::var("CARGO_CFG_TARGET_FAMILY").expect("target family not set"); + let target_family = std::env::var("CARGO_CFG_TARGET_FAMILY").expect("target family not set"); - if triple.contains("android") { if cfg!(feature = "android-lld") { build.define("ANDROID_LD", "lld"); @@ -54,8 +65,8 @@ fn main() { build.define("ANDROID_ABI", "armeabi-v7a"); } } - - if target_os=="windows" && target_env == "gnu" { + + if target_os == "windows" && target_env == "gnu" { build.define("CMAKE_SH", "CMAKE_SH-NOTFOUND"); if cfg!(feature = "local_dynamic_tls") { build.flag_if_supported("-ftls-model=local-dynamic"); @@ -63,7 +74,7 @@ fn main() { build.flag_if_supported("-ftls-model=initial-exec"); } } - + if target_family == "unix" && target_os != "haiku" { if cfg!(feature = "local_dynamic_tls") { build.flag_if_supported("-ftls-model=local-dynamic"); @@ -82,7 +93,7 @@ fn main() { if cfg!(feature = "native-cpu") { build.define("SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE", "ON"); - build.flag_if_supported("-march=native"); + build.flag_if_supported("-march=native"); } if cfg!(feature = "stats") { @@ -107,8 +118,8 @@ fn main() { println!("cargo:rustc-link-lib=dylib=mincore"); } - if target_os=="windows" && target_env == "gnu" { - println!("cargo:rustc-link-lib=dylib=stdc++"); + if target_os == "windows" && target_env == "gnu" { + //using cc println!("cargo:rustc-link-lib=dylib=atomic"); } @@ -129,3 +140,161 @@ fn main() { println!("cargo:rustc-link-lib=dylib=atomic"); }; } + + +#[cfg(not(feature = "build_cc"))] +fn main() { + let mut cfg = &mut cmake::Config::new("snmalloc"); + + let build_type = if cfg!(feature = "debug") { + "Debug" + } else { + "Release" + }; + + cfg = cfg + .define("SNMALLOC_RUST_SUPPORT", "ON") + .profile(build_type) + .very_verbose(true); + + let triple = std::env::var("TARGET").unwrap(); + if triple.contains("android") { + if let Ok(ndk) = std::env::var("ANDROID_NDK") { + cfg = cfg.define( + "CMAKE_TOOLCHAIN_FILE", + format!("{}/build/cmake/android.toolchain.cmake", ndk), + ); + } else { + eprintln!("please set ANDROID_NDK environment variable"); + std::process::abort(); + } + + if let Ok(platform) = std::env::var("ANDROID_PLATFORM") { + cfg = cfg.define("ANDROID_PLATFORM", platform); + } + + if cfg!(feature = "android-lld") { + cfg = cfg.define("ANDROID_LD", "lld"); + } + + if cfg!(feature = "android-shared-stl") { + println!("cargo:rustc-link-lib=dylib=c++_shared"); + cfg = cfg.define("ANDROID_STL", "c++_shared"); + } + + if triple.contains("aarch64") { + cfg = cfg.define("ANDROID_ABI", "arm64-v8a"); + } else if triple.contains("armv7") { + cfg = cfg + .define("ANDROID_ABI", "armeabi-v7a") + .define("ANDROID_ARM_MODE", "arm"); + } else if triple.contains("x86_64") { + cfg = cfg.define("ANDROID_ABI", "x86_64"); + } else if triple.contains("i686") { + cfg = cfg.define("ANDROID_ABI", "x86_64"); + } else if triple.contains("neon") { + cfg = cfg.define("ANDROID_ABI", "armeabi-v7a with NEON") + } else if triple.contains("arm") { + cfg = cfg.define("ANDROID_ABI", "armeabi-v7a"); + } + } + + if cfg!(all(windows, target_env = "msvc")) { + cfg = cfg.define("CMAKE_CXX_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc"); + cfg = cfg.define("CMAKE_C_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc"); + } + + if cfg!(all(windows, target_env = "gnu")) { + cfg = cfg.define("CMAKE_SH", "CMAKE_SH-NOTFOUND"); + } + + let target = if cfg!(feature = "1mib") { + "snmallocshim-1mib-rust" + } else if cfg!(feature = "16mib") { + "snmallocshim-16mib-rust" + } else { + panic!("please set a chunk configuration"); + }; + + if cfg!(feature = "native-cpu") { + cfg = cfg.define("SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE", "ON") + } + + if cfg!(feature = "stats") { + cfg = cfg.define("USE_SNMALLOC_STATS", "ON") + } + + if cfg!(feature = "qemu") { + cfg = cfg.define("SNMALLOC_QEMU_WORKAROUND", "ON") + } + + let mut dst = if cfg!(feature = "cache-friendly") { + cfg.define("CACHE_FRIENDLY_OFFSET", "64") + .build_target(target) + .build() + } else { + cfg.build_target(target).build() + }; + + dst.push("./build"); + + println!("cargo:rustc-link-lib={}", target); + + if cfg!(all(windows, target_env = "msvc")) { + println!("cargo:rustc-link-lib=dylib=mincore"); + println!( + "cargo:rustc-link-search=native={}/{}", + dst.display(), + build_type + ); + } else { + println!("cargo:rustc-link-search=native={}", dst.display()); + } + + if cfg!(all(windows, target_env = "gnu")) { + let stdout = std::process::Command::new("gcc") + .args(&["-print-search-dirs"]) + .output() + .unwrap_or_else(|_| { + eprintln!("Cannot run gcc.exe"); + std::process::abort(); + }) + .stdout; + + let outputs = String::from_utf8(stdout).unwrap_or_else(|_| { + eprintln!("gcc output contains non-utf8 characters"); + std::process::abort(); + }); + + outputs + .lines() + .filter(|line| line.starts_with("libraries: =")) + .map(|line| line.split_at("libraries: =".len()).1) + .flat_map(|line| line.split(";")) + .for_each(|path| { + println!("cargo:rustc-link-search=native={}", path); + }); + + println!("cargo:rustc-link-lib=dylib=stdc++"); + println!("cargo:rustc-link-lib=dylib=atomic"); + println!("cargo:rustc-link-lib=dylib=winpthread"); + println!("cargo:rustc-link-lib=dylib=gcc_s"); + } + + if cfg!(target_os = "macos") { + println!("cargo:rustc-link-lib=dylib=c++"); + } + + if cfg!(target_os = "openbsd") { + println!("cargo:rustc-link-lib=dylib=c++"); + } + + if cfg!(target_os = "freebsd") { + println!("cargo:rustc-link-lib=dylib=c++"); + } + + if cfg!(target_os = "linux") { + println!("cargo:rustc-link-lib=dylib=stdc++"); + println!("cargo:rustc-link-lib=dylib=atomic"); + } +} diff --git a/src/lib.rs b/src/lib.rs index c4ad3f6af..d89008043 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,22 +4,22 @@ //! - Memory that is freed by the same thread that allocated it does not require any synchronising operations. //! - Freeing memory in a different thread to initially allocated it, does not take any locks and instead uses a novel message passing scheme to return the memory to the original allocator, where it is recycled. //! - The allocator uses large ranges of pages to reduce the amount of meta-data required. -//! +//! //! The benchmark is available at the [paper](https://github.com/microsoft/snmalloc/blob/master/snmalloc.pdf) of `snmalloc` //! There are three features defined in this crate: //! - `debug`: Enable the `Debug` mode in `snmalloc`. //! - `1mib`: Use the `1mib` chunk configuration. //! - `cache-friendly`: Make the allocator more cache friendly (setting `CACHE_FRIENDLY_OFFSET` to `64` in building the library). -//! +//! //! The whole library supports `no_std`. -//! +//! //! To use `snmalloc-rs` add it as a dependency: //! ```toml //! # Cargo.toml //! [dependencies] //! snmalloc-rs = "0.1.0" //! ``` -//! +//! //! To set `SnMalloc` as the global allocator add this to your project: //! ```rust //! #[global_allocator] @@ -32,8 +32,8 @@ use core::alloc::{GlobalAlloc, Layout}; pub struct SnMalloc; unsafe impl GlobalAlloc for SnMalloc { - /// Allocate the memory with the given alignment and size. - /// On success, it returns a pointer pointing to the required memory address. + /// Allocate the memory with the given alignment and size. + /// On success, it returns a pointer pointing to the required memory address. /// On failure, it returns a null pointer. /// The client must assure the following things: /// - `alignment` is greater than zero @@ -44,7 +44,7 @@ unsafe impl GlobalAlloc for SnMalloc { ffi::rust_alloc(layout.align(), layout.size()) as _ } - /// De-allocate the memory at the given address with the given alignment and size. + /// De-allocate the memory at the given address with the given alignment and size. /// The client must assure the following things: /// - the memory is acquired using the same allocator and the pointer points to the start position. /// - Other constrains are the same as the rust standard library. @@ -54,8 +54,8 @@ unsafe impl GlobalAlloc for SnMalloc { ffi::rust_dealloc(ptr as _, layout.align(), layout.size()); } - /// Re-allocate the memory at the given address with the given alignment and size. - /// On success, it returns a pointer pointing to the required memory address. + /// Re-allocate the memory at the given address with the given alignment and size. + /// On success, it returns a pointer pointing to the required memory address. /// The memory content within the `new_size` will remains the same as previous. /// On failure, it returns a null pointer. In this situation, the previous memory is not returned to the allocator. /// The client must assure the following things: From d3f736c7cb0eb928d031838c1c86730c58c72cb7 Mon Sep 17 00:00:00 2001 From: Ryan Clanton Date: Fri, 12 Mar 2021 17:30:29 -0500 Subject: [PATCH 104/145] make builds mutually exclusive --- Cargo.toml | 2 +- snmalloc-sys/Cargo.toml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4c9ec9b63..e0675685e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ members = ["snmalloc-sys" ] snmalloc-sys = {version = "0.2.25", path = "snmalloc-sys",default-features = false } [features] -default = ["1mib"] +default = ["snmalloc-sys/build_cmake","1mib"] build_cc = ["snmalloc-sys/build_cc","1mib"] 1mib = ["snmalloc-sys/1mib"] 16mib = ["snmalloc-sys/16mib"] diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 053bf5abd..80c057f98 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -22,8 +22,9 @@ version = "0.2" default-features = false [features] -default = ["1mib","cmake"] +default = ["1mib","build_cmake"] build_cc = ["cc"] +build_cmake = ["cmake"] 1mib = [] 16mib = [] qemu = [] From 8da2e88b690f7df0577d5a40b957ed739a6a2ccb Mon Sep 17 00:00:00 2001 From: Ryan Clanton Date: Sun, 14 Mar 2021 11:59:04 -0400 Subject: [PATCH 105/145] addition of build_cc to the Readme --- Cargo.toml | 2 ++ README.md | 10 ++++++++++ snmalloc-sys/build.rs | 16 ++-------------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e0675685e..cd7468e95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,3 +30,5 @@ cache-friendly = ["snmalloc-sys/cache-friendly"] android-lld = ["snmalloc-sys/android-lld"] android-shared-stl = ["snmalloc-sys/android-shared-stl"] native-cpu = ["snmalloc-sys/native-cpu"] +local_dynamic_tls = ["snmalloc-sys/local_dynamic_tls"] + diff --git a/README.md b/README.md index df480be42..a750a4b9f 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,9 @@ There are three features defined in this crate: - `native-cpu`: Optimize `snmalloc` for the native CPU of the host machine. (this is not a default behavior since `0.2.14`) - `qemu`: workaround `madvise` problem of QEMU environment - `stats`: enable statistics +- `local_dynamic_tls`: workaround cannot allocate memory in static tls block +- `build_cc`: use of cc crate instead of cmake (cmake still default) as builder (more platform agnostic) + **To get the crates compiled, you need to choose either `1mib` or `16mib` to determine the chunk configuration** @@ -62,6 +65,13 @@ Hence, please make sure the following libs are in your `PATH`: - feature `android-shared-std` can be used to set the STL library of `snmalloc` to `c++_shared` (it uses `c++_static` by default) ## Changelog +### 0.2.26 + +- **upstream** Building adjustment +- option of cc crate as build feature, only c compiler needed, no cmake required +- Addition of dynamic local TLS option + + ### 0.2.25 - **upstream** Apple M1 support diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index fe16b8efa..87948f689 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -33,6 +33,7 @@ fn main() { build.flag_if_supported("-g"); build.flag_if_supported("-fomit-frame-pointer"); build.flag_if_supported("-fpermissive"); + build.static_crt(true); build.cpp(true); build.debug(false); @@ -45,11 +46,9 @@ fn main() { if cfg!(feature = "android-lld") { build.define("ANDROID_LD", "lld"); } - if cfg!(feature = "android-shared-stl") { build.define("ANDROID_STL", "c++_shared"); } - if triple.contains("aarch64") { build.define("ANDROID_ABI", "arm64-v8a"); } else if triple.contains("armv7") { @@ -66,16 +65,7 @@ fn main() { } } - if target_os == "windows" && target_env == "gnu" { - build.define("CMAKE_SH", "CMAKE_SH-NOTFOUND"); - if cfg!(feature = "local_dynamic_tls") { - build.flag_if_supported("-ftls-model=local-dynamic"); - } else { - build.flag_if_supported("-ftls-model=initial-exec"); - } - } - - if target_family == "unix" && target_os != "haiku" { + if target_family == "unix" || target_env == "gnu" && target_os != "haiku" { if cfg!(feature = "local_dynamic_tls") { build.flag_if_supported("-ftls-model=local-dynamic"); } else { @@ -119,7 +109,6 @@ fn main() { } if target_os == "windows" && target_env == "gnu" { - //using cc println!("cargo:rustc-link-lib=dylib=atomic"); } @@ -141,7 +130,6 @@ fn main() { }; } - #[cfg(not(feature = "build_cc"))] fn main() { let mut cfg = &mut cmake::Config::new("snmalloc"); From e740c03bf85b1edcf47bb7249d4e65352a95cc94 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Mon, 15 Mar 2021 14:55:57 +0800 Subject: [PATCH 106/145] bump version: 0.2.26 --- CHANGELOG.md | 7 ++++++- Cargo.toml | 4 ++-- README.md | 1 + snmalloc-sys/Cargo.toml | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7db427275..eed73846b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,17 @@ ## Changelog +### 0.2.26 + +- **upstream** Building adjustment +- option of cc crate as build feature, only c compiler needed, no cmake required +- Addition of dynamic local TLS option + ### 0.2.25 - **upstream** Apple M1 support - **upstream** Building adjust - non-allocation tracking functions - ### 0.2.24 - **upstream** update to use a more efficient power of 2 check diff --git a/Cargo.toml b/Cargo.toml index cd7468e95..685e5b6c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.25" +version = "0.2.26" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.25", path = "snmalloc-sys",default-features = false } +snmalloc-sys = {version = "0.2.26", path = "snmalloc-sys",default-features = false } [features] default = ["snmalloc-sys/build_cmake","1mib"] diff --git a/README.md b/README.md index a750a4b9f..5dbea6c4a 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ Hence, please make sure the following libs are in your `PATH`: - feature `android-shared-std` can be used to set the STL library of `snmalloc` to `c++_shared` (it uses `c++_static` by default) ## Changelog + ### 0.2.26 - **upstream** Building adjustment diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 80c057f98..2e30db207 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.25" +version = "0.2.26" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" From e0cda35d50544e48954059a4a5f11f2f00f1bfd6 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 29 Mar 2021 06:20:54 +0000 Subject: [PATCH 107/145] Bump snmalloc-sys/snmalloc from `1d12e34` to `c5b65d0` Bumps [snmalloc-sys/snmalloc](https://github.com/microsoft/snmalloc) from `1d12e34` to `c5b65d0`. - [Release notes](https://github.com/microsoft/snmalloc/releases) - [Commits](https://github.com/microsoft/snmalloc/compare/1d12e34b9f616da2ad5665f72818cca0a804f478...c5b65d07b8079b22eec9f78bec197ea7a0fd15f2) Signed-off-by: dependabot-preview[bot] --- snmalloc-sys/snmalloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 1d12e34b9..c5b65d07b 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 1d12e34b9f616da2ad5665f72818cca0a804f478 +Subproject commit c5b65d07b8079b22eec9f78bec197ea7a0fd15f2 From 633b0b6978969ee28afa81dbc8299e0bee3e6709 Mon Sep 17 00:00:00 2001 From: Ryan Clanton <55164720+ryancinsight@users.noreply.github.com> Date: Wed, 21 Apr 2021 19:43:26 -0400 Subject: [PATCH 108/145] remove libc usage --- snmalloc-sys/Cargo.toml | 5 ----- snmalloc-sys/src/lib.rs | 13 ++++++------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 2e30db207..172b88995 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -16,11 +16,6 @@ build = "build.rs" cc = {version = "1.0",optional=true} cmake = {version = "0.1",optional=true} - -[dependencies.libc] -version = "0.2" -default-features = false - [features] default = ["1mib","build_cmake"] build_cc = ["cc"] diff --git a/snmalloc-sys/src/lib.rs b/snmalloc-sys/src/lib.rs index a421c7ad4..952bb92ce 100644 --- a/snmalloc-sys/src/lib.rs +++ b/snmalloc-sys/src/lib.rs @@ -1,8 +1,7 @@ #![no_std] #![allow(non_camel_case_types)] -use core::ffi::c_void; -use libc::size_t; +use {core::ffi::c_void, core::usize}; extern "C" { /// Allocate the memory with the given alignment and size. @@ -12,14 +11,14 @@ extern "C" { /// - `alignment` is greater than zero /// - `alignment` is a power of 2 /// The program may be forced to abort if the constrains are not full-filled. - pub fn rust_alloc(alignment: size_t, size: size_t) -> *mut c_void; + pub fn rust_alloc(alignment: usize, size: usize) -> *mut c_void; /// De-allocate the memory at the given address with the given alignment and size. /// The client must assure the following things: /// - the memory is acquired using the same allocator and the pointer points to the start position. /// - `alignment` and `size` is the same as allocation /// The program may be forced to abort if the constrains are not full-filled. - pub fn rust_dealloc(ptr: *mut c_void, alignment: size_t, size: size_t) -> c_void; + pub fn rust_dealloc(ptr: *mut c_void, alignment: usize, size: usize) -> c_void; /// Re-allocate the memory at the given address with the given alignment and size. /// On success, it returns a pointer pointing to the required memory address. @@ -32,9 +31,9 @@ extern "C" { /// The program may be forced to abort if the constrains are not full-filled. pub fn rust_realloc( ptr: *mut c_void, - alignment: size_t, - old_size: size_t, - new_size: size_t, + alignment: usize, + old_size: usize, + new_size: usize, ) -> *mut c_void; /// Allocate `count` items of `size` length each. From 753b1aeac38ccc9d097894b6ea0ddecbb2ba3a19 Mon Sep 17 00:00:00 2001 From: Ryan Clanton <55164720+ryancinsight@users.noreply.github.com> Date: Wed, 21 Apr 2021 20:08:53 -0400 Subject: [PATCH 109/145] check if -Wmaybe-unitialized removes warning --- snmalloc-sys/build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 87948f689..69afd3706 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -33,6 +33,7 @@ fn main() { build.flag_if_supported("-g"); build.flag_if_supported("-fomit-frame-pointer"); build.flag_if_supported("-fpermissive"); + build.flag_if_supported("-Wmaybe-uninitialized"); build.static_crt(true); build.cpp(true); build.debug(false); From d1f55f6b0be5ca0f4fdb54ec17dea8df1ac646f1 Mon Sep 17 00:00:00 2001 From: Ryan Clanton <55164720+ryancinsight@users.noreply.github.com> Date: Wed, 21 Apr 2021 20:16:30 -0400 Subject: [PATCH 110/145] Revert "check if -Wmaybe-unitialized removes warning" This reverts commit 753b1aeac38ccc9d097894b6ea0ddecbb2ba3a19. --- snmalloc-sys/build.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 69afd3706..87948f689 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -33,7 +33,6 @@ fn main() { build.flag_if_supported("-g"); build.flag_if_supported("-fomit-frame-pointer"); build.flag_if_supported("-fpermissive"); - build.flag_if_supported("-Wmaybe-uninitialized"); build.static_crt(true); build.cpp(true); build.debug(false); From bb3223cc94feafedd63fb37d14d6fac748b0b94d Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 28 Apr 2021 22:12:29 +0000 Subject: [PATCH 111/145] Upgrade to GitHub-native Dependabot --- .github/dependabot.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..4e1a6b906 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: +- package-ecosystem: cargo + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 +- package-ecosystem: gitsubmodule + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 From 8a59e64669d9f59f2622bf7487488a303c005cea Mon Sep 17 00:00:00 2001 From: Ryan Clanton <55164720+ryancinsight@users.noreply.github.com> Date: Thu, 29 Apr 2021 16:38:53 -0400 Subject: [PATCH 112/145] addition of windows 7 and 8 compatibility --- CHANGELOG.md | 6 ++++++ Cargo.toml | 3 ++- snmalloc-sys/Cargo.toml | 2 ++ snmalloc-sys/build.rs | 44 ++++++++++++++++++++++++++++++++--------- src/lib.rs | 8 ++++---- 5 files changed, 49 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eed73846b..35aff8858 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## Changelog +### 0.2.27 + +- Reduction of libc dependency +- **upstream** Windows 7 and windows 8 compatibility added +- **upstream** Option to use C++20 standards if available + ### 0.2.26 - **upstream** Building adjustment diff --git a/Cargo.toml b/Cargo.toml index 685e5b6c6..b44cde490 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,4 +31,5 @@ android-lld = ["snmalloc-sys/android-lld"] android-shared-stl = ["snmalloc-sys/android-shared-stl"] native-cpu = ["snmalloc-sys/native-cpu"] local_dynamic_tls = ["snmalloc-sys/local_dynamic_tls"] - +win8compat = ["snmalloc-sys/win8compat"] +usecxx20 = ["snmalloc-sys/usecxx20"] diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 172b88995..685ea8a3d 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -30,3 +30,5 @@ android-lld = [] android-shared-stl = [] native-cpu = [] local_dynamic_tls = [] +win8compat = [] +usecxx20 = [] \ No newline at end of file diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 87948f689..a8a3ec1ce 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -14,7 +14,6 @@ fn main() { build.flag_if_supported("/Ob2"); build.flag_if_supported("/DNDEBUG"); build.flag_if_supported("/EHsc"); - build.flag_if_supported("/std:c++17"); build.flag_if_supported("/Gd"); build.flag_if_supported("/TP"); build.flag_if_supported("/Gm-"); @@ -24,9 +23,6 @@ fn main() { build.flag_if_supported("/Zc:forScope"); build.flag_if_supported("/Zc:inline"); build.flag_if_supported("-O3"); - build.flag_if_supported("-Wc++17-extensions"); - build.flag_if_supported("-std=c++1z"); - build.flag_if_supported("-std=gnu++1z"); build.flag_if_supported("-mcx16"); build.flag_if_supported("-fno-exceptions"); build.flag_if_supported("-fno-rtti"); @@ -36,6 +32,21 @@ fn main() { build.static_crt(true); build.cpp(true); build.debug(false); + if cfg!(feature = "usecxx20") { + build.flag_if_supported("-std=c++17"); //original required if cxx20 not supported + build.flag_if_supported("/std:c++17"); + build.flag_if_supported("-Wc++17-extensions"); + build.flag_if_supported("/Wc++17-extensions"); + build.flag_if_supported("-std=c++20"); + build.flag_if_supported("/std:c++20"); + build.flag_if_supported("-Wc++20-extensions"); + build.flag_if_supported("/Wc++20-extensions"); + } else { + build.flag_if_supported("-std=c++17"); + build.flag_if_supported("/std:c++17"); + build.flag_if_supported("-Wc++17-extensions"); + build.flag_if_supported("/Wc++17-extensions"); + } let triple = std::env::var("TARGET").unwrap(); let target_os = std::env::var("CARGO_CFG_TARGET_OS").expect("target_os not defined!"); @@ -57,7 +68,7 @@ fn main() { } else if triple.contains("x86_64") { build.define("ANDROID_ABI", "x86_64"); } else if triple.contains("i686") { - build.define("ANDROID_ABI", "x86_64"); + build.define("ANDROID_ABI", "x86"); } else if triple.contains("neon") { build.define("ANDROID_ABI", "armeabi-v7a with NEON"); } else if triple.contains("arm") { @@ -73,6 +84,10 @@ fn main() { } } + if cfg!(feature = "win8compat") { + build.flag_if_supported("-DWINVER=0x0603"); + } + let target = if cfg!(feature = "1mib") { "snmallocshim-1mib-rust" } else if cfg!(feature = "16mib") { @@ -105,7 +120,9 @@ fn main() { } if target_env == "msvc" { - println!("cargo:rustc-link-lib=dylib=mincore"); + if cfg!(not(feature = "win8compat")) { + println!("cargo:rustc-link-lib=dylib=mincore"); + } } if target_os == "windows" && target_env == "gnu" { @@ -179,7 +196,7 @@ fn main() { } else if triple.contains("x86_64") { cfg = cfg.define("ANDROID_ABI", "x86_64"); } else if triple.contains("i686") { - cfg = cfg.define("ANDROID_ABI", "x86_64"); + cfg = cfg.define("ANDROID_ABI", "x86"); } else if triple.contains("neon") { cfg = cfg.define("ANDROID_ABI", "armeabi-v7a with NEON") } else if triple.contains("arm") { @@ -190,6 +207,9 @@ fn main() { if cfg!(all(windows, target_env = "msvc")) { cfg = cfg.define("CMAKE_CXX_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc"); cfg = cfg.define("CMAKE_C_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc"); + if cfg!(feature = "win8compat") { + cfg = cfg.define("WIN8COMPAT", "ON") + } } if cfg!(all(windows, target_env = "gnu")) { @@ -208,6 +228,10 @@ fn main() { cfg = cfg.define("SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE", "ON") } + if cfg!(feature = "usecxx20") { + cfg = cfg.define("SNMALLOC_USE_CXX20", "ON") + } + if cfg!(feature = "stats") { cfg = cfg.define("USE_SNMALLOC_STATS", "ON") } @@ -229,7 +253,9 @@ fn main() { println!("cargo:rustc-link-lib={}", target); if cfg!(all(windows, target_env = "msvc")) { - println!("cargo:rustc-link-lib=dylib=mincore"); + if cfg!(not(feature = "win8compat")) { + println!("cargo:rustc-link-lib=dylib=mincore"); + } println!( "cargo:rustc-link-search=native={}/{}", dst.display(), @@ -258,7 +284,7 @@ fn main() { .lines() .filter(|line| line.starts_with("libraries: =")) .map(|line| line.split_at("libraries: =".len()).1) - .flat_map(|line| line.split(";")) + .flat_map(|line| line.split(';')) .for_each(|path| { println!("cargo:rustc-link-search=native={}", path); }); diff --git a/src/lib.rs b/src/lib.rs index d89008043..8a94f0a89 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -79,7 +79,7 @@ mod tests { let layout = Layout::from_size_align(8, 8).unwrap(); let alloc = SnMalloc; - let ptr = alloc.alloc(layout.clone()); + let ptr = alloc.alloc(layout); alloc.dealloc(ptr, layout); } } @@ -90,7 +90,7 @@ mod tests { let layout = Layout::from_size_align(8, 8).unwrap(); let alloc = SnMalloc; - let ptr = alloc.alloc_zeroed(layout.clone()); + let ptr = alloc.alloc_zeroed(layout); alloc.dealloc(ptr, layout); } } @@ -101,8 +101,8 @@ mod tests { let layout = Layout::from_size_align(8, 8).unwrap(); let alloc = SnMalloc; - let ptr = alloc.alloc(layout.clone()); - let ptr = alloc.realloc(ptr, layout.clone(), 16); + let ptr = alloc.alloc(layout); + let ptr = alloc.realloc(ptr, layout, 16); alloc.dealloc(ptr, layout); } } From 96ee80ecf9392ff5c24ccd5cfada6d8d2876c6a1 Mon Sep 17 00:00:00 2001 From: SchrodingerZhu Date: Sun, 2 May 2021 18:38:09 +0800 Subject: [PATCH 113/145] bump version to 0.2.27 --- CHANGELOG.md | 2 ++ Cargo.toml | 4 ++-- README.md | 22 +++++++++++++--------- snmalloc-sys/Cargo.toml | 4 ++-- snmalloc-sys/snmalloc | 2 +- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35aff8858..0b5ea2895 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ - Reduction of libc dependency - **upstream** Windows 7 and windows 8 compatibility added - **upstream** Option to use C++20 standards if available +- **upstream** Preparations of cherification (heavy refactors of the structure) +- **upstream** Cold routine annotations ### 0.2.26 diff --git a/Cargo.toml b/Cargo.toml index b44cde490..3d8509eed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.26" +version = "0.2.27" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.26", path = "snmalloc-sys",default-features = false } +snmalloc-sys = {version = "0.2.27", path = "snmalloc-sys", default-features = false } [features] default = ["snmalloc-sys/build_cmake","1mib"] diff --git a/README.md b/README.md index 5dbea6c4a..ba4ceebd6 100644 --- a/README.md +++ b/README.md @@ -21,11 +21,12 @@ There are three features defined in this crate: - `16mib`: Use the `16mib` chunk configuration. - `cache-friendly`: Make the allocator more cache friendly (setting `CACHE_FRIENDLY_OFFSET` to `64` in building the library). - `native-cpu`: Optimize `snmalloc` for the native CPU of the host machine. (this is not a default behavior since `0.2.14`) -- `qemu`: workaround `madvise` problem of QEMU environment -- `stats`: enable statistics -- `local_dynamic_tls`: workaround cannot allocate memory in static tls block -- `build_cc`: use of cc crate instead of cmake (cmake still default) as builder (more platform agnostic) - +- `qemu`: Workaround `madvise` problem of QEMU environment +- `stats`: Enable statistics +- `local_dynamic_tls`: Workaround cannot allocate memory in static tls block +- `build_cc`: Use of cc crate instead of cmake (cmake still default) as builder (more platform agnostic) +- `usecxx20`: Enable C++20 standard if available +- `win8compat`: Improve compatibility for old Windows platforms (removing usages of `VirtualAlloc2` and other new APIs) **To get the crates compiled, you need to choose either `1mib` or `16mib` to determine the chunk configuration** @@ -66,6 +67,13 @@ Hence, please make sure the following libs are in your `PATH`: ## Changelog +### 0.2.27 +- Reduction of libc dependency +- **upstream** Windows 7 and windows 8 compatibility added +- **upstream** Option to use C++20 standards if available +- **upstream** Preparations of cherification (heavy refactors of the structure) +- **upstream** Cold routine annotations + ### 0.2.26 - **upstream** Building adjustment @@ -84,8 +92,4 @@ Hence, please make sure the following libs are in your `PATH`: - **upstream** update to use a more efficient power of 2 check - fix msvc support w/ crt-static -### 0.2.23 - -- **upstream** fix external pagemap usage - for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 685ea8a3d..de13180fa 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.26" +version = "0.2.27" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -31,4 +31,4 @@ android-shared-stl = [] native-cpu = [] local_dynamic_tls = [] win8compat = [] -usecxx20 = [] \ No newline at end of file +usecxx20 = [] diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index c5b65d07b..e3a7eab78 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit c5b65d07b8079b22eec9f78bec197ea7a0fd15f2 +Subproject commit e3a7eab78923e84cb2301797590583279880cf6c From da669818b654619c185e93b0e4a990d7678daa1e Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 2 May 2021 12:03:56 +0100 Subject: [PATCH 114/145] no hardcoded profile for build_cc build. --- snmalloc-sys/build.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index a8a3ec1ce..fbad0ea03 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -1,5 +1,10 @@ #[cfg(feature = "build_cc")] fn main() { + let (debug, optim) = if cfg!(feature = "debug") { + (true, "-O0") + } else { + (false, "-O3") + }; let mut build = cc::Build::new(); build.include("snmalloc/src"); build.file("snmalloc/src/override/rust.cc".to_string()); @@ -22,7 +27,7 @@ fn main() { build.flag_if_supported("/Zc:wchar_t"); build.flag_if_supported("/Zc:forScope"); build.flag_if_supported("/Zc:inline"); - build.flag_if_supported("-O3"); + build.flag_if_supported(optim); build.flag_if_supported("-mcx16"); build.flag_if_supported("-fno-exceptions"); build.flag_if_supported("-fno-rtti"); @@ -31,7 +36,7 @@ fn main() { build.flag_if_supported("-fpermissive"); build.static_crt(true); build.cpp(true); - build.debug(false); + build.debug(debug); if cfg!(feature = "usecxx20") { build.flag_if_supported("-std=c++17"); //original required if cxx20 not supported build.flag_if_supported("/std:c++17"); From 91fd8fb0f1e23394cbccb583df775f7e21707127 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Mon, 3 May 2021 01:53:40 +0100 Subject: [PATCH 115/145] add MSVC support possibly --- snmalloc-sys/build.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index fbad0ea03..8fab47682 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -1,9 +1,9 @@ #[cfg(feature = "build_cc")] fn main() { - let (debug, optim) = if cfg!(feature = "debug") { - (true, "-O0") + let (debug, optim_unix, optim_msvc, prof_msvc_hint) = if cfg!(feature = "debug") { + (true, "-O0", "/O0", "/DEBUG") } else { - (false, "-O3") + (false, "-O3", "/O2", "/RELEASE") }; let mut build = cc::Build::new(); build.include("snmalloc/src"); @@ -27,7 +27,9 @@ fn main() { build.flag_if_supported("/Zc:wchar_t"); build.flag_if_supported("/Zc:forScope"); build.flag_if_supported("/Zc:inline"); - build.flag_if_supported(optim); + build.flag_if_supported(prof_msvc_hint); + build.flag_if_supported(optim_msvc); + build.flag_if_supported(optim_unix); build.flag_if_supported("-mcx16"); build.flag_if_supported("-fno-exceptions"); build.flag_if_supported("-fno-rtti"); From 4292a34a10c58b0223888e954596b28b13407e00 Mon Sep 17 00:00:00 2001 From: Schrodinger ZHU Yifan Date: Mon, 11 Oct 2021 12:33:27 +0800 Subject: [PATCH 116/145] Snmalloc v1 maintain oct 10 2021 (#161) * bump module Signed-off-by: Schrodinger ZHU Yifan * deprecate cache-friendly Signed-off-by: Schrodinger ZHU Yifan * bump version and use exposed alloc_zeroed Signed-off-by: Schrodinger ZHU Yifan * update change log Signed-off-by: Schrodinger ZHU Yifan --- CHANGELOG.md | 5 ++++ Cargo.toml | 4 ++-- README.md | 53 +++++++++++++++++++++++++---------------- snmalloc-sys/Cargo.toml | 2 +- snmalloc-sys/build.rs | 16 +++++++------ snmalloc-sys/snmalloc | 2 +- snmalloc-sys/src/lib.rs | 20 ++++++++++++++++ src/lib.rs | 7 ++++++ 8 files changed, 77 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b5ea2895..301bde727 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Changelog +### 0.2.28 +- Deprecation of `cache-friendly` +- Use exposed `alloc_zeroed` from `snmalloc` +- **upstream** changes of remote communication, corruption detection and compilation flag detection. + ### 0.2.27 - Reduction of libc dependency diff --git a/Cargo.toml b/Cargo.toml index 3d8509eed..2e180d2c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.2.27" +version = "0.2.28" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.27", path = "snmalloc-sys", default-features = false } +snmalloc-sys = {version = "0.2.28", path = "snmalloc-sys", default-features = false } [features] default = ["snmalloc-sys/build_cmake","1mib"] diff --git a/README.md b/README.md index ba4ceebd6..02b8de66f 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,39 @@ # snmalloc-rs -**Notice: MinGW Build is broken and may not be fixed in a near future. See [this PR](https://github.com/microsoft/snmalloc/pull/217) in the upstream.** + +**Notice: MinGW Build is broken and may not be fixed in a near future. +See [this PR](https://github.com/microsoft/snmalloc/pull/217) in the upstream.** MSVC/MinGW/Linux/MacOS: [![Actions Status](https://github.com/schrodingerzhu/snmalloc-rs/workflows/Rust/badge.svg)](https://github.com/schrodingerzhu/snmalloc-rs/actions) FreeBSD: [![Build Status](https://api.cirrus-ci.com/github/SchrodingerZhu/snmalloc-rs.svg)](https://cirrus-ci.com/github/SchrodingerZhu/snmalloc-rs) -`snmalloc-rs` provides a wrapper for [`microsoft/snmalloc`](https://github.com/microsoft/snmalloc) to make it usable as a global allocator for rust. -snmalloc is a research allocator. Its key design features are: +`snmalloc-rs` provides a wrapper for [`microsoft/snmalloc`](https://github.com/microsoft/snmalloc) to make it usable as +a global allocator for rust. snmalloc is a research allocator. Its key design features are: - Memory that is freed by the same thread that allocated it does not require any synchronising operations. -- Freeing memory in a different thread to initially allocated it, does not take any locks and instead uses a novel message passing scheme to return the memory to the original allocator, where it is recycled. +- Freeing memory in a different thread to initially allocated it, does not take any locks and instead uses a novel + message passing scheme to return the memory to the original allocator, where it is recycled. - The allocator uses large ranges of pages to reduce the amount of meta-data required. -Some old benchmark results are available in the [`snmalloc` paper](https://github.com/microsoft/snmalloc/blob/master/snmalloc.pdf). Some recent benchmark results are listed at -[bench_suite](https://github.com/SchrodingerZhu/bench_suite). -There are three features defined in this crate: +Some old benchmark results are available in +the [`snmalloc` paper](https://github.com/microsoft/snmalloc/blob/master/snmalloc.pdf). Some recent benchmark results +are listed at +[bench_suite](https://github.com/SchrodingerZhu/bench_suite). There are three features defined in this crate: - `debug`: Enable the `Debug` mode in `snmalloc`. - `1mib`: Use the `1mib` chunk configuration. From `0.2.17`, this is set as a default feature - `16mib`: Use the `16mib` chunk configuration. -- `cache-friendly`: Make the allocator more cache friendly (setting `CACHE_FRIENDLY_OFFSET` to `64` in building the library). -- `native-cpu`: Optimize `snmalloc` for the native CPU of the host machine. (this is not a default behavior since `0.2.14`) +- `cache-friendly`: Make the allocator more cache friendly (setting `CACHE_FRIENDLY_OFFSET` to `64` in building the + library). + (**deprecated since 0.2.28**) +- `native-cpu`: Optimize `snmalloc` for the native CPU of the host machine. (this is not a default behavior + since `0.2.14`) - `qemu`: Workaround `madvise` problem of QEMU environment - `stats`: Enable statistics - `local_dynamic_tls`: Workaround cannot allocate memory in static tls block - `build_cc`: Use of cc crate instead of cmake (cmake still default) as builder (more platform agnostic) - `usecxx20`: Enable C++20 standard if available -- `win8compat`: Improve compatibility for old Windows platforms (removing usages of `VirtualAlloc2` and other new APIs) +- `win8compat`: Improve compatibility for old Windows platforms (removing usages of `VirtualAlloc2` and other new APIs) **To get the crates compiled, you need to choose either `1mib` or `16mib` to determine the chunk configuration** @@ -47,15 +54,16 @@ static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc; ## For MinGW Users -`mingw` version is only tested on nightly branch with MSYS environment. We are using dynamic linking method. -Hence, please make sure the following libs are in your `PATH`: +`mingw` version is only tested on nightly branch with MSYS environment. We are using dynamic linking method. Hence, +please make sure the following libs are in your `PATH`: - `winpthread` - `atomic` - `stdc++` -- `gcc_s` +- `gcc_s` -**Notice:** since version `0.2.12`, we no longer require you to provide additional environment variables for `mingw` target. +**Notice:** since version `0.2.12`, we no longer require you to provide additional environment variables for `mingw` +target. ## For Android Cross-Compilation @@ -63,11 +71,19 @@ Hence, please make sure the following libs are in your `PATH`: - `ANDROID_PLATFORM` can be passed as an optional environment variable - `ANDROID_ABI` used by CMake is detected automatically - feature `android-lld` can be used to set the linker of `snmalloc` to `lld` -- feature `android-shared-std` can be used to set the STL library of `snmalloc` to `c++_shared` (it uses `c++_static` by default) +- feature `android-shared-std` can be used to set the STL library of `snmalloc` to `c++_shared` (it uses `c++_static` by + default) ## Changelog +### 0.2.28 + +- Deprecation of `cache-friendly` +- Use exposed `alloc_zeroed` from `snmalloc` +- **upstream** changes of remote communication, corruption detection and compilation flag detection. + ### 0.2.27 + - Reduction of libc dependency - **upstream** Windows 7 and windows 8 compatibility added - **upstream** Option to use C++20 standards if available @@ -80,16 +96,11 @@ Hence, please make sure the following libs are in your `PATH`: - option of cc crate as build feature, only c compiler needed, no cmake required - Addition of dynamic local TLS option - ### 0.2.25 - **upstream** Apple M1 support - **upstream** Building adjust -- non-allocation tracking functions - -### 0.2.24 +- non-allocation tracking functions -- **upstream** update to use a more efficient power of 2 check -- fix msvc support w/ crt-static for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index de13180fa..9c52c937b 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.2.27" +version = "0.2.28" authors = ["schrodingerzhu "] edition = "2018" license = "MIT" diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 8fab47682..9eae227d0 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -117,7 +117,10 @@ fn main() { } if cfg!(feature = "cache-friendly") { - build.define("CACHE_FRIENDLY_OFFSET", "64"); + eprintln!("cache-friendly feature flag is deprecated and no longer has any effect. \ + it may be removed in a future release"); + // The following code no longer works + // build.define("CACHE_FRIENDLY_OFFSET", "64"); } build.compile(target); @@ -247,14 +250,13 @@ fn main() { cfg = cfg.define("SNMALLOC_QEMU_WORKAROUND", "ON") } - let mut dst = if cfg!(feature = "cache-friendly") { - cfg.define("CACHE_FRIENDLY_OFFSET", "64") - .build_target(target) - .build() - } else { - cfg.build_target(target).build() + if cfg!(feature = "cache-friendly") { + eprintln!("cache-friendly feature flag is deprecated and no longer has any effect. \ + it may be removed in a future release"); }; + let mut dst = cfg.build_target(target).build(); + dst.push("./build"); println!("cargo:rustc-link-lib={}", target); diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index e3a7eab78..6e638742e 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit e3a7eab78923e84cb2301797590583279880cf6c +Subproject commit 6e638742e3c66549174d4c264bd05c9435938ac1 diff --git a/snmalloc-sys/src/lib.rs b/snmalloc-sys/src/lib.rs index 952bb92ce..b77dd194f 100644 --- a/snmalloc-sys/src/lib.rs +++ b/snmalloc-sys/src/lib.rs @@ -3,6 +3,13 @@ use {core::ffi::c_void, core::usize}; +#[cfg_attr( +feature = "cache-friendly", +deprecated( +since = "0.2.28", +note = "Crate `snmalloc-sys` enables cache-friendly feature flag, \ + which is deprecated and no longer has any effect. \ + It may be removed in a future release"))] extern "C" { /// Allocate the memory with the given alignment and size. /// On success, it returns a pointer pointing to the required memory address. @@ -20,6 +27,9 @@ extern "C" { /// The program may be forced to abort if the constrains are not full-filled. pub fn rust_dealloc(ptr: *mut c_void, alignment: usize, size: usize) -> c_void; + /// Behaves like rust_alloc, but also ensures that the contents are set to zero before being returned. + pub fn rust_alloc_zeroed(alignment: usize, size: usize) -> *mut c_void; + /// Re-allocate the memory at the given address with the given alignment and size. /// On success, it returns a pointer pointing to the required memory address. /// The memory content within the `new_size` will remains the same as previous. @@ -68,6 +78,15 @@ extern "C" { mod tests { use super::*; + #[test] + fn it_zero_allocs_correctly() { + let ptr = unsafe { rust_alloc_zeroed(8, 1024) } as *mut u8 as *mut [u8; 1024]; + unsafe { + assert!((*ptr).iter().all(|x| *x == 0)); + }; + unsafe { rust_dealloc(ptr as *mut c_void, 8, 1024) }; + } + #[test] fn it_frees_memory_malloc() { let ptr = unsafe { rust_alloc(8, 8) } as *mut u8; @@ -77,6 +96,7 @@ mod tests { }; unsafe { rust_dealloc(ptr as *mut c_void, 8, 8) }; } + #[test] fn it_frees_memory_sn_malloc() { let ptr = unsafe { sn_malloc(8) } as *mut u8; diff --git a/src/lib.rs b/src/lib.rs index 8a94f0a89..fc693e7f1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,6 +44,13 @@ unsafe impl GlobalAlloc for SnMalloc { ffi::rust_alloc(layout.align(), layout.size()) as _ } + + /// Behaves like alloc, but also ensures that the contents are set to zero before being returned. + #[inline(always)] + unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { + ffi::rust_alloc_zeroed(layout.align(), layout.size()) as _ + } + /// De-allocate the memory at the given address with the given alignment and size. /// The client must assure the following things: /// - the memory is acquired using the same allocator and the pointer points to the start position. From 8247795d75b374cd5b71339a73c961a30b70bd36 Mon Sep 17 00:00:00 2001 From: Schrodinger ZHU Yifan Date: Sun, 30 Jan 2022 17:37:18 +0800 Subject: [PATCH 117/145] Snmalloc 2 (#164) support snmalloc 2 --- .github/workflows/rust.yml | 16 +++--- CHANGELOG.md | 4 ++ Cargo.toml | 17 +++--- README.md | 35 +++++------- snmalloc-sys/Cargo.toml | 13 ++--- snmalloc-sys/build.rs | 110 ++++++++++++++++++------------------- snmalloc-sys/snmalloc | 2 +- snmalloc-sys/src/lib.rs | 29 ++++------ src/lib.rs | 18 +++--- 9 files changed, 114 insertions(+), 130 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index b8048ff20..d45adaf55 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -15,7 +15,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, windows-latest, macOS-latest] + os: [windows-latest, macos-11, ubuntu-latest] rust: [stable, nightly] steps: - uses: actions-rs/toolchain@v1 @@ -25,15 +25,17 @@ jobs: uses: actions/checkout@v2 with: submodules: recursive + - name: update dependency + run: | + if bash -c 'uname -s | grep 'Linux' >/dev/null'; then + sudo apt-get update -y && sudo apt-get --reinstall install -y libc6-dev + fi + shell: bash - name: Build run: cargo build --verbose - name: Run tests run: cargo test --all - - name: Run tests 1mib - run: cargo test --all --features 1mib - - name: Run tests 1mib build_cc - run: cargo test --all --features build_cc - name: Run tests debug run: cargo test --all --features debug - - name: Run tests cache-friendly - run: cargo test --all --features cache-friendly \ No newline at end of file + - name: Run tests check + run: cargo test --all --features check \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 301bde727..beaf8a107 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +### 0.3.0-beta.1 + +- Beta release to support snmalloc 2 + ### 0.2.28 - Deprecation of `cache-friendly` - Use exposed `alloc_zeroed` from `snmalloc` diff --git a/Cargo.toml b/Cargo.toml index 2e180d2c8..fb9d0f6dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "snmalloc-rs" -version = "0.2.28" +version = "0.3.0-beta.1+f1be609" authors = ["schrodingerzhu "] -edition = "2018" +edition = "2021" license = "MIT" description = "rust bindings of snmalloc." keywords = ["snmalloc", "allocator"] @@ -16,20 +16,17 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.2.28", path = "snmalloc-sys", default-features = false } +snmalloc-sys = {version = "0.3.0-beta.1", path = "snmalloc-sys", default-features = false } [features] -default = ["snmalloc-sys/build_cmake","1mib"] -build_cc = ["snmalloc-sys/build_cc","1mib"] -1mib = ["snmalloc-sys/1mib"] -16mib = ["snmalloc-sys/16mib"] +default = ["snmalloc-sys/build_cmake"] +build_cc = ["snmalloc-sys/build_cc"] qemu = ["snmalloc-sys/qemu"] stats = ["snmalloc-sys/stats"] debug = ["snmalloc-sys/debug"] -cache-friendly = ["snmalloc-sys/cache-friendly"] android-lld = ["snmalloc-sys/android-lld"] -android-shared-stl = ["snmalloc-sys/android-shared-stl"] native-cpu = ["snmalloc-sys/native-cpu"] local_dynamic_tls = ["snmalloc-sys/local_dynamic_tls"] win8compat = ["snmalloc-sys/win8compat"] -usecxx20 = ["snmalloc-sys/usecxx20"] +usecxx17 = ["snmalloc-sys/usecxx17"] +check = ["snmalloc-sys/check"] \ No newline at end of file diff --git a/README.md b/README.md index 02b8de66f..0a99b9cb9 100644 --- a/README.md +++ b/README.md @@ -21,18 +21,19 @@ are listed at [bench_suite](https://github.com/SchrodingerZhu/bench_suite). There are three features defined in this crate: - `debug`: Enable the `Debug` mode in `snmalloc`. -- `1mib`: Use the `1mib` chunk configuration. From `0.2.17`, this is set as a default feature -- `16mib`: Use the `16mib` chunk configuration. -- `cache-friendly`: Make the allocator more cache friendly (setting `CACHE_FRIENDLY_OFFSET` to `64` in building the - library). - (**deprecated since 0.2.28**) +- ~~`1mib`: Use the `1mib` chunk configuration. From `0.2.17`, this is set as a default feature~~ (removed since 0.3.0) +- ~~`16mib`: Use the `16mib` chunk configuration.~~ (removed since 0.3.0) +- ~~`cache-friendly`: Make the allocator more cache friendly (setting `CACHE_FRIENDLY_OFFSET` to `64` in building the + library).~~ (removed since 0.3.0) - `native-cpu`: Optimize `snmalloc` for the native CPU of the host machine. (this is not a default behavior since `0.2.14`) - `qemu`: Workaround `madvise` problem of QEMU environment - `stats`: Enable statistics - `local_dynamic_tls`: Workaround cannot allocate memory in static tls block - `build_cc`: Use of cc crate instead of cmake (cmake still default) as builder (more platform agnostic) -- `usecxx20`: Enable C++20 standard if available +- ~~`usecxx20`: Enable C++20 standard if available~~ (removed since 0.3.0) +- `usecxx17`: Use C++17 standard +- `check`: Enable extra checks to improve security - `win8compat`: Improve compatibility for old Windows platforms (removing usages of `VirtualAlloc2` and other new APIs) **To get the crates compiled, you need to choose either `1mib` or `16mib` to determine the chunk configuration** @@ -42,7 +43,7 @@ To use `snmalloc-rs` add it as a dependency: ```toml # Cargo.toml [dependencies] -snmalloc-rs = "0.2" +snmalloc-rs = "0.3-beta.1" ``` To set `SnMalloc` as the global allocator add this to your project: @@ -71,11 +72,15 @@ target. - `ANDROID_PLATFORM` can be passed as an optional environment variable - `ANDROID_ABI` used by CMake is detected automatically - feature `android-lld` can be used to set the linker of `snmalloc` to `lld` -- feature `android-shared-std` can be used to set the STL library of `snmalloc` to `c++_shared` (it uses `c++_static` by - default) +- ~~feature `android-shared-std` can be used to set the STL library of `snmalloc` to `c++_shared` (it uses `c++_static` by + default)~~ (`libstdc++` is no longer a dependency) ## Changelog +### 0.3.0-beta.1 + +- Beta release to support snmalloc 2 + ### 0.2.28 - Deprecation of `cache-friendly` @@ -90,17 +95,5 @@ target. - **upstream** Preparations of cherification (heavy refactors of the structure) - **upstream** Cold routine annotations -### 0.2.26 - -- **upstream** Building adjustment -- option of cc crate as build feature, only c compiler needed, no cmake required -- Addition of dynamic local TLS option - -### 0.2.25 - -- **upstream** Apple M1 support -- **upstream** Building adjust -- non-allocation tracking functions - for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 9c52c937b..43ebd3b8e 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "snmalloc-sys" -version = "0.2.28" +version = "0.3.0-beta.1+f1be609" authors = ["schrodingerzhu "] -edition = "2018" +edition = "2021" license = "MIT" description = "rust raw bindings of snmalloc." keywords = ["snmalloc", "allocator"] @@ -17,18 +17,15 @@ cc = {version = "1.0",optional=true} cmake = {version = "0.1",optional=true} [features] -default = ["1mib","build_cmake"] +default = ["build_cmake"] build_cc = ["cc"] build_cmake = ["cmake"] -1mib = [] -16mib = [] qemu = [] stats = [] debug = [] -cache-friendly = [] android-lld = [] -android-shared-stl = [] native-cpu = [] local_dynamic_tls = [] win8compat = [] -usecxx20 = [] +usecxx17 = [] +check = [] diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 9eae227d0..a94b82403 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -39,20 +39,17 @@ fn main() { build.static_crt(true); build.cpp(true); build.debug(debug); - if cfg!(feature = "usecxx20") { - build.flag_if_supported("-std=c++17"); //original required if cxx20 not supported + if cfg!(feature = "usecxx17") { + build.flag_if_supported("-std=c++17"); build.flag_if_supported("/std:c++17"); build.flag_if_supported("-Wc++17-extensions"); build.flag_if_supported("/Wc++17-extensions"); + build.define("SNMALLOC_USE_CXX17", "1"); + } else { build.flag_if_supported("-std=c++20"); build.flag_if_supported("/std:c++20"); build.flag_if_supported("-Wc++20-extensions"); build.flag_if_supported("/Wc++20-extensions"); - } else { - build.flag_if_supported("-std=c++17"); - build.flag_if_supported("/std:c++17"); - build.flag_if_supported("-Wc++17-extensions"); - build.flag_if_supported("/Wc++17-extensions"); } let triple = std::env::var("TARGET").unwrap(); @@ -92,15 +89,13 @@ fn main() { } if cfg!(feature = "win8compat") { - build.flag_if_supported("-DWINVER=0x0603"); + build.define("WINVER", "0x0603"); } - let target = if cfg!(feature = "1mib") { - "snmallocshim-1mib-rust" - } else if cfg!(feature = "16mib") { - "snmallocshim-16mib-rust" + let target = if cfg!(feature = "check") { + "snmallocshim-rust" } else { - panic!("please set a chunk configuration"); + "snmallocshim-checks-rust" }; if cfg!(feature = "native-cpu") { @@ -125,10 +120,6 @@ fn main() { build.compile(target); - if cfg!(feature = "android-shared-stl") { - println!("cargo:rustc-link-lib=dylib=c++_shared"); - } - if target_env == "msvc" { if cfg!(not(feature = "win8compat")) { println!("cargo:rustc-link-lib=dylib=mincore"); @@ -139,22 +130,29 @@ fn main() { println!("cargo:rustc-link-lib=dylib=atomic"); } - if target_os == "macos" { - println!("cargo:rustc-link-lib=dylib=c++"); - } - - if target_os == "openbsd" { - println!("cargo:rustc-link-lib=dylib=c++"); - } - - if target_os == "freebsd" { - println!("cargo:rustc-link-lib=dylib=c++"); - } - if target_os == "linux" { - println!("cargo:rustc-link-lib=dylib=stdc++"); println!("cargo:rustc-link-lib=dylib=atomic"); }; + + if cfg!(target_os = "freebsd") { + // using THREAD_DESTRUCTOR + } else if cfg!(all(unix, not(target_os = "macos"))) { + if cfg!(target_env = "gnu") { + println!("cargo:rustc-link-lib=c_nonshared"); + } + } else if cfg!(windows) { + // no need + } else { + // link c++ runtime + println!("cargo:rustc-link-lib={}", + std::env::var("CXXSTDLIB").unwrap_or_else(|_| { + if cfg!(target_os = "macos") || cfg!(target_os = "openbsd") { + "c++".to_string() + } else { + "stdc++".to_string() + } + })) + } } #[cfg(not(feature = "build_cc"))] @@ -226,20 +224,18 @@ fn main() { cfg = cfg.define("CMAKE_SH", "CMAKE_SH-NOTFOUND"); } - let target = if cfg!(feature = "1mib") { - "snmallocshim-1mib-rust" - } else if cfg!(feature = "16mib") { - "snmallocshim-16mib-rust" + let target = if cfg!(feature = "check") { + "snmallocshim-checks-rust" } else { - panic!("please set a chunk configuration"); + "snmallocshim-rust" }; if cfg!(feature = "native-cpu") { cfg = cfg.define("SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE", "ON") } - if cfg!(feature = "usecxx20") { - cfg = cfg.define("SNMALLOC_USE_CXX20", "ON") + if cfg!(feature = "usecxx17") { + cfg = cfg.define("SNMALLOC_USE_CXX17", "ON") } if cfg!(feature = "stats") { @@ -250,11 +246,6 @@ fn main() { cfg = cfg.define("SNMALLOC_QEMU_WORKAROUND", "ON") } - if cfg!(feature = "cache-friendly") { - eprintln!("cache-friendly feature flag is deprecated and no longer has any effect. \ - it may be removed in a future release"); - }; - let mut dst = cfg.build_target(target).build(); dst.push("./build"); @@ -297,27 +288,34 @@ fn main() { .for_each(|path| { println!("cargo:rustc-link-search=native={}", path); }); - - println!("cargo:rustc-link-lib=dylib=stdc++"); println!("cargo:rustc-link-lib=dylib=atomic"); println!("cargo:rustc-link-lib=dylib=winpthread"); println!("cargo:rustc-link-lib=dylib=gcc_s"); } - if cfg!(target_os = "macos") { - println!("cargo:rustc-link-lib=dylib=c++"); - } - - if cfg!(target_os = "openbsd") { - println!("cargo:rustc-link-lib=dylib=c++"); + // linux: using PTHREAD_DESTRUCTORS + if cfg!(target_os = "linux") { + println!("cargo:rustc-link-lib=dylib=atomic"); } if cfg!(target_os = "freebsd") { - println!("cargo:rustc-link-lib=dylib=c++"); - } - - if cfg!(target_os = "linux") { - println!("cargo:rustc-link-lib=dylib=stdc++"); - println!("cargo:rustc-link-lib=dylib=atomic"); + // using THREAD_DESTRUCTOR + } else if cfg!(all(unix, not(target_os = "macos"))) { + // using PTHREAD_DESTRUCTOR + if cfg!(target_env = "gnu") { + println!("cargo:rustc-link-lib=c_nonshared"); + } + } else if cfg!(windows) { + // not need for explicit c++ runtime + } else { + // link c++ runtime + println!("cargo:rustc-link-lib={}", + std::env::var("CXXSTDLIB").unwrap_or_else(|_| { + if cfg!(target_os = "macos") || cfg!(target_os = "openbsd") { + "c++".to_string() + } else { + "stdc++".to_string() + } + })) } } diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 6e638742e..f1be609cd 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 6e638742e3c66549174d4c264bd05c9435938ac1 +Subproject commit f1be609cdbd564018d506a91f02ab26b3dd619af diff --git a/snmalloc-sys/src/lib.rs b/snmalloc-sys/src/lib.rs index b77dd194f..19803b98e 100644 --- a/snmalloc-sys/src/lib.rs +++ b/snmalloc-sys/src/lib.rs @@ -3,13 +3,6 @@ use {core::ffi::c_void, core::usize}; -#[cfg_attr( -feature = "cache-friendly", -deprecated( -since = "0.2.28", -note = "Crate `snmalloc-sys` enables cache-friendly feature flag, \ - which is deprecated and no longer has any effect. \ - It may be removed in a future release"))] extern "C" { /// Allocate the memory with the given alignment and size. /// On success, it returns a pointer pointing to the required memory address. @@ -18,17 +11,17 @@ extern "C" { /// - `alignment` is greater than zero /// - `alignment` is a power of 2 /// The program may be forced to abort if the constrains are not full-filled. - pub fn rust_alloc(alignment: usize, size: usize) -> *mut c_void; + pub fn sn_rust_alloc(alignment: usize, size: usize) -> *mut c_void; /// De-allocate the memory at the given address with the given alignment and size. /// The client must assure the following things: /// - the memory is acquired using the same allocator and the pointer points to the start position. /// - `alignment` and `size` is the same as allocation /// The program may be forced to abort if the constrains are not full-filled. - pub fn rust_dealloc(ptr: *mut c_void, alignment: usize, size: usize) -> c_void; + pub fn sn_rust_dealloc(ptr: *mut c_void, alignment: usize, size: usize) -> c_void; /// Behaves like rust_alloc, but also ensures that the contents are set to zero before being returned. - pub fn rust_alloc_zeroed(alignment: usize, size: usize) -> *mut c_void; + pub fn sn_rust_alloc_zeroed(alignment: usize, size: usize) -> *mut c_void; /// Re-allocate the memory at the given address with the given alignment and size. /// On success, it returns a pointer pointing to the required memory address. @@ -39,7 +32,7 @@ extern "C" { /// - `alignment` and `old_size` is the same as allocation /// - `alignment` fulfills all the requirements as `rust_alloc` /// The program may be forced to abort if the constrains are not full-filled. - pub fn rust_realloc( + pub fn sn_rust_realloc( ptr: *mut c_void, alignment: usize, old_size: usize, @@ -80,21 +73,21 @@ mod tests { #[test] fn it_zero_allocs_correctly() { - let ptr = unsafe { rust_alloc_zeroed(8, 1024) } as *mut u8 as *mut [u8; 1024]; + let ptr = unsafe { sn_rust_alloc_zeroed(8, 1024) } as *mut u8 as *mut [u8; 1024]; unsafe { assert!((*ptr).iter().all(|x| *x == 0)); }; - unsafe { rust_dealloc(ptr as *mut c_void, 8, 1024) }; + unsafe { sn_rust_dealloc(ptr as *mut c_void, 8, 1024) }; } #[test] fn it_frees_memory_malloc() { - let ptr = unsafe { rust_alloc(8, 8) } as *mut u8; + let ptr = unsafe { sn_rust_alloc(8, 8) } as *mut u8; unsafe { *ptr = 127; assert_eq!(*ptr, 127) }; - unsafe { rust_dealloc(ptr as *mut c_void, 8, 8) }; + unsafe { sn_rust_dealloc(ptr as *mut c_void, 8, 8) }; } #[test] @@ -112,14 +105,14 @@ mod tests { #[test] fn it_reallocs_correctly() { - let mut ptr = unsafe { rust_alloc(8, 8) } as *mut u8; + let mut ptr = unsafe { sn_rust_alloc(8, 8) } as *mut u8; unsafe { *ptr = 127; assert_eq!(*ptr, 127) }; - ptr = unsafe { rust_realloc(ptr as *mut c_void, 8, 8, 16) } as *mut u8; + ptr = unsafe { sn_rust_realloc(ptr as *mut c_void, 8, 8, 16) } as *mut u8; unsafe { assert_eq!(*ptr, 127) }; - unsafe { rust_dealloc(ptr as *mut c_void, 8, 16) }; + unsafe { sn_rust_dealloc(ptr as *mut c_void, 8, 16) }; } #[test] diff --git a/src/lib.rs b/src/lib.rs index fc693e7f1..cc31c3190 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,16 +41,10 @@ unsafe impl GlobalAlloc for SnMalloc { /// The program may be forced to abort if the constrains are not full-filled. #[inline(always)] unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - ffi::rust_alloc(layout.align(), layout.size()) as _ + ffi::sn_rust_alloc(layout.align(), layout.size()) as _ } - /// Behaves like alloc, but also ensures that the contents are set to zero before being returned. - #[inline(always)] - unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { - ffi::rust_alloc_zeroed(layout.align(), layout.size()) as _ - } - /// De-allocate the memory at the given address with the given alignment and size. /// The client must assure the following things: /// - the memory is acquired using the same allocator and the pointer points to the start position. @@ -58,7 +52,13 @@ unsafe impl GlobalAlloc for SnMalloc { /// The program may be forced to abort if the constrains are not full-filled. #[inline(always)] unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { - ffi::rust_dealloc(ptr as _, layout.align(), layout.size()); + ffi::sn_rust_dealloc(ptr as _, layout.align(), layout.size()); + } + + /// Behaves like alloc, but also ensures that the contents are set to zero before being returned. + #[inline(always)] + unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { + ffi::sn_rust_alloc_zeroed(layout.align(), layout.size()) as _ } /// Re-allocate the memory at the given address with the given alignment and size. @@ -72,7 +72,7 @@ unsafe impl GlobalAlloc for SnMalloc { /// The program may be forced to abort if the constrains are not full-filled. #[inline(always)] unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { - ffi::rust_realloc(ptr as _, layout.align(), layout.size(), new_size) as _ + ffi::sn_rust_realloc(ptr as _, layout.align(), layout.size(), new_size) as _ } } From c86b12164b5df3e578a526d80b7d2771b616b36c Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Wed, 18 May 2022 08:19:02 -0400 Subject: [PATCH 118/145] Correct dependency version (#166) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0a99b9cb9..0971175fd 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ To use `snmalloc-rs` add it as a dependency: ```toml # Cargo.toml [dependencies] -snmalloc-rs = "0.3-beta.1" +snmalloc-rs = "0.3.0-beta.1" ``` To set `SnMalloc` as the global allocator add this to your project: From 19e6103e96549537eaa86b96b53a8378162fab37 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Tue, 31 May 2022 04:12:51 +0100 Subject: [PATCH 119/145] 0.3.0 release (#167) --- CHANGELOG.md | 5 +++++ Cargo.toml | 5 ++--- README.md | 13 +++++++++---- snmalloc-sys/Cargo.toml | 3 +-- snmalloc-sys/build.rs | 4 ---- snmalloc-sys/snmalloc | 2 +- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index beaf8a107..ec012bf45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Changelog +### 0.3.0 +- Release to follow upstream 0.6.0 +- **upstream** Major redesign of the code to improve performance and + enable a mode that provides strong checks against corruption. + ### 0.3.0-beta.1 - Beta release to support snmalloc 2 diff --git a/Cargo.toml b/Cargo.toml index fb9d0f6dd..2a845ffab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.3.0-beta.1+f1be609" +version = "0.3.0" authors = ["schrodingerzhu "] edition = "2021" license = "MIT" @@ -16,13 +16,12 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.3.0-beta.1", path = "snmalloc-sys", default-features = false } +snmalloc-sys = {version = "0.3.0", path = "snmalloc-sys", default-features = false } [features] default = ["snmalloc-sys/build_cmake"] build_cc = ["snmalloc-sys/build_cc"] qemu = ["snmalloc-sys/qemu"] -stats = ["snmalloc-sys/stats"] debug = ["snmalloc-sys/debug"] android-lld = ["snmalloc-sys/android-lld"] native-cpu = ["snmalloc-sys/native-cpu"] diff --git a/README.md b/README.md index 0971175fd..c037ad839 100644 --- a/README.md +++ b/README.md @@ -28,12 +28,13 @@ are listed at - `native-cpu`: Optimize `snmalloc` for the native CPU of the host machine. (this is not a default behavior since `0.2.14`) - `qemu`: Workaround `madvise` problem of QEMU environment -- `stats`: Enable statistics +- ~~`stats`: Enable statistics~~ (removed since 0.3.0) - `local_dynamic_tls`: Workaround cannot allocate memory in static tls block - `build_cc`: Use of cc crate instead of cmake (cmake still default) as builder (more platform agnostic) - ~~`usecxx20`: Enable C++20 standard if available~~ (removed since 0.3.0) - `usecxx17`: Use C++17 standard -- `check`: Enable extra checks to improve security +- `check`: Enable extra checks to improve security, see upstream [security docs](https://github.com/microsoft/snmalloc/tree/main/docs/security). + Note that the `memcpy` protection is not enabled in Rust. - `win8compat`: Improve compatibility for old Windows platforms (removing usages of `VirtualAlloc2` and other new APIs) **To get the crates compiled, you need to choose either `1mib` or `16mib` to determine the chunk configuration** @@ -43,7 +44,7 @@ To use `snmalloc-rs` add it as a dependency: ```toml # Cargo.toml [dependencies] -snmalloc-rs = "0.3.0-beta.1" +snmalloc-rs = "0.3.0" ``` To set `SnMalloc` as the global allocator add this to your project: @@ -77,9 +78,13 @@ target. ## Changelog +### 0.3.0 + +- Release to support snmalloc 0.6.0. + ### 0.3.0-beta.1 -- Beta release to support snmalloc 2 +- Beta release to support snmalloc ~~2~~ 0.6.0 ### 0.2.28 diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 43ebd3b8e..91d6c25a3 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.3.0-beta.1+f1be609" +version = "0.3.0" authors = ["schrodingerzhu "] edition = "2021" license = "MIT" @@ -21,7 +21,6 @@ default = ["build_cmake"] build_cc = ["cc"] build_cmake = ["cmake"] qemu = [] -stats = [] debug = [] android-lld = [] native-cpu = [] diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index a94b82403..d26b03880 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -103,10 +103,6 @@ fn main() { build.flag_if_supported("-march=native"); } - if cfg!(feature = "stats") { - build.define("USE_SNMALLOC_STATS", "ON"); - } - if cfg!(feature = "qemu") { build.define("SNMALLOC_QEMU_WORKAROUND", "ON"); } diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index f1be609cd..d5c732f3c 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit f1be609cdbd564018d506a91f02ab26b3dd619af +Subproject commit d5c732f3c14969d119178cbc8382d592800c5421 From cdce0e0913a9a3c8e0b4ab015917983aaedb3aec Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Wed, 1 Jun 2022 15:49:34 +0100 Subject: [PATCH 120/145] build_cc fix (#168) --- .github/workflows/rust.yml | 4 +++- snmalloc-sys/build.rs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d45adaf55..8f4e5fb42 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -38,4 +38,6 @@ jobs: - name: Run tests debug run: cargo test --all --features debug - name: Run tests check - run: cargo test --all --features check \ No newline at end of file + run: cargo test --all --features check + - name: Run tests build_cc + run: cargo test --all --features "build_cc usecxx17" \ No newline at end of file diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index d26b03880..a43124841 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -6,8 +6,8 @@ fn main() { (false, "-O3", "/O2", "/RELEASE") }; let mut build = cc::Build::new(); - build.include("snmalloc/src"); - build.file("snmalloc/src/override/rust.cc".to_string()); + build.include("snmalloc/src/snmalloc"); + build.file("snmalloc/src/snmalloc/override/rust.cc".to_string()); build.flag_if_supported("/O2"); build.flag_if_supported("/Zi"); build.flag_if_supported("/nologo"); From ab17b1aa88e117f6187bad96633179acd9f48b33 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Wed, 1 Jun 2022 19:52:08 +0100 Subject: [PATCH 121/145] Add native-cpu to CI --- .github/workflows/rust.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 8f4e5fb42..9134ebb58 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -40,4 +40,6 @@ jobs: - name: Run tests check run: cargo test --all --features check - name: Run tests build_cc - run: cargo test --all --features "build_cc usecxx17" \ No newline at end of file + run: cargo test --all --features "build_cc usecxx17" + - name: Run tests build_cc + run: cargo test --all --features native-cpu \ No newline at end of file From 83952a4b754487222426fb289b055a79ec7b4e58 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Tue, 7 Jun 2022 20:16:44 +0100 Subject: [PATCH 122/145] Updates for 0.3.1 release --- CHANGELOG.md | 4 ++++ Cargo.toml | 4 ++-- README.md | 14 +++++--------- snmalloc-sys/Cargo.toml | 2 +- snmalloc-sys/snmalloc | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec012bf45..c5c0493b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +### 0.3.1 +- Fixes `build_cc` feature (broken in 0.3.0 release). +- Fixes `native-cpu` feature (broken in 0.3.0 release). + ### 0.3.0 - Release to follow upstream 0.6.0 - **upstream** Major redesign of the code to improve performance and diff --git a/Cargo.toml b/Cargo.toml index 2a845ffab..2a87f8e44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.3.0" +version = "0.3.1" authors = ["schrodingerzhu "] edition = "2021" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.3.0", path = "snmalloc-sys", default-features = false } +snmalloc-sys = {version = "0.3.1", path = "snmalloc-sys", default-features = false } [features] default = ["snmalloc-sys/build_cmake"] diff --git a/README.md b/README.md index c037ad839..d6fadcf0d 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,11 @@ target. ## Changelog +### 0.3.1 + +- Fixes `build_cc` feature (broken in 0.3.0 release). +- Fixes `native-cpu` feature (broken in 0.3.0 release). + ### 0.3.0 - Release to support snmalloc 0.6.0. @@ -92,13 +97,4 @@ target. - Use exposed `alloc_zeroed` from `snmalloc` - **upstream** changes of remote communication, corruption detection and compilation flag detection. -### 0.2.27 - -- Reduction of libc dependency -- **upstream** Windows 7 and windows 8 compatibility added -- **upstream** Option to use C++20 standards if available -- **upstream** Preparations of cherification (heavy refactors of the structure) -- **upstream** Cold routine annotations - - for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 91d6c25a3..4971d9c99 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.3.0" +version = "0.3.1" authors = ["schrodingerzhu "] edition = "2021" license = "MIT" diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index d5c732f3c..e17672d3c 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit d5c732f3c14969d119178cbc8382d592800c5421 +Subproject commit e17672d3c14200250badf6a2426707bd6d0bbe90 From 20ce0f207e4b676a6890e5b9fbbbaeeb91d8fd59 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Fri, 17 Jun 2022 06:30:18 +0100 Subject: [PATCH 123/145] Version bump --- CHANGELOG.md | 3 +++ Cargo.toml | 4 ++-- README.md | 4 ++++ snmalloc-sys/Cargo.toml | 2 +- snmalloc-sys/snmalloc | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5c0493b1..0edd74464 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Changelog +### 0.3.2 +- Tracking upstream to enable old Linux variants. + ### 0.3.1 - Fixes `build_cc` feature (broken in 0.3.0 release). - Fixes `native-cpu` feature (broken in 0.3.0 release). diff --git a/Cargo.toml b/Cargo.toml index 2a87f8e44..4ed8e31be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.3.1" +version = "0.3.2" authors = ["schrodingerzhu "] edition = "2021" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.3.1", path = "snmalloc-sys", default-features = false } +snmalloc-sys = {version = "0.3.2", path = "snmalloc-sys", default-features = false } [features] default = ["snmalloc-sys/build_cmake"] diff --git a/README.md b/README.md index d6fadcf0d..b828d0635 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,10 @@ target. ## Changelog +### 0.3.2 + +- Tracking upstream to enable old Linux variants. + ### 0.3.1 - Fixes `build_cc` feature (broken in 0.3.0 release). diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 4971d9c99..58812c672 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.3.1" +version = "0.3.2" authors = ["schrodingerzhu "] edition = "2021" license = "MIT" diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index e17672d3c..6b0bda01c 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit e17672d3c14200250badf6a2426707bd6d0bbe90 +Subproject commit 6b0bda01c7ab2323ad7ac5e4e850751f50345c4a From 5d97eabc76b2ce71d2f0ca727f9b20c3c722bd78 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Fri, 17 Jun 2022 11:17:45 +0100 Subject: [PATCH 124/145] Version bump --- CHANGELOG.md | 3 +++ Cargo.toml | 4 ++-- README.md | 11 +++-------- snmalloc-sys/Cargo.toml | 2 +- snmalloc-sys/snmalloc | 2 +- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0edd74464..3f3c9a960 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Changelog +### 0.3.3 +- Tracking upstream to fix Linux PAL typo. + ### 0.3.2 - Tracking upstream to enable old Linux variants. diff --git a/Cargo.toml b/Cargo.toml index 4ed8e31be..ba0e03c0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.3.2" +version = "0.3.3" authors = ["schrodingerzhu "] edition = "2021" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.3.2", path = "snmalloc-sys", default-features = false } +snmalloc-sys = {version = "0.3.3", path = "snmalloc-sys", default-features = false } [features] default = ["snmalloc-sys/build_cmake"] diff --git a/README.md b/README.md index b828d0635..fa43bed5e 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,9 @@ target. ## Changelog +### 0.3.3 +- Tracking upstream to fix Linux PAL typo. + ### 0.3.2 - Tracking upstream to enable old Linux variants. @@ -94,11 +97,3 @@ target. ### 0.3.0-beta.1 - Beta release to support snmalloc ~~2~~ 0.6.0 - -### 0.2.28 - -- Deprecation of `cache-friendly` -- Use exposed `alloc_zeroed` from `snmalloc` -- **upstream** changes of remote communication, corruption detection and compilation flag detection. - -for older versions, see [CHANGELOG](CHANGELOG.md) diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 58812c672..4588dc5b9 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.3.2" +version = "0.3.3" authors = ["schrodingerzhu "] edition = "2021" license = "MIT" diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 6b0bda01c..c560a9aa2 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 6b0bda01c7ab2323ad7ac5e4e850751f50345c4a +Subproject commit c560a9aa275d7c31593a957261812d8657665b10 From aa0d2419fa732b9a11e3f0071ed40e765b92bae0 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Thu, 29 Jun 2023 12:40:34 +0100 Subject: [PATCH 125/145] Update snmalloc to latest release. (#175) * Update snmalloc to latest release. * Update docs. Signed-off-by: Matthew Parkinson --- CHANGELOG.md | 3 +++ Cargo.toml | 4 ++-- README.md | 5 ++++- snmalloc-sys/Cargo.toml | 2 +- snmalloc-sys/snmalloc | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f3c9a960..25a5879cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Changelog +### 0.3.4 +- Tracking upstream to match version 0.6.2 + ### 0.3.3 - Tracking upstream to fix Linux PAL typo. diff --git a/Cargo.toml b/Cargo.toml index ba0e03c0e..cda9752b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.3.3" +version = "0.3.4" authors = ["schrodingerzhu "] edition = "2021" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.3.3", path = "snmalloc-sys", default-features = false } +snmalloc-sys = {version = "0.3.4", path = "snmalloc-sys", default-features = false } [features] default = ["snmalloc-sys/build_cmake"] diff --git a/README.md b/README.md index fa43bed5e..96bafd179 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ To use `snmalloc-rs` add it as a dependency: ```toml # Cargo.toml [dependencies] -snmalloc-rs = "0.3.0" +snmalloc-rs = "0.3.4" ``` To set `SnMalloc` as the global allocator add this to your project: @@ -78,6 +78,9 @@ target. ## Changelog +### 0.3.4 +- Tracking upstream to version 0.6.2. + ### 0.3.3 - Tracking upstream to fix Linux PAL typo. diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 4588dc5b9..dcedae7ac 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.3.3" +version = "0.3.4" authors = ["schrodingerzhu "] edition = "2021" license = "MIT" diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index c560a9aa2..dc1268886 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit c560a9aa275d7c31593a957261812d8657665b10 +Subproject commit dc1268886a5d49d38a54e5d1402b5924a71fee0b From 21adcc37bdecc0c9b8712c2cbcd9e6c39ac29479 Mon Sep 17 00:00:00 2001 From: Schrodinger ZHU Yifan Date: Sat, 10 Feb 2024 13:17:38 -0500 Subject: [PATCH 126/145] ci: update freebsd to 15-snap (#177) --- .cirrus.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.cirrus.yml b/.cirrus.yml index f662c1406..e1130e82e 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,5 +1,5 @@ freebsd_instance: - image_family: freebsd-13-0-snap + image_family: freebsd-15-0-snap task: name: cargo test (stable) env: From e0e4bfa931f1aaefab57f1e48348828310e35122 Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Sat, 10 Feb 2024 18:26:14 +0000 Subject: [PATCH 127/145] update proposal. (#176) - snmalloc to last version. - then adding a handful of available build options, diabling TLS support and LTO linkage. Signed-off-by: David Carlier --- Cargo.toml | 4 +++- snmalloc-sys/Cargo.toml | 2 ++ snmalloc-sys/build.rs | 50 ++++++++++++++++++++++++++--------------- snmalloc-sys/snmalloc | 2 +- src/lib.rs | 12 +++++++++- 5 files changed, 49 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cda9752b1..0b126cbb8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,4 +28,6 @@ native-cpu = ["snmalloc-sys/native-cpu"] local_dynamic_tls = ["snmalloc-sys/local_dynamic_tls"] win8compat = ["snmalloc-sys/win8compat"] usecxx17 = ["snmalloc-sys/usecxx17"] -check = ["snmalloc-sys/check"] \ No newline at end of file +check = ["snmalloc-sys/check"] +lto = ["snmalloc-sys/lto"] +notls = ["snmalloc-sys/notls"] diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index dcedae7ac..85452c835 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -28,3 +28,5 @@ local_dynamic_tls = [] win8compat = [] usecxx17 = [] check = [] +lto = [] +notls = [] diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index a43124841..a1d02d81b 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -108,12 +108,22 @@ fn main() { } if cfg!(feature = "cache-friendly") { - eprintln!("cache-friendly feature flag is deprecated and no longer has any effect. \ - it may be removed in a future release"); + eprintln!( + "cache-friendly feature flag is deprecated and no longer has any effect. \ + it may be removed in a future release" + ); // The following code no longer works // build.define("CACHE_FRIENDLY_OFFSET", "64"); } + if cfg!(feature = "lto") { + build.define("SNMALLOC_IPO", "ON"); + } + + if cfg!(feature = "notls") { + build.define("SNMALLOC_ENABLE_DYNAMIC_LOADING", "ON"); + } + build.compile(target); if target_env == "msvc" { @@ -140,14 +150,16 @@ fn main() { // no need } else { // link c++ runtime - println!("cargo:rustc-link-lib={}", - std::env::var("CXXSTDLIB").unwrap_or_else(|_| { - if cfg!(target_os = "macos") || cfg!(target_os = "openbsd") { - "c++".to_string() - } else { - "stdc++".to_string() - } - })) + println!( + "cargo:rustc-link-lib={}", + std::env::var("CXXSTDLIB").unwrap_or_else(|_| { + if cfg!(target_os = "macos") || cfg!(target_os = "openbsd") { + "c++".to_string() + } else { + "stdc++".to_string() + } + }) + ) } } @@ -305,13 +317,15 @@ fn main() { // not need for explicit c++ runtime } else { // link c++ runtime - println!("cargo:rustc-link-lib={}", - std::env::var("CXXSTDLIB").unwrap_or_else(|_| { - if cfg!(target_os = "macos") || cfg!(target_os = "openbsd") { - "c++".to_string() - } else { - "stdc++".to_string() - } - })) + println!( + "cargo:rustc-link-lib={}", + std::env::var("CXXSTDLIB").unwrap_or_else(|_| { + if cfg!(target_os = "macos") || cfg!(target_os = "openbsd") { + "c++".to_string() + } else { + "stdc++".to_string() + } + }) + ) } } diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index dc1268886..b8e9e99cf 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit dc1268886a5d49d38a54e5d1402b5924a71fee0b +Subproject commit b8e9e99cf096357d37c67d423ccb657652879ba1 diff --git a/src/lib.rs b/src/lib.rs index cc31c3190..457fcbf94 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,7 +44,6 @@ unsafe impl GlobalAlloc for SnMalloc { ffi::sn_rust_alloc(layout.align(), layout.size()) as _ } - /// De-allocate the memory at the given address with the given alignment and size. /// The client must assure the following things: /// - the memory is acquired using the same allocator and the pointer points to the start position. @@ -113,4 +112,15 @@ mod tests { alloc.dealloc(ptr, layout); } } + + #[test] + fn it_frees_large_alloc() { + unsafe { + let layout = Layout::from_size_align(1 << 20, 32).unwrap(); + let alloc = SnMalloc; + + let ptr = alloc.alloc(layout); + alloc.dealloc(ptr, layout); + } + } } From 9e939e91cddb89553b65584054d6b0450fffe0ae Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Mon, 12 Feb 2024 14:52:22 +0000 Subject: [PATCH 128/145] exposing sn_malloc_usable_size as a mean to assess how much the (#178) * exposing sn_malloc_usable_size as a mean to assess how much the underlying allocator actually rounded up the allocated size. Signed-off-by: David Carlier --- src/lib.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 457fcbf94..1d6ad6a8c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,6 +75,17 @@ unsafe impl GlobalAlloc for SnMalloc { } } +impl SnMalloc { + /// Returns the available bytes in a memory block. + /// + /// Note that the value could be higher than the allocation size and + /// depends very much on the underlying operating system. + #[inline(always)] + pub fn usable_size(&self, ptr: *const u8) -> usize { + unsafe { ffi::sn_malloc_usable_size(ptr as *const _) } + } +} + #[cfg(test)] mod tests { use super::*; @@ -123,4 +134,17 @@ mod tests { alloc.dealloc(ptr, layout); } } + + #[test] + fn it_usable_size() { + unsafe { + let layout = Layout::from_size_align(8, 8).unwrap(); + let alloc = SnMalloc; + + let ptr = alloc.alloc(layout); + let usz = alloc.usable_size(ptr); + alloc.dealloc(ptr, layout); + assert!(usz >= 8); + } + } } From 609bcb01f9ec592a11aa3010bea4fcf1ce815dd7 Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Thu, 29 Feb 2024 15:11:30 +0000 Subject: [PATCH 129/145] update readme to reflect last changes (#179) Signed-off-by: David Carlier --- Cargo.toml | 4 ++-- README.md | 2 ++ snmalloc-sys/Cargo.toml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0b126cbb8..d7c0d73cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.3.4" +version = "0.3.5" authors = ["schrodingerzhu "] edition = "2021" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys" ] [dependencies] -snmalloc-sys = {version = "0.3.4", path = "snmalloc-sys", default-features = false } +snmalloc-sys = {version = "0.3.5", path = "snmalloc-sys", default-features = false } [features] default = ["snmalloc-sys/build_cmake"] diff --git a/README.md b/README.md index 96bafd179..95c28bf2d 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ are listed at - `check`: Enable extra checks to improve security, see upstream [security docs](https://github.com/microsoft/snmalloc/tree/main/docs/security). Note that the `memcpy` protection is not enabled in Rust. - `win8compat`: Improve compatibility for old Windows platforms (removing usages of `VirtualAlloc2` and other new APIs) +- `lto`: Links with InterProceduralOptimization/LinkTimeOptimization +- `notls`: Enables to be loaded dynamically, thus disable tls. **To get the crates compiled, you need to choose either `1mib` or `16mib` to determine the chunk configuration** diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 85452c835..2a268c15c 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.3.4" +version = "0.3.5" authors = ["schrodingerzhu "] edition = "2021" license = "MIT" From 8897bb70e7d85ecb8105fc598314ba1cc50391ea Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Wed, 27 Mar 2024 18:39:18 +0000 Subject: [PATCH 130/145] fix needless borrow clippy warning for gcc on windows (#180) --- snmalloc-sys/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index a1d02d81b..c3efe1f78 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -275,7 +275,7 @@ fn main() { if cfg!(all(windows, target_env = "gnu")) { let stdout = std::process::Command::new("gcc") - .args(&["-print-search-dirs"]) + .args(["-print-search-dirs"]) .output() .unwrap_or_else(|_| { eprintln!("Cannot run gcc.exe"); From 09ae27052601a1a1f4435e6da3527881600219de Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Wed, 27 Mar 2024 19:16:53 +0000 Subject: [PATCH 131/145] adding macos 14 (arm64) to CI (#181) --- .github/workflows/rust.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9134ebb58..a2566c4a9 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -15,7 +15,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [windows-latest, macos-11, ubuntu-latest] + os: [windows-latest, macos-11, macos-14, ubuntu-latest] rust: [stable, nightly] steps: - uses: actions-rs/toolchain@v1 @@ -42,4 +42,4 @@ jobs: - name: Run tests build_cc run: cargo test --all --features "build_cc usecxx17" - name: Run tests build_cc - run: cargo test --all --features native-cpu \ No newline at end of file + run: cargo test --all --features native-cpu From 0f6017120abac69a53838d3ecc79adeb4f4bceb0 Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Sat, 30 Mar 2024 17:16:41 +0000 Subject: [PATCH 132/145] github actions update (#182) --- .github/workflows/rust.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a2566c4a9..1a6baab71 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -41,5 +41,9 @@ jobs: run: cargo test --all --features check - name: Run tests build_cc run: cargo test --all --features "build_cc usecxx17" - - name: Run tests build_cc + - name: Run tests native-cpu run: cargo test --all --features native-cpu + - name: Run tests local_dynamic_tls + run: cargo test --all --features local_dynamic_tls + - name: Run tests lto + run: cargo test --all --features lto From b130a788e3a8a425fe9df541c72cf619fc0313ff Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Wed, 12 Jun 2024 18:56:48 +0100 Subject: [PATCH 133/145] update snmalloc to last updates. (#183) also it had switched to main branch last year. --- .gitmodules | 2 +- snmalloc-sys/snmalloc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 2bf92f3aa..c5e2acf02 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "new"] path = snmalloc-sys/snmalloc url = https://github.com/microsoft/snmalloc - branch = master + branch = main diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index b8e9e99cf..d9bca6442 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit b8e9e99cf096357d37c67d423ccb657652879ba1 +Subproject commit d9bca644260847f3b325f4d0e12f0360ed1c0dac From 1e9b09f2195ddf38b7a1904f3f45de88a3490339 Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Wed, 12 Jun 2024 18:57:10 +0100 Subject: [PATCH 134/145] fix clippy warnings (#184) --- Cargo.toml | 1 + README.md | 1 + snmalloc-sys/Cargo.toml | 1 + snmalloc-sys/build.rs | 8 -------- snmalloc-sys/src/lib.rs | 2 +- 5 files changed, 4 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d7c0d73cf..1d19ada18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,3 +31,4 @@ usecxx17 = ["snmalloc-sys/usecxx17"] check = ["snmalloc-sys/check"] lto = ["snmalloc-sys/lto"] notls = ["snmalloc-sys/notls"] +stats = ["snmalloc-sys/stats"] diff --git a/README.md b/README.md index 95c28bf2d..2c2c6f801 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ are listed at - `win8compat`: Improve compatibility for old Windows platforms (removing usages of `VirtualAlloc2` and other new APIs) - `lto`: Links with InterProceduralOptimization/LinkTimeOptimization - `notls`: Enables to be loaded dynamically, thus disable tls. +- `stats`: Enables allocation statistics. **To get the crates compiled, you need to choose either `1mib` or `16mib` to determine the chunk configuration** diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 2a268c15c..3e0cc26ec 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -30,3 +30,4 @@ usecxx17 = [] check = [] lto = [] notls = [] +stats = [] diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index c3efe1f78..39fbcce51 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -61,9 +61,6 @@ fn main() { if cfg!(feature = "android-lld") { build.define("ANDROID_LD", "lld"); } - if cfg!(feature = "android-shared-stl") { - build.define("ANDROID_STL", "c++_shared"); - } if triple.contains("aarch64") { build.define("ANDROID_ABI", "arm64-v8a"); } else if triple.contains("armv7") { @@ -198,11 +195,6 @@ fn main() { cfg = cfg.define("ANDROID_LD", "lld"); } - if cfg!(feature = "android-shared-stl") { - println!("cargo:rustc-link-lib=dylib=c++_shared"); - cfg = cfg.define("ANDROID_STL", "c++_shared"); - } - if triple.contains("aarch64") { cfg = cfg.define("ANDROID_ABI", "arm64-v8a"); } else if triple.contains("armv7") { diff --git a/snmalloc-sys/src/lib.rs b/snmalloc-sys/src/lib.rs index 19803b98e..b4fc83ad1 100644 --- a/snmalloc-sys/src/lib.rs +++ b/snmalloc-sys/src/lib.rs @@ -1,7 +1,7 @@ #![no_std] #![allow(non_camel_case_types)] -use {core::ffi::c_void, core::usize}; +use core::ffi::c_void; extern "C" { /// Allocate the memory with the given alignment and size. From 865ded82f8fa867cc9bf92e6a078f39c2616109b Mon Sep 17 00:00:00 2001 From: Schrodinger ZHU Yifan Date: Wed, 12 Jun 2024 12:14:11 -0700 Subject: [PATCH 135/145] bump version (#185) --- Cargo.toml | 2 +- snmalloc-sys/Cargo.toml | 2 +- snmalloc-sys/snmalloc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1d19ada18..ea159fa2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.3.5" +version = "0.3.6" authors = ["schrodingerzhu "] edition = "2021" license = "MIT" diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 3e0cc26ec..d52400504 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.3.5" +version = "0.3.6" authors = ["schrodingerzhu "] edition = "2021" license = "MIT" diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index d9bca6442..2dba088d2 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit d9bca644260847f3b325f4d0e12f0360ed1c0dac +Subproject commit 2dba088d243e24d4ff09a016ef33a8a06f298980 From a564ef910b1209aedd4de4941baa69788c83d740 Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Fri, 20 Sep 2024 22:36:28 +0100 Subject: [PATCH 136/145] update to last changes on main (#186) --- snmalloc-sys/build.rs | 3 +-- snmalloc-sys/snmalloc | 2 +- snmalloc-sys/src/lib.rs | 25 +++++++++++++------------ src/lib.rs | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 39fbcce51..ff657ae1c 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -6,7 +6,7 @@ fn main() { (false, "-O3", "/O2", "/RELEASE") }; let mut build = cc::Build::new(); - build.include("snmalloc/src/snmalloc"); + build.include("snmalloc/src"); build.file("snmalloc/src/snmalloc/override/rust.cc".to_string()); build.flag_if_supported("/O2"); build.flag_if_supported("/Zi"); @@ -44,7 +44,6 @@ fn main() { build.flag_if_supported("/std:c++17"); build.flag_if_supported("-Wc++17-extensions"); build.flag_if_supported("/Wc++17-extensions"); - build.define("SNMALLOC_USE_CXX17", "1"); } else { build.flag_if_supported("-std=c++20"); build.flag_if_supported("/std:c++20"); diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 2dba088d2..d537d3526 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 2dba088d243e24d4ff09a016ef33a8a06f298980 +Subproject commit d537d352683799beea94c0698d85bcfa7f6f4ece diff --git a/snmalloc-sys/src/lib.rs b/snmalloc-sys/src/lib.rs index b4fc83ad1..499dc410b 100644 --- a/snmalloc-sys/src/lib.rs +++ b/snmalloc-sys/src/lib.rs @@ -42,12 +42,12 @@ extern "C" { /// Allocate `count` items of `size` length each. /// Returns `null` if `count * size` overflows or on out-of-memory. /// All items are initialized to zero. - pub fn sn_calloc(count: usize, size: usize) -> *mut c_void; + pub fn calloc(count: usize, size: usize) -> *mut c_void; /// Allocate `size` bytes. /// Returns pointer to the allocated memory or null if out of memory. /// Returns a unique pointer if called with `size` 0. - pub fn sn_malloc(size: usize) -> *mut c_void; + pub fn malloc(size: usize) -> *mut c_void; /// Re-allocate memory to `newsize` bytes. /// Return pointer to the allocated memory or null if out of memory. If null @@ -57,14 +57,14 @@ extern "C" { /// If `p` is null, it behaves as [`sn_malloc`]. If `newsize` is larger than /// the original `size` allocated for `p`, the bytes after `size` are /// uninitialized. - pub fn sn_realloc(p: *mut c_void, newsize: usize) -> *mut c_void; + pub fn realloc(p: *mut c_void, newsize: usize) -> *mut c_void; /// Free previously allocated memory. /// The pointer `p` must have been allocated before (or be null). - pub fn sn_free(p: *mut c_void); + pub fn free(p: *mut c_void); /// Return the available bytes in a memory block. - pub fn sn_malloc_usable_size(p: *const c_void) -> usize; + pub fn sn_rust_usable_size(p: *const c_void) -> usize; } #[cfg(test)] @@ -92,15 +92,15 @@ mod tests { #[test] fn it_frees_memory_sn_malloc() { - let ptr = unsafe { sn_malloc(8) } as *mut u8; - unsafe { sn_free(ptr as *mut c_void) }; + let ptr = unsafe { malloc(8) } as *mut u8; + unsafe { free(ptr as *mut c_void) }; } #[test] fn it_frees_memory_sn_realloc() { - let ptr = unsafe { sn_malloc(8) } as *mut u8; - let ptr = unsafe { sn_realloc(ptr as *mut c_void, 8) } as *mut u8; - unsafe { sn_free(ptr as *mut c_void) }; + let ptr = unsafe { malloc(8) } as *mut u8; + let ptr = unsafe { realloc(ptr as *mut c_void, 8) } as *mut u8; + unsafe { free(ptr as *mut c_void) }; } #[test] @@ -117,11 +117,12 @@ mod tests { #[test] fn it_calculates_usable_size() { - let ptr = unsafe { sn_malloc(32) } as *mut u8; - let usable_size = unsafe { sn_malloc_usable_size(ptr as *mut c_void) }; + let ptr = unsafe { sn_rust_alloc(32, 8) } as *mut u8; + let usable_size = unsafe { sn_rust_usable_size(ptr as *mut c_void) }; assert!( usable_size >= 32, "usable_size should at least equal to the allocated size" ); + unsafe { sn_rust_dealloc(ptr as *mut c_void, 32, 8) }; } } diff --git a/src/lib.rs b/src/lib.rs index 1d6ad6a8c..a957963dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,7 +82,7 @@ impl SnMalloc { /// depends very much on the underlying operating system. #[inline(always)] pub fn usable_size(&self, ptr: *const u8) -> usize { - unsafe { ffi::sn_malloc_usable_size(ptr as *const _) } + unsafe { ffi::sn_rust_usable_size(ptr as *const _) } } } From 95fd6cec7f8f07093ca25c2cb947abb1a9ce3615 Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Tue, 29 Oct 2024 17:06:32 +0000 Subject: [PATCH 137/145] github action for macOs is going to remove 12 release support. (#188) ref: https://github.com/actions/runner-images/issues/10721 --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1a6baab71..9573899f1 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -15,7 +15,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [windows-latest, macos-11, macos-14, ubuntu-latest] + os: [windows-latest, macos-13, macos-14, ubuntu-latest] rust: [stable, nightly] steps: - uses: actions-rs/toolchain@v1 From 743c6728e20eaf7054fea970434fd7692669ab9b Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Sat, 16 Nov 2024 21:04:42 +0000 Subject: [PATCH 138/145] snmalloc to benefits from recent fixes. (#189) --- .github/workflows/rust.yml | 2 +- Cargo.toml | 1 + snmalloc-sys/Cargo.toml | 1 + snmalloc-sys/build.rs | 12 ++++++++++++ snmalloc-sys/snmalloc | 2 +- 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9573899f1..ea10f7456 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -15,7 +15,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [windows-latest, macos-13, macos-14, ubuntu-latest] + os: [windows-latest, macos-14, macos-15, ubuntu-latest] rust: [stable, nightly] steps: - uses: actions-rs/toolchain@v1 diff --git a/Cargo.toml b/Cargo.toml index ea159fa2e..84207b19f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,3 +32,4 @@ check = ["snmalloc-sys/check"] lto = ["snmalloc-sys/lto"] notls = ["snmalloc-sys/notls"] stats = ["snmalloc-sys/stats"] +#nowait-on-target = ["snmalloc-sys/nowait-on-target"] diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index d52400504..fb286fda9 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -31,3 +31,4 @@ check = [] lto = [] notls = [] stats = [] +#usewait-on-target = [] diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index ff657ae1c..7880aeed2 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -120,6 +120,12 @@ fn main() { build.define("SNMALLOC_ENABLE_DYNAMIC_LOADING", "ON"); } + if cfg!(feature = "usewait-on-address") { + build.define("SNMALLOC_USE_WAIT_ON_ADDRESS", "1"); + } else { + build.define("SNMALLOC_USE_WAIT_ON_ADDRESS", "0"); + } + build.compile(target); if target_env == "msvc" { @@ -245,6 +251,12 @@ fn main() { cfg = cfg.define("SNMALLOC_QEMU_WORKAROUND", "ON") } + if cfg!(feature = "usewait-on-address") { + cfg = cfg.define("SNMALLOC_USE_WAIT_ON_ADDRESS", "1") + } else { + cfg = cfg.define("SNMALLOC_USE_WAIT_ON_ADDRESS", "0") + } + let mut dst = cfg.build_target(target).build(); dst.push("./build"); diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index d537d3526..01885f5a0 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit d537d352683799beea94c0698d85bcfa7f6f4ece +Subproject commit 01885f5a042f1ba7812d18df36b4ec76b0ad8b40 From a517429d09c7424a27a26705470589b6d1f561a9 Mon Sep 17 00:00:00 2001 From: Schrodinger ZHU Yifan Date: Thu, 28 Nov 2024 12:14:53 -0500 Subject: [PATCH 139/145] sync up with upstream (#190) --- CHANGELOG.md | 4 ++++ Cargo.toml | 10 +++++----- snmalloc-sys/Cargo.toml | 8 ++++---- snmalloc-sys/build.rs | 5 +++-- snmalloc-sys/snmalloc | 2 +- src/lib.rs | 3 +++ 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25a5879cd..1dd514f1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +### 0.3.7 + +- Tracking upstream to match version 0.7 + ### 0.3.4 - Tracking upstream to match version 0.6.2 diff --git a/Cargo.toml b/Cargo.toml index 84207b19f..bb47f9e05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.3.6" +version = "0.3.7" authors = ["schrodingerzhu "] edition = "2021" license = "MIT" @@ -13,13 +13,13 @@ readme = "README.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [workspace] -members = ["snmalloc-sys" ] +members = ["snmalloc-sys"] [dependencies] -snmalloc-sys = {version = "0.3.5", path = "snmalloc-sys", default-features = false } +snmalloc-sys = { version = "0.3.7", path = "snmalloc-sys", default-features = false } [features] -default = ["snmalloc-sys/build_cmake"] +default = ["snmalloc-sys/build_cmake", "snmalloc-sys/usewait-on-address"] build_cc = ["snmalloc-sys/build_cc"] qemu = ["snmalloc-sys/qemu"] debug = ["snmalloc-sys/debug"] @@ -32,4 +32,4 @@ check = ["snmalloc-sys/check"] lto = ["snmalloc-sys/lto"] notls = ["snmalloc-sys/notls"] stats = ["snmalloc-sys/stats"] -#nowait-on-target = ["snmalloc-sys/nowait-on-target"] +usewait-on-address = ["snmalloc-sys/usewait-on-address"] diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index fb286fda9..8739bf533 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.3.6" +version = "0.3.7" authors = ["schrodingerzhu "] edition = "2021" license = "MIT" @@ -13,8 +13,8 @@ build = "build.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [build-dependencies] -cc = {version = "1.0",optional=true} -cmake = {version = "0.1",optional=true} +cc = { version = "1.0", optional = true } +cmake = { version = "0.1", optional = true } [features] default = ["build_cmake"] @@ -31,4 +31,4 @@ check = [] lto = [] notls = [] stats = [] -#usewait-on-target = [] +usewait-on-address = [] diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 7880aeed2..c3d3ddc6d 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -260,8 +260,9 @@ fn main() { let mut dst = cfg.build_target(target).build(); dst.push("./build"); - - println!("cargo:rustc-link-lib={}", target); + // we need to specify static modifier, otherwise the linker may not be smart enough to resolve + // dependency from snmalloc to libc/libgcc_s + println!("cargo:rustc-link-lib=static={}", target); if cfg!(all(windows, target_env = "msvc")) { if cfg!(not(feature = "win8compat")) { diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 01885f5a0..564c88b07 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 01885f5a042f1ba7812d18df36b4ec76b0ad8b40 +Subproject commit 564c88b07c53728ec90a88d7d34d0f74d3b0bfff diff --git a/src/lib.rs b/src/lib.rs index a957963dc..b4e8158c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,6 +38,7 @@ unsafe impl GlobalAlloc for SnMalloc { /// The client must assure the following things: /// - `alignment` is greater than zero /// - Other constrains are the same as the rust standard library. + /// /// The program may be forced to abort if the constrains are not full-filled. #[inline(always)] unsafe fn alloc(&self, layout: Layout) -> *mut u8 { @@ -48,6 +49,7 @@ unsafe impl GlobalAlloc for SnMalloc { /// The client must assure the following things: /// - the memory is acquired using the same allocator and the pointer points to the start position. /// - Other constrains are the same as the rust standard library. + /// /// The program may be forced to abort if the constrains are not full-filled. #[inline(always)] unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { @@ -68,6 +70,7 @@ unsafe impl GlobalAlloc for SnMalloc { /// - the memory is acquired using the same allocator and the pointer points to the start position /// - `alignment` fulfills all the requirements as `rust_alloc` /// - Other constrains are the same as the rust standard library. + /// /// The program may be forced to abort if the constrains are not full-filled. #[inline(always)] unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { From c9d63b23ccf8e7be3c2a903ba7a52df4dc3c9ceb Mon Sep 17 00:00:00 2001 From: Ryan Clanton <55164720+ryancinsight@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:13:08 -0500 Subject: [PATCH 140/145] build compatibility and thread sharing (#191) * Update build.rs improve compatibilty and build errors on build_cc/cmake for windows * Update build.rs improve clang64 MSYSTEM linking pass tests * Update lib.rs, thread/process share safety null catches * Update build.rs ninja not necessary * Update build.rs ubuntu fix * Update build.rs unify builds and reconfigure freebsd In testing I noticed an almost doubling of test time between build_cc and cmake, they are now unified to make sure there is reduced chance of difference between builds. also enabled ability to read build environment of allocator * Update build.rs correct ubuntu linking to stdc++ for thread local safety * Update build.rs remove gcc link for tls * Update build.rs freebsd link c++ * Update build.rs LTO/IPO working on all builds, unix/linux * Update build.rs don't need static lib * Update build.rs correct lib location differences on windows * Update build.rs revert unix * Update build.rs unix family includes linux --- snmalloc-sys/build.rs | 719 ++++++++++++++++++++++++++---------------- src/lib.rs | 102 ++++-- 2 files changed, 525 insertions(+), 296 deletions(-) diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index c3d3ddc6d..263898846 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -1,335 +1,502 @@ -#[cfg(feature = "build_cc")] -fn main() { - let (debug, optim_unix, optim_msvc, prof_msvc_hint) = if cfg!(feature = "debug") { - (true, "-O0", "/O0", "/DEBUG") - } else { - (false, "-O3", "/O2", "/RELEASE") - }; - let mut build = cc::Build::new(); - build.include("snmalloc/src"); - build.file("snmalloc/src/snmalloc/override/rust.cc".to_string()); - build.flag_if_supported("/O2"); - build.flag_if_supported("/Zi"); - build.flag_if_supported("/nologo"); - build.flag_if_supported("/W4"); - build.flag_if_supported("/WX"); - build.flag_if_supported("/wd4127"); - build.flag_if_supported("/wd4324"); - build.flag_if_supported("/wd4201"); - build.flag_if_supported("/Ob2"); - build.flag_if_supported("/DNDEBUG"); - build.flag_if_supported("/EHsc"); - build.flag_if_supported("/Gd"); - build.flag_if_supported("/TP"); - build.flag_if_supported("/Gm-"); - build.flag_if_supported("/GS"); - build.flag_if_supported("/fp:precise"); - build.flag_if_supported("/Zc:wchar_t"); - build.flag_if_supported("/Zc:forScope"); - build.flag_if_supported("/Zc:inline"); - build.flag_if_supported(prof_msvc_hint); - build.flag_if_supported(optim_msvc); - build.flag_if_supported(optim_unix); - build.flag_if_supported("-mcx16"); - build.flag_if_supported("-fno-exceptions"); - build.flag_if_supported("-fno-rtti"); - build.flag_if_supported("-g"); - build.flag_if_supported("-fomit-frame-pointer"); - build.flag_if_supported("-fpermissive"); - build.static_crt(true); - build.cpp(true); - build.debug(debug); - if cfg!(feature = "usecxx17") { - build.flag_if_supported("-std=c++17"); - build.flag_if_supported("/std:c++17"); - build.flag_if_supported("-Wc++17-extensions"); - build.flag_if_supported("/Wc++17-extensions"); - } else { - build.flag_if_supported("-std=c++20"); - build.flag_if_supported("/std:c++20"); - build.flag_if_supported("-Wc++20-extensions"); - build.flag_if_supported("/Wc++20-extensions"); +#![allow(dead_code)] + +use std::env; +use std::fs; + +#[derive(Debug, PartialEq)] +enum Compiler { + Clang, + Gcc, + Msvc, + Unknown +} + +struct BuildConfig { + debug: bool, + optim_level: String, + target_os: String, + target_env: String, + target_family: String, + target: String, + out_dir: String, + build_type: String, + msystem: Option, + cmake_cxx_standard: String, + target_lib: String, + features: BuildFeatures, + #[cfg(feature = "build_cc")] + builder: cc::Build, + #[cfg(not(feature = "build_cc"))] + builder: cmake::Config, + compiler: Compiler +} + +impl std::fmt::Debug for BuildConfig { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("BuildConfig") + .field("debug", &self.debug) + .field("optim_level", &self.optim_level) + .field("target_os", &self.target_os) + .field("target_env", &self.target_env) + .field("target_family", &self.target_family) + .field("target", &self.target) + .field("out_dir", &self.out_dir) + .field("build_type", &self.build_type) + .field("msystem", &self.msystem) + .field("cmake_cxx_standard", &self.cmake_cxx_standard) + .field("target_lib", &self.target_lib) + .field("features", &self.features) + .finish() } +} - let triple = std::env::var("TARGET").unwrap(); - let target_os = std::env::var("CARGO_CFG_TARGET_OS").expect("target_os not defined!"); - let target_env = std::env::var("CARGO_CFG_TARGET_ENV").expect("target_env not defined!"); - let target_family = std::env::var("CARGO_CFG_TARGET_FAMILY").expect("target family not set"); +#[derive(Debug, Clone)] +struct BuildFeatures { + native_cpu: bool, + qemu: bool, + wait_on_address: bool, + lto: bool, + notls: bool, + win8compat: bool, + stats: bool, + android_lld: bool, + local_dynamic_tls: bool, +} - if triple.contains("android") { - if cfg!(feature = "android-lld") { - build.define("ANDROID_LD", "lld"); +impl BuildConfig { + fn new() -> Self { + let debug = cfg!(feature = "debug"); + #[cfg(feature = "build_cc")] + let builder = cc::Build::new(); + + #[cfg(not(feature = "build_cc"))] + let builder = Config::new("snmalloc"); + + let mut config = Self { + debug, + optim_level: (if debug { "-O0" } else { "-O3" }).to_string(), + target_os: env::var("CARGO_CFG_TARGET_OS").expect("target_os not defined!"), + target_env: env::var("CARGO_CFG_TARGET_ENV").expect("target_env not defined!"), + target_family: env::var("CARGO_CFG_TARGET_FAMILY").expect("target family not set"), + target: env::var("TARGET").expect("TARGET not set"), + out_dir: env::var("OUT_DIR").unwrap(), + build_type: (if debug { "Debug" } else { "Release" }).to_string(), + msystem: env::var("MSYSTEM").ok(), + cmake_cxx_standard: (if cfg!(feature = "usecxx17") { "17" } else { "20" }).to_string(), + target_lib: (if cfg!(feature = "check") { + "snmallocshim-checks-rust" + } else { + "snmallocshim-rust" + }).to_string(), + features: BuildFeatures::new(), + builder, + compiler: Compiler::Unknown, + }; + config.compiler = config.detect_compiler(); + config.embed_build_info(); + config + } + + fn detect_compiler(&self) -> Compiler { + // Check MSYSTEM for MSYS2 environments + if let Some(msystem) = &self.msystem { + match msystem.as_str() { + "CLANG64" | "CLANGARM64" => return Compiler::Clang, + "MINGW64" | "UCRT64" => return Compiler::Gcc, + _ => {} + } } - if triple.contains("aarch64") { - build.define("ANDROID_ABI", "arm64-v8a"); - } else if triple.contains("armv7") { - build.define("ANDROID_ABI", "armeabi-v7a"); - build.define("ANDROID_ARM_MODE", "arm"); - } else if triple.contains("x86_64") { - build.define("ANDROID_ABI", "x86_64"); - } else if triple.contains("i686") { - build.define("ANDROID_ABI", "x86"); - } else if triple.contains("neon") { - build.define("ANDROID_ABI", "armeabi-v7a with NEON"); - } else if triple.contains("arm") { - build.define("ANDROID_ABI", "armeabi-v7a"); + + // Check target environment + if let Ok(env) = env::var("CARGO_CFG_TARGET_ENV") { + match env.as_str() { + "msvc" => return Compiler::Msvc, + "gnu" => return Compiler::Gcc, + _ => {} + } } - } - if target_family == "unix" || target_env == "gnu" && target_os != "haiku" { - if cfg!(feature = "local_dynamic_tls") { - build.flag_if_supported("-ftls-model=local-dynamic"); - } else { - build.flag_if_supported("-ftls-model=initial-exec"); + // Check CC environment variable + if let Ok(cc) = env::var("CC") { + let cc = cc.to_lowercase(); + if cc.contains("clang") { + return Compiler::Clang; + } else if cc.contains("gcc") { + return Compiler::Gcc; + } } - } - if cfg!(feature = "win8compat") { - build.define("WINVER", "0x0603"); + // Default based on platform and target + if self.target.contains("msvc") { + Compiler::Msvc + } else if cfg!(windows) { + Compiler::Gcc // Assume GCC for non-MSVC Windows environments + } else if cfg!(unix) { + Compiler::Clang // Default to Clang for Unix-like systems + } else { + Compiler::Unknown + } } - let target = if cfg!(feature = "check") { - "snmallocshim-rust" - } else { - "snmallocshim-checks-rust" - }; - if cfg!(feature = "native-cpu") { - build.define("SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE", "ON"); - build.flag_if_supported("-march=native"); + fn embed_build_info(&self) { + let build_info = [ + ("BUILD_TARGET_OS", &self.target_os), + ("BUILD_TARGET_ENV", &self.target_env), + ("BUILD_TARGET_FAMILY", &self.target_family), + ("BUILD_TARGET", &self.target), + ("BUILD_CC", &format!("{:#?}", self.compiler)), + ("BUILD_TYPE", &self.build_type), + ("BUILD_DEBUG", &self.debug.to_string()), + ("BUILD_OPTIM_LEVEL", &self.optim_level), + ("BUILD_CXX_STANDARD", &self.cmake_cxx_standard), + ]; + + for (key, value) in build_info { + println!("cargo:rustc-env={}={}", key, value); + } + + if let Some(ms) = &self.msystem { + println!("cargo:rustc-env=BUILD_MSYSTEM={}", ms); + } } - if cfg!(feature = "qemu") { - build.define("SNMALLOC_QEMU_WORKAROUND", "ON"); + fn get_cpp_flags(&self) -> [&'static str; 2] { + if cfg!(feature = "usecxx17") { + ["-std=c++17", "/std:c++17"] + } else { + ["-std=c++20", "/std:c++20"] + } } - if cfg!(feature = "cache-friendly") { - eprintln!( - "cache-friendly feature flag is deprecated and no longer has any effect. \ - it may be removed in a future release" - ); - // The following code no longer works - // build.define("CACHE_FRIENDLY_OFFSET", "64"); + fn is_msvc(&self) -> bool { + self.target_env == "msvc" } - if cfg!(feature = "lto") { - build.define("SNMALLOC_IPO", "ON"); + fn is_gnu(&self) -> bool { + self.target_env == "gnu" } - if cfg!(feature = "notls") { - build.define("SNMALLOC_ENABLE_DYNAMIC_LOADING", "ON"); + fn is_windows(&self) -> bool { + self.target_os == "windows" } - if cfg!(feature = "usewait-on-address") { - build.define("SNMALLOC_USE_WAIT_ON_ADDRESS", "1"); - } else { - build.define("SNMALLOC_USE_WAIT_ON_ADDRESS", "0"); + fn is_linux(&self) -> bool { + self.target_os == "linux" } - build.compile(target); - - if target_env == "msvc" { - if cfg!(not(feature = "win8compat")) { - println!("cargo:rustc-link-lib=dylib=mincore"); - } + fn is_unix(&self) -> bool { + self.target_family == "unix" } - if target_os == "windows" && target_env == "gnu" { - println!("cargo:rustc-link-lib=dylib=atomic"); + fn is_clang_msys(&self) -> bool { + self.msystem.as_deref().map_or(false, |s| s.contains("CLANG")) } - if target_os == "linux" { - println!("cargo:rustc-link-lib=dylib=atomic"); - }; - - if cfg!(target_os = "freebsd") { - // using THREAD_DESTRUCTOR - } else if cfg!(all(unix, not(target_os = "macos"))) { - if cfg!(target_env = "gnu") { - println!("cargo:rustc-link-lib=c_nonshared"); - } - } else if cfg!(windows) { - // no need - } else { - // link c++ runtime - println!( - "cargo:rustc-link-lib={}", - std::env::var("CXXSTDLIB").unwrap_or_else(|_| { - if cfg!(target_os = "macos") || cfg!(target_os = "openbsd") { - "c++".to_string() - } else { - "stdc++".to_string() - } - }) - ) + fn is_ucrt64(&self) -> bool { + self.msystem.as_deref() == Some("UCRT64") } } -#[cfg(not(feature = "build_cc"))] -fn main() { - let mut cfg = &mut cmake::Config::new("snmalloc"); - - let build_type = if cfg!(feature = "debug") { - "Debug" - } else { - "Release" - }; - - cfg = cfg - .define("SNMALLOC_RUST_SUPPORT", "ON") - .profile(build_type) - .very_verbose(true); - - let triple = std::env::var("TARGET").unwrap(); - if triple.contains("android") { - if let Ok(ndk) = std::env::var("ANDROID_NDK") { - cfg = cfg.define( - "CMAKE_TOOLCHAIN_FILE", - format!("{}/build/cmake/android.toolchain.cmake", ndk), - ); - } else { - eprintln!("please set ANDROID_NDK environment variable"); - std::process::abort(); - } - - if let Ok(platform) = std::env::var("ANDROID_PLATFORM") { - cfg = cfg.define("ANDROID_PLATFORM", platform); - } +trait BuilderDefine { + fn define(&mut self, key: &str, value: &str) -> &mut Self; + fn flag_if_supported(&mut self, flag: &str) -> &mut Self; + fn build_lib(&mut self, target_lib: &str) -> std::path::PathBuf; + fn configure_output_dir(&mut self, out_dir: &str) -> &mut Self; + fn configure_cpp(&mut self, debug: bool) -> &mut Self; +} - if cfg!(feature = "android-lld") { - cfg = cfg.define("ANDROID_LD", "lld"); - } +#[cfg(feature = "build_cc")] +impl BuilderDefine for cc::Build { + fn define(&mut self, key: &str, value: &str) -> &mut Self { + self.define(key, Some(value)) + } + + fn flag_if_supported(&mut self, flag: &str) -> &mut Self { + self.flag_if_supported(flag) + } + + fn build_lib(&mut self, target_lib: &str) -> std::path::PathBuf { + self.compile(target_lib); + std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()) + } - if triple.contains("aarch64") { - cfg = cfg.define("ANDROID_ABI", "arm64-v8a"); - } else if triple.contains("armv7") { - cfg = cfg - .define("ANDROID_ABI", "armeabi-v7a") - .define("ANDROID_ARM_MODE", "arm"); - } else if triple.contains("x86_64") { - cfg = cfg.define("ANDROID_ABI", "x86_64"); - } else if triple.contains("i686") { - cfg = cfg.define("ANDROID_ABI", "x86"); - } else if triple.contains("neon") { - cfg = cfg.define("ANDROID_ABI", "armeabi-v7a with NEON") - } else if triple.contains("arm") { - cfg = cfg.define("ANDROID_ABI", "armeabi-v7a"); - } + fn configure_output_dir(&mut self, out_dir: &str) -> &mut Self { + self.out_dir(out_dir) } - if cfg!(all(windows, target_env = "msvc")) { - cfg = cfg.define("CMAKE_CXX_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc"); - cfg = cfg.define("CMAKE_C_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc"); - if cfg!(feature = "win8compat") { - cfg = cfg.define("WIN8COMPAT", "ON") - } + fn configure_cpp(&mut self, debug: bool) -> &mut Self { + self.include("snmalloc/src") + .file("snmalloc/src/snmalloc/override/rust.cc") + .cpp(true) + .debug(debug) + .static_crt(true) } +} - if cfg!(all(windows, target_env = "gnu")) { - cfg = cfg.define("CMAKE_SH", "CMAKE_SH-NOTFOUND"); +#[cfg(not(feature = "build_cc"))] +impl BuilderDefine for cmake::Config { + fn define(&mut self, key: &str, value: &str) -> &mut Self { + self.define(key, value) + } + + fn flag_if_supported(&mut self, _flag: &str) -> &mut Self { + self + } + + fn build_lib(&mut self, target_lib: &str) -> std::path::PathBuf { + self.build_target(target_lib).build() } - let target = if cfg!(feature = "check") { - "snmallocshim-checks-rust" - } else { - "snmallocshim-rust" - }; + fn configure_output_dir(&mut self, out_dir: &str) -> &mut Self { + self.out_dir(out_dir) + } - if cfg!(feature = "native-cpu") { - cfg = cfg.define("SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE", "ON") + fn configure_cpp(&mut self, _debug: bool) -> &mut Self { + self.define("SNMALLOC_RUST_SUPPORT", "ON") + .very_verbose(true) + .define("CMAKE_SH", "CMAKE_SH-NOTFOUND") + .always_configure(true) + .static_crt(true) } +} - if cfg!(feature = "usecxx17") { - cfg = cfg.define("SNMALLOC_USE_CXX17", "ON") +fn apply_defines(builder: &mut T, defines: &[(&str, &str)]) { + for (key, value) in defines { + builder.define(key, value); } +} +impl BuildFeatures { + fn new() -> Self { + Self { + native_cpu: cfg!(feature = "native-cpu"), + qemu: cfg!(feature = "qemu"), + wait_on_address: cfg!(feature = "usewait-on-address"), + lto: cfg!(feature = "lto"), + notls: cfg!(feature = "notls"), + win8compat: cfg!(feature = "win8compat"), + stats: cfg!(feature = "stats"), + android_lld: cfg!(feature = "android-lld"), + local_dynamic_tls: cfg!(feature = "local_dynamic_tls"), + } + } +} - if cfg!(feature = "stats") { - cfg = cfg.define("USE_SNMALLOC_STATS", "ON") +fn configure_platform(config: &mut BuildConfig) { + // Basic optimization and compiler flags + config.builder + .flag_if_supported(&config.optim_level) + .flag_if_supported("-fomit-frame-pointer"); + + // C++ standard flags + for std in config.get_cpp_flags() { + config.builder.flag_if_supported(std); } - if cfg!(feature = "qemu") { - cfg = cfg.define("SNMALLOC_QEMU_WORKAROUND", "ON") + // Common feature configurations + if config.features.native_cpu { + config.builder.define("SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE", "ON"); + #[cfg(feature = "build_cc")] + config.builder.flag_if_supported("-march=native"); } - if cfg!(feature = "usewait-on-address") { - cfg = cfg.define("SNMALLOC_USE_WAIT_ON_ADDRESS", "1") - } else { - cfg = cfg.define("SNMALLOC_USE_WAIT_ON_ADDRESS", "0") + // Platform-specific configurations + match () { + _ if config.is_windows() => { + let common_flags = vec!["-mcx16", "-fno-exceptions", "-fno-rtti", "-pthread"]; + for flag in common_flags { + config.builder.flag_if_supported(flag); + } + + if let Some(msystem) = &config.msystem { + match msystem.as_str() { + "CLANG64" | "CLANGARM64" => { + let defines = vec![ + ("CMAKE_CXX_COMPILER", "clang++"), + ("CMAKE_C_COMPILER", "clang"), + ("CMAKE_CXX_FLAGS", "-fuse-ld=lld -stdlib=libc++ -mcx16 -Wno-error=unknown-pragmas -Qunused-arguments"), + ("CMAKE_C_FLAGS", "-fuse-ld=lld -Wno-error=unknown-pragmas -Qunused-arguments"), + ("CMAKE_EXE_LINKER_FLAGS", "-fuse-ld=lld -stdlib=libc++"), + ("CMAKE_SHARED_LINKER_FLAGS", "-fuse-ld=lld -stdlib=libc++") + ]; + apply_defines(&mut config.builder, &defines); + if config.features.lto { + config.builder.flag_if_supported("-flto=thin"); + } + } + "UCRT64" | "MINGW64" => { + let defines = vec![ + ("CMAKE_CXX_FLAGS", "-fuse-ld=lld -Wno-error=unknown-pragmas"), + ("CMAKE_SYSTEM_NAME", "Windows"), + ("CMAKE_C_FLAGS", "-fuse-ld=lld -Wno-error=unknown-pragmas"), + ("CMAKE_EXE_LINKER_FLAGS", "-fuse-ld=lld"), + ("CMAKE_SHARED_LINKER_FLAGS", "-fuse-ld=lld") + ]; + apply_defines(&mut config.builder, &defines); + } + _ => {} + } + } + } + _ if config.is_msvc() => { + let msvc_flags = vec![ + "/nologo", "/W4", "/WX", "/wd4127", "/wd4324", "/wd4201", + "/Ob2", "/DNDEBUG", "/EHsc", "/Gd", "/TP", "/Gm-", "/GS", + "/fp:precise", "/Zc:wchar_t", "/Zc:forScope", "/Zc:inline" + ]; + for flag in msvc_flags { + config.builder.flag_if_supported(flag); + } + + if config.features.lto { + config.builder + .flag_if_supported("/GL") + .define("CMAKE_INTERPROCEDURAL_OPTIMIZATION", "TRUE") + .define("SNMALLOC_IPO", "ON"); + println!("cargo:rustc-link-arg=/LTCG"); + } + + config.builder + .define("CMAKE_CXX_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc") + .define("CMAKE_C_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc"); + } + _ if config.is_unix() => { + let unix_flags = vec!["-fPIC", "-pthread", "-fno-exceptions", "-fno-rtti", "-mcx16", "-Wno-unused-parameter"]; + for flag in unix_flags { + config.builder.flag_if_supported(flag); + } + + if config.target_os != "haiku" { + let tls_model = if config.features.local_dynamic_tls { "-ftls-model=local-dynamic" } else { "-ftls-model=initial-exec" }; + config.builder.flag_if_supported(tls_model); + } + } + _ => {} } - let mut dst = cfg.build_target(target).build(); + // Feature configurations + config.builder + .define("SNMALLOC_QEMU_WORKAROUND", if config.features.qemu { "ON" } else { "OFF" }) + .define("SNMALLOC_ENABLE_DYNAMIC_LOADING", if config.features.notls { "ON" } else { "OFF" }) + .define("SNMALLOC_USE_WAIT_ON_ADDRESS", if config.features.wait_on_address { "1" } else { "0" }) + .define("USE_SNMALLOC_STATS", if config.features.stats { "ON" } else { "OFF" }); - dst.push("./build"); - // we need to specify static modifier, otherwise the linker may not be smart enough to resolve - // dependency from snmalloc to libc/libgcc_s - println!("cargo:rustc-link-lib=static={}", target); + // Android configuration + if config.target.contains("android") { + let ndk = env::var("ANDROID_NDK").expect("ANDROID_NDK environment variable not set"); + config.builder + .define("CMAKE_TOOLCHAIN_FILE", &*format!("{}/build/cmake/android.toolchain.cmake", ndk)) + .define("ANDROID_PLATFORM", &*env::var("ANDROID_PLATFORM").unwrap_or_default()); - if cfg!(all(windows, target_env = "msvc")) { - if cfg!(not(feature = "win8compat")) { - println!("cargo:rustc-link-lib=dylib=mincore"); + if cfg!(feature = "android-lld") { + config.builder.define("ANDROID_LD", "lld"); } - println!( - "cargo:rustc-link-search=native={}/{}", - dst.display(), - build_type - ); - } else { - println!("cargo:rustc-link-search=native={}", dst.display()); - } - if cfg!(all(windows, target_env = "gnu")) { - let stdout = std::process::Command::new("gcc") - .args(["-print-search-dirs"]) - .output() - .unwrap_or_else(|_| { - eprintln!("Cannot run gcc.exe"); - std::process::abort(); - }) - .stdout; - - let outputs = String::from_utf8(stdout).unwrap_or_else(|_| { - eprintln!("gcc output contains non-utf8 characters"); - std::process::abort(); - }); - - outputs - .lines() - .filter(|line| line.starts_with("libraries: =")) - .map(|line| line.split_at("libraries: =".len()).1) - .flat_map(|line| line.split(';')) - .for_each(|path| { - println!("cargo:rustc-link-search=native={}", path); - }); - println!("cargo:rustc-link-lib=dylib=atomic"); - println!("cargo:rustc-link-lib=dylib=winpthread"); - println!("cargo:rustc-link-lib=dylib=gcc_s"); + let (abi, arm_mode) = match config.target.as_str() { + t if t.contains("aarch64") => ("arm64-v8a", None), + t if t.contains("armv7") => ("armeabi-v7a", Some("arm")), + t if t.contains("x86_64") => ("x86_64", None), + t if t.contains("i686") => ("x86", None), + t if t.contains("neon") => ("armeabi-v7a with NEON", None), + t if t.contains("arm") => ("armeabi-v7a", None), + _ => panic!("Unsupported Android architecture: {}", config.target), + }; + config.builder.define("ANDROID_ABI", abi); + if let Some(mode) = arm_mode { + config.builder.define("ANDROID_ARM_MODE", mode); + } } +} - // linux: using PTHREAD_DESTRUCTORS - if cfg!(target_os = "linux") { - println!("cargo:rustc-link-lib=dylib=atomic"); - } - if cfg!(target_os = "freebsd") { - // using THREAD_DESTRUCTOR - } else if cfg!(all(unix, not(target_os = "macos"))) { - // using PTHREAD_DESTRUCTOR - if cfg!(target_env = "gnu") { - println!("cargo:rustc-link-lib=c_nonshared"); +fn configure_linking(config: &BuildConfig) { + + match () { + _ if config.is_msvc() => { + // Windows MSVC specific libraries + if !config.features.win8compat { + println!("cargo:rustc-link-lib=mincore"); + } + // Essential Windows libraries + println!("cargo:rustc-link-lib=kernel32"); + println!("cargo:rustc-link-lib=user32"); + println!("cargo:rustc-link-lib=advapi32"); + println!("cargo:rustc-link-lib=ws2_32"); + println!("cargo:rustc-link-lib=userenv"); + println!("cargo:rustc-link-lib=bcrypt"); + println!("cargo:rustc-link-lib=msvcrt"); } - } else if cfg!(windows) { - // not need for explicit c++ runtime - } else { - // link c++ runtime - println!( - "cargo:rustc-link-lib={}", - std::env::var("CXXSTDLIB").unwrap_or_else(|_| { - if cfg!(target_os = "macos") || cfg!(target_os = "openbsd") { - "c++".to_string() - } else { - "stdc++".to_string() - } - }) - ) + _ if config.is_windows() && config.is_gnu() => { + println!("cargo:rustc-link-lib=kernel32"); + println!("cargo:rustc-link-lib=bcrypt"); + println!("cargo:rustc-link-lib=winpthread"); + + if config.is_clang_msys() { + println!("cargo:rustc-link-lib=c++"); + } else if config.is_ucrt64() { + println!("cargo:rustc-link-lib=stdc++"); + } else { + println!("cargo:rustc-link-lib=stdc++"); + println!("cargo:rustc-link-lib=atomic"); + } + } + _ if cfg!(target_os = "freebsd") => { + println!("cargo:rustc-link-lib=c++"); + } + _ if config.is_linux() => { + println!("cargo:rustc-link-lib=atomic"); + println!("cargo:rustc-link-lib=stdc++"); + println!("cargo:rustc-link-lib=pthread"); + println!("cargo:rustc-link-lib=c"); + println!("cargo:rustc-link-lib=gcc_s"); + println!("cargo:rustc-link-lib=util"); + println!("cargo:rustc-link-lib=rt"); + println!("cargo:rustc-link-lib=dl"); + println!("cargo:rustc-link-lib=m"); + + if cfg!(feature = "usecxx17") && !config.is_clang_msys() { + println!("cargo:rustc-link-lib=gcc"); + } + } + _ if config.is_unix() && !cfg!(any(target_os = "macos", target_os = "freebsd")) => { + if config.is_gnu() { + println!("cargo:rustc-link-lib=c_nonshared"); + } + } + _ if !config.is_windows() => { + let cxxlib = if cfg!(any(target_os = "macos", target_os = "openbsd")) { + "c++" + } else { + "stdc++" + }; + println!("cargo:rustc-link-lib={}", cxxlib); + } + _ => {} } } + +#[cfg(feature = "build_cc")] +use cc; +#[cfg(not(feature = "build_cc"))] +use cmake::Config; + +fn main() { + let mut config = BuildConfig::new(); + + config.builder + .configure_cpp(config.debug) + .configure_output_dir(&config.out_dir); + + // Apply all configurations + configure_platform(&mut config); + + // Build and configure output + println!("cargo:rustc-link-search=/usr/local/lib"); + println!("cargo:rustc-link-search={}", config.out_dir); + println!("cargo:rustc-link-search={}/build", config.out_dir); + println!("cargo:rustc-link-search={}/build/Debug", config.out_dir); + println!("cargo:rustc-link-search={}/build/Release", config.out_dir); + let mut dst = config.builder.build_lib(&config.target_lib); + println!("cargo:rustc-link-lib={}", config.target_lib); + configure_linking(&config); +} diff --git a/src/lib.rs b/src/lib.rs index b4e8158c2..c4ab77411 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,10 +27,43 @@ //! ``` extern crate snmalloc_sys as ffi; -use core::alloc::{GlobalAlloc, Layout}; +use core::{ + alloc::{GlobalAlloc, Layout}, + ptr::NonNull, +}; +#[derive(Debug, Copy, Clone)] +#[repr(C)] pub struct SnMalloc; +unsafe impl Send for SnMalloc {} +unsafe impl Sync for SnMalloc {} + +impl SnMalloc { + #[inline(always)] + pub const fn new() -> Self { + Self + } + + /// Returns the available bytes in a memory block. + #[inline(always)] + pub fn usable_size(&self, ptr: *const u8) -> Option { + match ptr.is_null() { + true => None, + false => Some(unsafe { ffi::sn_rust_usable_size(ptr.cast()) }) + } + } + + /// Allocates memory with the given layout, returning a non-null pointer on success + #[inline(always)] + pub fn alloc_aligned(&self, layout: Layout) -> Option> { + match layout.size() { + 0 => NonNull::new(layout.align() as *mut u8), + size => NonNull::new(unsafe { ffi::sn_rust_alloc(layout.align(), size) }.cast()) + } + } +} + unsafe impl GlobalAlloc for SnMalloc { /// Allocate the memory with the given alignment and size. /// On success, it returns a pointer pointing to the required memory address. @@ -42,7 +75,10 @@ unsafe impl GlobalAlloc for SnMalloc { /// The program may be forced to abort if the constrains are not full-filled. #[inline(always)] unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - ffi::sn_rust_alloc(layout.align(), layout.size()) as _ + match layout.size() { + 0 => layout.align() as *mut u8, + size => ffi::sn_rust_alloc(layout.align(), size).cast() + } } /// De-allocate the memory at the given address with the given alignment and size. @@ -53,13 +89,18 @@ unsafe impl GlobalAlloc for SnMalloc { /// The program may be forced to abort if the constrains are not full-filled. #[inline(always)] unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { - ffi::sn_rust_dealloc(ptr as _, layout.align(), layout.size()); + if layout.size() != 0 { + ffi::sn_rust_dealloc(ptr as _, layout.align(), layout.size()); + } } /// Behaves like alloc, but also ensures that the contents are set to zero before being returned. #[inline(always)] unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { - ffi::sn_rust_alloc_zeroed(layout.align(), layout.size()) as _ + match layout.size() { + 0 => layout.align() as *mut u8, + size => ffi::sn_rust_alloc_zeroed(layout.align(), size).cast() + } } /// Re-allocate the memory at the given address with the given alignment and size. @@ -74,25 +115,47 @@ unsafe impl GlobalAlloc for SnMalloc { /// The program may be forced to abort if the constrains are not full-filled. #[inline(always)] unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { - ffi::sn_rust_realloc(ptr as _, layout.align(), layout.size(), new_size) as _ - } -} - -impl SnMalloc { - /// Returns the available bytes in a memory block. - /// - /// Note that the value could be higher than the allocation size and - /// depends very much on the underlying operating system. - #[inline(always)] - pub fn usable_size(&self, ptr: *const u8) -> usize { - unsafe { ffi::sn_rust_usable_size(ptr as *const _) } + match new_size { + 0 => { + self.dealloc(ptr, layout); + layout.align() as *mut u8 + } + new_size if layout.size() == 0 => { + self.alloc(Layout::from_size_align_unchecked(new_size, layout.align())) + } + _ => ffi::sn_rust_realloc(ptr.cast(), layout.align(), layout.size(), new_size).cast() + } } } #[cfg(test)] mod tests { use super::*; + #[test] + fn allocation_lifecycle() { + let alloc = SnMalloc::new(); + unsafe { + let layout = Layout::from_size_align(8, 8).unwrap(); + + // Test regular allocation + let ptr = alloc.alloc(layout); + alloc.dealloc(ptr, layout); + // Test zeroed allocation + let ptr = alloc.alloc_zeroed(layout); + alloc.dealloc(ptr, layout); + + // Test reallocation + let ptr = alloc.alloc(layout); + let ptr = alloc.realloc(ptr, layout, 16); + alloc.dealloc(ptr, layout); + + // Test large allocation + let large_layout = Layout::from_size_align(1 << 20, 32).unwrap(); + let ptr = alloc.alloc(large_layout); + alloc.dealloc(ptr, large_layout); + } + } #[test] fn it_frees_allocated_memory() { unsafe { @@ -139,13 +202,12 @@ mod tests { } #[test] - fn it_usable_size() { + fn test_usable_size() { + let alloc = SnMalloc::new(); unsafe { let layout = Layout::from_size_align(8, 8).unwrap(); - let alloc = SnMalloc; - let ptr = alloc.alloc(layout); - let usz = alloc.usable_size(ptr); + let usz = alloc.usable_size(ptr).expect("usable_size returned None"); alloc.dealloc(ptr, layout); assert!(usz >= 8); } From ed3a6c9c19f3819e4810df1f010073c10c699894 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Thu, 6 Feb 2025 03:19:43 +0000 Subject: [PATCH 141/145] Update snmalloc to 0.7.1 (#195) * Update snmalloc to 0.7.1 This tracks the upstream changes in snmalloc 0.7.1. * Address warning from CI. --- CHANGELOG.md | 5 +++++ Cargo.toml | 4 ++-- README.md | 11 ++++++++++- snmalloc-sys/Cargo.toml | 2 +- snmalloc-sys/build.rs | 3 +-- snmalloc-sys/snmalloc | 2 +- 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dd514f1e..f843daf6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Changelog +### 0.3.8 + +- Tracking upstream to match version 0.7.1 +- Recommended to upgrade from 0.3.7 to get an important bug fix. + ### 0.3.7 - Tracking upstream to match version 0.7 diff --git a/Cargo.toml b/Cargo.toml index bb47f9e05..421544701 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-rs" -version = "0.3.7" +version = "0.3.8" authors = ["schrodingerzhu "] edition = "2021" license = "MIT" @@ -16,7 +16,7 @@ readme = "README.md" members = ["snmalloc-sys"] [dependencies] -snmalloc-sys = { version = "0.3.7", path = "snmalloc-sys", default-features = false } +snmalloc-sys = { version = "0.3.8", path = "snmalloc-sys", default-features = false } [features] default = ["snmalloc-sys/build_cmake", "snmalloc-sys/usewait-on-address"] diff --git a/README.md b/README.md index 2c2c6f801..869da4bc0 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ To use `snmalloc-rs` add it as a dependency: ```toml # Cargo.toml [dependencies] -snmalloc-rs = "0.3.4" +snmalloc-rs = "0.3.8" ``` To set `SnMalloc` as the global allocator add this to your project: @@ -81,6 +81,15 @@ target. ## Changelog +### 0.3.8 + +- Tracking upstream to match version 0.7.1 +- Recommended to upgrade from 0.3.7 to get an important bug fix. + +### 0.3.7 + +- Tracking upstream to match version 0.7 + ### 0.3.4 - Tracking upstream to version 0.6.2. diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 8739bf533..56f612e06 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snmalloc-sys" -version = "0.3.7" +version = "0.3.8" authors = ["schrodingerzhu "] edition = "2021" license = "MIT" diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index 263898846..b7612a326 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -1,7 +1,6 @@ #![allow(dead_code)] use std::env; -use std::fs; #[derive(Debug, PartialEq)] enum Compiler { @@ -496,7 +495,7 @@ fn main() { println!("cargo:rustc-link-search={}/build", config.out_dir); println!("cargo:rustc-link-search={}/build/Debug", config.out_dir); println!("cargo:rustc-link-search={}/build/Release", config.out_dir); - let mut dst = config.builder.build_lib(&config.target_lib); + let mut _dst = config.builder.build_lib(&config.target_lib); println!("cargo:rustc-link-lib={}", config.target_lib); configure_linking(&config); } diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index 564c88b07..cdb04ec8d 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit 564c88b07c53728ec90a88d7d34d0f74d3b0bfff +Subproject commit cdb04ec8d93a59cf69369ad3b2d8b165f29ebfb7 From 9ccb725c52a750998ce067147a24e9fa3a1eabb4 Mon Sep 17 00:00:00 2001 From: Will Brown Date: Sat, 5 Apr 2025 19:07:02 -0400 Subject: [PATCH 142/145] add libc api feature (#198) --- .gitignore | 4 +++ Cargo.toml | 1 + README.md | 1 + snmalloc-sys/Cargo.toml | 1 + snmalloc-sys/build.rs | 5 +++- snmalloc-sys/snmalloc | 2 +- snmalloc-sys/src/lib.rs | 61 ++++++++++++++++++++++++++++------------- 7 files changed, 54 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 64f40ab29..67613f769 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ target Cargo.lock .idea + +# vscode dirs +.vscode/ +.vs/ \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 421544701..3c45fc7b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,3 +33,4 @@ lto = ["snmalloc-sys/lto"] notls = ["snmalloc-sys/notls"] stats = ["snmalloc-sys/stats"] usewait-on-address = ["snmalloc-sys/usewait-on-address"] +libc-api = ["snmalloc-sys/libc-api"] diff --git a/README.md b/README.md index 869da4bc0..8f06ce5d0 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ are listed at - `lto`: Links with InterProceduralOptimization/LinkTimeOptimization - `notls`: Enables to be loaded dynamically, thus disable tls. - `stats`: Enables allocation statistics. +- `libc-api`: Enables libc API backed by snmalloc. **To get the crates compiled, you need to choose either `1mib` or `16mib` to determine the chunk configuration** diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-sys/Cargo.toml index 56f612e06..b0b3f20c2 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-sys/Cargo.toml @@ -32,3 +32,4 @@ lto = [] notls = [] stats = [] usewait-on-address = [] +libc-api = [] diff --git a/snmalloc-sys/build.rs b/snmalloc-sys/build.rs index b7612a326..2a9440a29 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-sys/build.rs @@ -60,6 +60,7 @@ struct BuildFeatures { stats: bool, android_lld: bool, local_dynamic_tls: bool, + libc_api: bool, } impl BuildConfig { @@ -277,6 +278,7 @@ impl BuildFeatures { stats: cfg!(feature = "stats"), android_lld: cfg!(feature = "android-lld"), local_dynamic_tls: cfg!(feature = "local_dynamic_tls"), + libc_api: cfg!(feature = "libc-api"), } } } @@ -378,7 +380,8 @@ fn configure_platform(config: &mut BuildConfig) { .define("SNMALLOC_QEMU_WORKAROUND", if config.features.qemu { "ON" } else { "OFF" }) .define("SNMALLOC_ENABLE_DYNAMIC_LOADING", if config.features.notls { "ON" } else { "OFF" }) .define("SNMALLOC_USE_WAIT_ON_ADDRESS", if config.features.wait_on_address { "1" } else { "0" }) - .define("USE_SNMALLOC_STATS", if config.features.stats { "ON" } else { "OFF" }); + .define("USE_SNMALLOC_STATS", if config.features.stats { "ON" } else { "OFF" }) + .define("SNMALLOC_RUST_LIBC_API", if config.features.libc_api { "ON" } else { "OFF" }); // Android configuration if config.target.contains("android") { diff --git a/snmalloc-sys/snmalloc b/snmalloc-sys/snmalloc index cdb04ec8d..e6bf8570d 160000 --- a/snmalloc-sys/snmalloc +++ b/snmalloc-sys/snmalloc @@ -1 +1 @@ -Subproject commit cdb04ec8d93a59cf69369ad3b2d8b165f29ebfb7 +Subproject commit e6bf8570d003c7f219f0a24704ad263b5a321c1a diff --git a/snmalloc-sys/src/lib.rs b/snmalloc-sys/src/lib.rs index 499dc410b..394a61fa0 100644 --- a/snmalloc-sys/src/lib.rs +++ b/snmalloc-sys/src/lib.rs @@ -39,15 +39,21 @@ extern "C" { new_size: usize, ) -> *mut c_void; + /// Return the available bytes in a memory block. + pub fn sn_rust_usable_size(p: *const c_void) -> usize; +} + +#[cfg(feature = "libc-api")] +extern "C" { /// Allocate `count` items of `size` length each. /// Returns `null` if `count * size` overflows or on out-of-memory. /// All items are initialized to zero. - pub fn calloc(count: usize, size: usize) -> *mut c_void; + pub fn sn_calloc(count: usize, size: usize) -> *mut c_void; /// Allocate `size` bytes. /// Returns pointer to the allocated memory or null if out of memory. /// Returns a unique pointer if called with `size` 0. - pub fn malloc(size: usize) -> *mut c_void; + pub fn sn_malloc(size: usize) -> *mut c_void; /// Re-allocate memory to `newsize` bytes. /// Return pointer to the allocated memory or null if out of memory. If null @@ -57,18 +63,19 @@ extern "C" { /// If `p` is null, it behaves as [`sn_malloc`]. If `newsize` is larger than /// the original `size` allocated for `p`, the bytes after `size` are /// uninitialized. - pub fn realloc(p: *mut c_void, newsize: usize) -> *mut c_void; + pub fn sn_realloc(p: *mut c_void, newsize: usize) -> *mut c_void; /// Free previously allocated memory. /// The pointer `p` must have been allocated before (or be null). - pub fn free(p: *mut c_void); + pub fn sn_free(p: *mut c_void); /// Return the available bytes in a memory block. - pub fn sn_rust_usable_size(p: *const c_void) -> usize; + pub fn sn_malloc_usable_size(p: *const c_void) -> usize; + } #[cfg(test)] -mod tests { +mod rust_tests { use super::*; #[test] @@ -90,19 +97,6 @@ mod tests { unsafe { sn_rust_dealloc(ptr as *mut c_void, 8, 8) }; } - #[test] - fn it_frees_memory_sn_malloc() { - let ptr = unsafe { malloc(8) } as *mut u8; - unsafe { free(ptr as *mut c_void) }; - } - - #[test] - fn it_frees_memory_sn_realloc() { - let ptr = unsafe { malloc(8) } as *mut u8; - let ptr = unsafe { realloc(ptr as *mut c_void, 8) } as *mut u8; - unsafe { free(ptr as *mut c_void) }; - } - #[test] fn it_reallocs_correctly() { let mut ptr = unsafe { sn_rust_alloc(8, 8) } as *mut u8; @@ -126,3 +120,32 @@ mod tests { unsafe { sn_rust_dealloc(ptr as *mut c_void, 32, 8) }; } } + +#[cfg(all(test, feature = "libc-api"))] +mod libc_tests { + use super::*; + + #[test] + fn it_frees_memory_sn_malloc() { + let ptr = unsafe { sn_malloc(8) } as *mut u8; + unsafe { sn_free(ptr as *mut c_void) }; + } + + #[test] + fn it_frees_memory_sn_realloc() { + let ptr = unsafe { sn_malloc(8) } as *mut u8; + let ptr = unsafe { sn_realloc(ptr as *mut c_void, 8) } as *mut u8; + unsafe { sn_free(ptr as *mut c_void) }; + } + + #[test] + fn it_calculates_malloc_usable_size() { + let ptr = unsafe { sn_malloc(32) } as *mut u8; + let usable_size = unsafe { sn_malloc_usable_size(ptr as *mut c_void) }; + assert!( + usable_size >= 32, + "usable_size should at least equal to the allocated size" + ); + unsafe { sn_free(ptr as *mut c_void) }; + } +} \ No newline at end of file From ec0b1e93164c9e52904361999e6186e178e07790 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Tue, 27 Jan 2026 11:12:14 +0000 Subject: [PATCH 143/145] Relocated for merge. --- .cirrus.yml | 15 --- .gitmodules | 4 - .travis.yml | 103 ------------------ .gitignore => snmalloc-rs/.gitignore | 0 CHANGELOG.md => snmalloc-rs/CHANGELOG.md | 0 Cargo.toml => snmalloc-rs/Cargo.toml | 2 +- LICENSE => snmalloc-rs/LICENSE | 0 README.md => snmalloc-rs/README.md | 0 .../snmalloc-sys}/Cargo.toml | 2 +- .../snmalloc-sys}/build.rs | 6 +- .../snmalloc-sys}/snmalloc | 0 .../snmalloc-sys}/src/lib.rs | 0 {src => snmalloc-rs/src}/lib.rs | 0 13 files changed, 5 insertions(+), 127 deletions(-) delete mode 100644 .cirrus.yml delete mode 100644 .gitmodules delete mode 100644 .travis.yml rename .gitignore => snmalloc-rs/.gitignore (100%) rename CHANGELOG.md => snmalloc-rs/CHANGELOG.md (100%) rename Cargo.toml => snmalloc-rs/Cargo.toml (95%) rename LICENSE => snmalloc-rs/LICENSE (100%) rename README.md => snmalloc-rs/README.md (100%) rename {snmalloc-sys => snmalloc-rs/snmalloc-sys}/Cargo.toml (92%) rename {snmalloc-sys => snmalloc-rs/snmalloc-sys}/build.rs (99%) rename {snmalloc-sys => snmalloc-rs/snmalloc-sys}/snmalloc (100%) rename {snmalloc-sys => snmalloc-rs/snmalloc-sys}/src/lib.rs (100%) rename {src => snmalloc-rs/src}/lib.rs (100%) diff --git a/.cirrus.yml b/.cirrus.yml deleted file mode 100644 index e1130e82e..000000000 --- a/.cirrus.yml +++ /dev/null @@ -1,15 +0,0 @@ -freebsd_instance: - image_family: freebsd-15-0-snap -task: - name: cargo test (stable) - env: - HOME: /tmp # cargo needs it - install_script: | - pkg install -y rust - pkg install -y cmake - pkg install -y git - build_script: | - git submodule update --init - cargo build --all - test_script: cargo test --all --all-targets - diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index c5e2acf02..000000000 --- a/.gitmodules +++ /dev/null @@ -1,4 +0,0 @@ -[submodule "new"] - path = snmalloc-sys/snmalloc - url = https://github.com/microsoft/snmalloc - branch = main diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3cde1c9c0..000000000 --- a/.travis.yml +++ /dev/null @@ -1,103 +0,0 @@ -matrix: - include: - - os: windows - language: rust - env: - - TOOLCHAIN=MinGW - rust: - - nightly - - - os: windows - language: rust - rust: - - stable - before_script: - - choco install visualstudio2019community - - choco install visualstudio2019-workload-nativedesktop - - export VS160COMNTOOLS="/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools" - - rustup toolchain install stable-x86_64-pc-windows-msvc - - rustup default stable-msvc - - - os: windows - language: rust - rust: - - nightly - before_script: - - choco install visualstudio2019community - - choco install visualstudio2019-workload-nativedesktop - - export VS160COMNTOOLS="/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools" - - rustup toolchain install nightly-x86_64-pc-windows-msvc - - rustup default nightly-msvc - - - os: linux - dist: bionic - language: rust - rust: - - stable - addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-9 - env: - - CC=gcc-9 - - CXX=g++-9 - - - os: linux - dist: bionic - language: rust - rust: - - nightly - addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - gcc-10 - - g++-10 - env: - - CC=gcc-10 - - CXX=g++-10 - - - os: linux - dist: bionic - arch: arm64 - language: rust - rust: - - stable - - - os: linux - dist: bionic - arch: arm64 - language: rust - rust: - - nightly - - - os: osx - osx_image: xcode12 - language: rust - rust: - - stable - - - os: osx - osx_image: xcode12 - language: rust - rust: - - nightly - allow_failures: - env: TOOLCHAIN=MinGW - -cache: - directories: - - $HOME/AppData/Local/Temp/chocolatey - -script: - - cargo test --all - - cargo test --all --features 1mib - - cargo test --all --features build_cc - - cargo test --all --features debug - - cargo test --all --features cache-friendly - - - diff --git a/.gitignore b/snmalloc-rs/.gitignore similarity index 100% rename from .gitignore rename to snmalloc-rs/.gitignore diff --git a/CHANGELOG.md b/snmalloc-rs/CHANGELOG.md similarity index 100% rename from CHANGELOG.md rename to snmalloc-rs/CHANGELOG.md diff --git a/Cargo.toml b/snmalloc-rs/Cargo.toml similarity index 95% rename from Cargo.toml rename to snmalloc-rs/Cargo.toml index 3c45fc7b5..30e1de4e3 100644 --- a/Cargo.toml +++ b/snmalloc-rs/Cargo.toml @@ -8,7 +8,7 @@ description = "rust bindings of snmalloc." keywords = ["snmalloc", "allocator"] categories = ["memory-management", "api-bindings"] homepage = "https://github.com/microsoft/snmalloc" -repository = "https://github.com/SchrodingerZhu/snmalloc-rs" +repository = "https://github.com/microsoft/snmalloc" readme = "README.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/LICENSE b/snmalloc-rs/LICENSE similarity index 100% rename from LICENSE rename to snmalloc-rs/LICENSE diff --git a/README.md b/snmalloc-rs/README.md similarity index 100% rename from README.md rename to snmalloc-rs/README.md diff --git a/snmalloc-sys/Cargo.toml b/snmalloc-rs/snmalloc-sys/Cargo.toml similarity index 92% rename from snmalloc-sys/Cargo.toml rename to snmalloc-rs/snmalloc-sys/Cargo.toml index b0b3f20c2..88e17154e 100644 --- a/snmalloc-sys/Cargo.toml +++ b/snmalloc-rs/snmalloc-sys/Cargo.toml @@ -8,7 +8,7 @@ description = "rust raw bindings of snmalloc." keywords = ["snmalloc", "allocator"] categories = ["memory-management", "api-bindings"] homepage = "https://github.com/microsoft/snmalloc" -repository = "https://github.com/SchrodingerZhu/snmalloc-rs" +repository = "https://github.com/microsoft/snmalloc" build = "build.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/snmalloc-sys/build.rs b/snmalloc-rs/snmalloc-sys/build.rs similarity index 99% rename from snmalloc-sys/build.rs rename to snmalloc-rs/snmalloc-sys/build.rs index 2a9440a29..35ddddea7 100644 --- a/snmalloc-sys/build.rs +++ b/snmalloc-rs/snmalloc-sys/build.rs @@ -70,7 +70,7 @@ impl BuildConfig { let builder = cc::Build::new(); #[cfg(not(feature = "build_cc"))] - let builder = Config::new("snmalloc"); + let builder = Config::new("../.."); let mut config = Self { debug, @@ -226,8 +226,8 @@ impl BuilderDefine for cc::Build { } fn configure_cpp(&mut self, debug: bool) -> &mut Self { - self.include("snmalloc/src") - .file("snmalloc/src/snmalloc/override/rust.cc") + self.include("../../src") + .file("../../src/snmalloc/override/rust.cc") .cpp(true) .debug(debug) .static_crt(true) diff --git a/snmalloc-sys/snmalloc b/snmalloc-rs/snmalloc-sys/snmalloc similarity index 100% rename from snmalloc-sys/snmalloc rename to snmalloc-rs/snmalloc-sys/snmalloc diff --git a/snmalloc-sys/src/lib.rs b/snmalloc-rs/snmalloc-sys/src/lib.rs similarity index 100% rename from snmalloc-sys/src/lib.rs rename to snmalloc-rs/snmalloc-sys/src/lib.rs diff --git a/src/lib.rs b/snmalloc-rs/src/lib.rs similarity index 100% rename from src/lib.rs rename to snmalloc-rs/src/lib.rs From 97620cd01d855c4b1f665e075195b841e0257519 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Tue, 27 Jan 2026 11:18:35 +0000 Subject: [PATCH 144/145] Adjust CI. --- .github/workflows/rust.yml | 62 ++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index ea10f7456..ee583e40c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,10 +1,18 @@ -name: Rust +name: snmalloc-rs CI + +# The following should ensure that the workflow only runs a single set of actions +# for each PR. But it will not apply this to pushes to the main branch. +concurrency: + group: ${{ github.ref }}-rust + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} on: push: - branches: [ master ] + branches: [ main ] pull_request: - branches: [ master ] + branches: [ main ] + + workflow_dispatch: env: CARGO_TERM_COLOR: always @@ -13,18 +21,44 @@ jobs: build: runs-on: ${{ matrix.os }} + name: "${{ matrix.os }}-${{ matrix.release.name }}-${{ matrix.rust }} (features: ${{ matrix.features.name }})" + defaults: + run: + shell: bash + working-directory: + ./snmalloc-rs strategy: matrix: os: [windows-latest, macos-14, macos-15, ubuntu-latest] rust: [stable, nightly] + release: + - name: release + flag: "--release" + - name: debug + flag: "" + features: + - name: default + args: "" + - name: debug + args: "--features debug" + - name: check + args: "--features check" + - name: build_cc + args: '--features "build_cc usecxx17"' + - name: native-cpu + args: "--features native-cpu" + - name: local_dynamic_tls + args: "--features local_dynamic_tls" + - name: lto + args: "--features lto" + # Don't abort runners if a single one fails + fail-fast: false steps: - uses: actions-rs/toolchain@v1 with: toolchain: ${{ matrix.rust }} - name: Checkout - uses: actions/checkout@v2 - with: - submodules: recursive + uses: actions/checkout@v4 - name: update dependency run: | if bash -c 'uname -s | grep 'Linux' >/dev/null'; then @@ -32,18 +66,6 @@ jobs: fi shell: bash - name: Build - run: cargo build --verbose + run: cargo build ${{ matrix.release.flag }} --verbose ${{ matrix.features.args }} - name: Run tests - run: cargo test --all - - name: Run tests debug - run: cargo test --all --features debug - - name: Run tests check - run: cargo test --all --features check - - name: Run tests build_cc - run: cargo test --all --features "build_cc usecxx17" - - name: Run tests native-cpu - run: cargo test --all --features native-cpu - - name: Run tests local_dynamic_tls - run: cargo test --all --features local_dynamic_tls - - name: Run tests lto - run: cargo test --all --features lto + run: cargo test ${{ matrix.release.flag }} --all ${{ matrix.features.args }} \ No newline at end of file From 07e6602dc493e27e6a5e8d190fc345cfeeb412cf Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Wed, 28 Jan 2026 16:29:11 +0000 Subject: [PATCH 145/145] Fix Windows Rust Build --- snmalloc-rs/snmalloc-sys/build.rs | 56 +++++++++++++++++-------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/snmalloc-rs/snmalloc-sys/build.rs b/snmalloc-rs/snmalloc-sys/build.rs index 35ddddea7..2a8ffebc1 100644 --- a/snmalloc-rs/snmalloc-sys/build.rs +++ b/snmalloc-rs/snmalloc-sys/build.rs @@ -252,7 +252,8 @@ impl BuilderDefine for cmake::Config { self.out_dir(out_dir) } - fn configure_cpp(&mut self, _debug: bool) -> &mut Self { + fn configure_cpp(&mut self, debug: bool) -> &mut Self { + self.profile(if debug { "Debug" } else { "Release" }); self.define("SNMALLOC_RUST_SUPPORT", "ON") .very_verbose(true) .define("CMAKE_SH", "CMAKE_SH-NOTFOUND") @@ -308,8 +309,29 @@ fn configure_platform(config: &mut BuildConfig) { for flag in common_flags { config.builder.flag_if_supported(flag); } - - if let Some(msystem) = &config.msystem { + if config.is_msvc() { + let msvc_flags = vec![ + "/nologo", "/W4", "/WX", "/wd4127", "/wd4324", "/wd4201", + "/Ob2", "/DNDEBUG", "/EHsc", "/Gd", "/TP", "/Gm-", "/GS", + "/fp:precise", "/Zc:wchar_t", "/Zc:forScope", "/Zc:inline" + ]; + for flag in msvc_flags { + config.builder.flag_if_supported(flag); + } + + if config.features.lto { + config.builder + .flag_if_supported("/GL") + .define("CMAKE_INTERPROCEDURAL_OPTIMIZATION", "TRUE") + .define("SNMALLOC_IPO", "ON"); + println!("cargo:rustc-link-arg=/LTCG"); + } + + config.builder + .define("CMAKE_CXX_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc") + .define("CMAKE_C_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc"); + } + else if let Some(msystem) = &config.msystem { match msystem.as_str() { "CLANG64" | "CLANGARM64" => { let defines = vec![ @@ -339,28 +361,6 @@ fn configure_platform(config: &mut BuildConfig) { } } } - _ if config.is_msvc() => { - let msvc_flags = vec![ - "/nologo", "/W4", "/WX", "/wd4127", "/wd4324", "/wd4201", - "/Ob2", "/DNDEBUG", "/EHsc", "/Gd", "/TP", "/Gm-", "/GS", - "/fp:precise", "/Zc:wchar_t", "/Zc:forScope", "/Zc:inline" - ]; - for flag in msvc_flags { - config.builder.flag_if_supported(flag); - } - - if config.features.lto { - config.builder - .flag_if_supported("/GL") - .define("CMAKE_INTERPROCEDURAL_OPTIMIZATION", "TRUE") - .define("SNMALLOC_IPO", "ON"); - println!("cargo:rustc-link-arg=/LTCG"); - } - - config.builder - .define("CMAKE_CXX_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc") - .define("CMAKE_C_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc"); - } _ if config.is_unix() => { let unix_flags = vec!["-fPIC", "-pthread", "-fno-exceptions", "-fno-rtti", "-mcx16", "-Wno-unused-parameter"]; for flag in unix_flags { @@ -426,7 +426,11 @@ fn configure_linking(config: &BuildConfig) { println!("cargo:rustc-link-lib=ws2_32"); println!("cargo:rustc-link-lib=userenv"); println!("cargo:rustc-link-lib=bcrypt"); - println!("cargo:rustc-link-lib=msvcrt"); + if config.debug { + println!("cargo:rustc-link-lib=msvcrtd"); + } else { + println!("cargo:rustc-link-lib=msvcrt"); + } } _ if config.is_windows() && config.is_gnu() => { println!("cargo:rustc-link-lib=kernel32");