Skip to content

Commit

Permalink
parity-util-mem: update mimalloc feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ordian committed Mar 12, 2020
1 parent 01ccef7 commit 6b3c09f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
11 changes: 3 additions & 8 deletions parity-util-mem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ dlmalloc = { version = "0.1.3", features = ["global"], optional = true }
wee_alloc = { version = "0.4.5", optional = true }
lru = { version = "0.4", optional = true }
hashbrown = { version = "0.6", optional = true }
# from https://github.com/microsoft/mimalloc:
# mimalloc can be built in secure mode,
# adding guard pages, randomized allocation, encrypted free lists, etc.
# to protect against various heap vulnerabilities.
# The performance penalty is only around 3% on average over our benchmarks.
mimallocator = { version = "0.1.3", features = ["secure"], optional = true }
mimalloc-sys = { version = "0.1.6", optional = true }
mimalloc = { version = "0.1.18", default-features = false, optional = true }
libmimalloc-sys = { version = "0.1.14", optional = true }
parity-util-mem-derive = { path = "derive", version = "0.1" }
impl-trait-for-tuples = "0.1.3"

Expand All @@ -45,7 +40,7 @@ weealloc-global = ["wee_alloc", "estimate-heapsize"]
# use jemalloc as global allocator
jemalloc-global = ["jemallocator"]
# use mimalloc as global allocator
mimalloc-global = ["mimallocator", "mimalloc-sys"]
mimalloc-global = ["mimalloc", "libmimalloc-sys"]
# implement additional types
ethereum-impls = ["ethereum-types", "primitive-types"]
# Full estimate: no call to allocator
Expand Down
2 changes: 1 addition & 1 deletion parity-util-mem/src/allocators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ mod usable_size {
pub unsafe extern "C" fn malloc_usable_size(ptr: *const c_void) -> usize {
// mimalloc doesn't actually mutate the value ptr points to,
// but requires a mut pointer in the API
mimalloc_sys::mi_usable_size(ptr as *mut _)
libmimalloc_sys::mi_usable_size(ptr as *mut _)
}

} else if #[cfg(target_os = "linux")] {
Expand Down
10 changes: 5 additions & 5 deletions parity-util-mem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ cfg_if::cfg_if! {
not(target_os = "windows"),
not(target_arch = "wasm32")
))] {
#[global_allocator]
/// Global allocator
#[global_allocator]
pub static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
} else if #[cfg(feature = "dlmalloc-global")] {
#[global_allocator]
/// Global allocator
#[global_allocator]
pub static ALLOC: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc;
} else if #[cfg(feature = "weealloc-global")] {
#[global_allocator]
/// Global allocator
#[global_allocator]
pub static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
} else if #[cfg(all(
feature = "mimalloc-global",
not(target_arch = "wasm32")
))] {
#[global_allocator]
/// Global allocator
pub static ALLOC: mimallocator::Mimalloc = mimallocator::Mimalloc;
#[global_allocator]
pub static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
} else {
// default allocator used
}
Expand Down

0 comments on commit 6b3c09f

Please sign in to comment.