Skip to content

Added mimalloc dev and dev-slice support #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
[submodule "libmimalloc-sys/c_src/mimalloc"]
path = libmimalloc-sys/c_src/mimalloc
url = https://github.com/microsoft/mimalloc
[submodule "libmimalloc-sys/c_src/mimalloc_dev"]
path = libmimalloc-sys/c_src/mimalloc_dev
url = https://github.com/microsoft/mimalloc.git
branch = dev
[submodule "libmimalloc-sys/c_src/mimalloc_dev_slice"]
path = libmimalloc-sys/c_src/mimalloc_dev_slice
url = https://github.com/microsoft/mimalloc.git
branch = dev-slice
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ override = ["libmimalloc-sys/override"]
debug = ["libmimalloc-sys/debug"]
debug_in_debug = ["libmimalloc-sys/debug_in_debug"]
local_dynamic_tls = ["libmimalloc-sys/local_dynamic_tls"]

# Allow to select different mimalloc branch
v1_dev = ["libmimalloc-sys/v1_dev"] # v1 dev branch
v2_dev = ["libmimalloc-sys/v2_dev"] # v2 dev-slice branch
# Trigger git submodule update to have the latest upstream commit to be used
# This will be for all submodules, master, dev and dev-slice
# Since mimalloc isn't fully ABI stable at the moment, it could cause issues.
submodule_update = ["libmimalloc-sys/submodule_update"]
8 changes: 8 additions & 0 deletions libmimalloc-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ override = []
extended = ["cty"]
local_dynamic_tls = []

# Allow to select different mimalloc branch
v1_dev = [] # v1 dev branch
v2_dev = [] # v2 dev-slice branch
# Trigger git submodule update to have the latest upstream commit to be used
# This will be for all submodules, master, dev and dev-slice
# Since mimalloc isn't fully ABI stable at the moment, it could cause issues.
submodule_update = []

# Show `extended` on docs.rs since it's the full API surface.
[package.metadata.docs.rs]
features = ["extended"]
32 changes: 29 additions & 3 deletions libmimalloc-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
use std::env;
use std::process::Command;

fn main() {
// Update the submodule's if the `submodule_update` feature is enabled.
// This ensures the latests commits are used to build this package.
// Since mimalloc isn't fully ABI stable at the moment, it could cause issues.
if cfg!(feature = "submodule_update") {
// Init or update the submodule with libui if needed
Command::new("git")
.args(&["version"])
.status()
.expect("Git does not appear to be installed. Error");
Command::new("git")
.args(&["submodule", "update", "--init", "--recursive", "--remote"])
.status()
.expect("Unable to update mimalloc submodule branches. Error");
}

let mut build = cc::Build::new();

build.include("c_src/mimalloc/include");
build.include("c_src/mimalloc/src");
build.file("c_src/mimalloc/src/static.c");
if cfg!(feature = "v1_dev") {
build.include("c_src/mimalloc_dev/include");
build.include("c_src/mimalloc_dev/src");
build.file("c_src/mimalloc_dev/src/static.c");
} else if cfg!(feature = "v2_dev") {
build.include("c_src/mimalloc_dev_slice/include");
build.include("c_src/mimalloc_dev_slice/src");
build.file("c_src/mimalloc_dev_slice/src/static.c");
} else {
build.include("c_src/mimalloc/include");
build.include("c_src/mimalloc/src");
build.file("c_src/mimalloc/src/static.c");
}

let target_os = env::var("CARGO_CFG_TARGET_OS").expect("target_os not defined!");
let target_family = env::var("CARGO_CFG_TARGET_FAMILY").expect("target_family not defined!");
Expand Down
1 change: 1 addition & 0 deletions libmimalloc-sys/c_src/mimalloc_dev
Submodule mimalloc_dev added at ccf117
1 change: 1 addition & 0 deletions libmimalloc-sys/c_src/mimalloc_dev_slice
Submodule mimalloc_dev_slice added at 18c189
33 changes: 20 additions & 13 deletions libmimalloc-sys/src/extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,18 @@ pub const mi_option_large_os_pages: mi_option_t = 6;
/// allocate just a little to take up space in the huge OS page area (which cannot be reset).
pub const mi_option_reserve_huge_os_pages: mi_option_t = 7;

/// TODO: update later
pub const mi_option_reserve_os_memory: mi_option_t = 8;
/// Option (experimental) reserve huge OS pages at a specific NUMA node
///
/// The huge pages are usually allocated evenly among NUMA nodes.
/// You can use mi_option_reserve_huge_os_pages_at=N where `N` is the numa node (starting at 0) to allocate all
/// the huge pages at a specific numa node instead.
pub const mi_option_reserve_huge_os_pages_at: mi_option_t = 8;

/// Option (experimental) reserve specified amount of OS memory at startup
pub const mi_option_reserve_os_memory: mi_option_t = 9;

/// Option (experimental) specifying number of segments per thread to keep cached.
pub const mi_option_segment_cache: mi_option_t = 9;
pub const mi_option_segment_cache: mi_option_t = 10;

/// Option (experimental) to reset page memory after mi_option_reset_delay milliseconds when it becomes free.
///
Expand All @@ -528,19 +535,19 @@ pub const mi_option_segment_cache: mi_option_t = 9;
/// off completely.
///
/// Default: 1 (true)
pub const mi_option_page_reset: mi_option_t = 10;
pub const mi_option_page_reset: mi_option_t = 11;

/// Experimental
pub const mi_option_abandoned_page_reset: mi_option_t = 11;
pub const mi_option_abandoned_page_reset: mi_option_t = 12;

/// Experimental
pub const mi_option_segment_reset: mi_option_t = 12;
pub const mi_option_segment_reset: mi_option_t = 13;

/// Experimental
pub const mi_option_eager_commit_delay: mi_option_t = 13;
pub const mi_option_eager_commit_delay: mi_option_t = 14;

/// Option (experimental) specifying delay in milli-seconds before resetting a page (100ms by default).
pub const mi_option_reset_delay: mi_option_t = 14;
pub const mi_option_reset_delay: mi_option_t = 15;

/// Option (experimental) to pretend there are at most N NUMA nodes.
///
Expand All @@ -549,19 +556,19 @@ pub const mi_option_reset_delay: mi_option_t = 14;
/// actual NUMA nodes is fine and will only cause threads to potentially allocate more
/// memory across actual NUMA nodes (but this can happen in any case as NUMA local
/// allocation is always a best effort but not guaranteed).
pub const mi_option_use_numa_nodes: mi_option_t = 15;
pub const mi_option_use_numa_nodes: mi_option_t = 16;

/// TODO: update later
pub const mi_option_limit_os_alloc: mi_option_t = 16;
pub const mi_option_limit_os_alloc: mi_option_t = 17;

/// Option (experimental) specifying OS tag to assign to mimalloc'd memory.
pub const mi_option_os_tag: mi_option_t = 17;
pub const mi_option_os_tag: mi_option_t = 18;

/// Experimental
pub const mi_option_max_errors: mi_option_t = 18;
pub const mi_option_max_errors: mi_option_t = 19;

/// Experimental
pub const mi_option_max_warnings: mi_option_t = 19;
pub const mi_option_max_warnings: mi_option_t = 20;

extern "C" {
// Note: mi_option_{enable,disable} aren't exposed because they're redundant
Expand Down
2 changes: 1 addition & 1 deletion libmimalloc-sys/sys-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ libmimalloc-sys = { path = "..", features = ["extended"] }
libc = "0.2"

[build-dependencies]
ctest = "0.2"
ctest2 = "0.4"
2 changes: 1 addition & 1 deletion libmimalloc-sys/sys-test/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() {
let mut cfg = ctest::TestGenerator::new();
let mut cfg = ctest2::TestGenerator::new();
cfg.header("mimalloc.h")
.include(concat!(
env!("CARGO_MANIFEST_DIR"),
Expand Down
2 changes: 1 addition & 1 deletion libmimalloc-sys/sys-test/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(bad_style, clippy::all)]
#![allow(bad_style, deprecated, clippy::all)]

use libmimalloc_sys::*;

Expand Down