diff --git a/Cargo.lock b/Cargo.lock index 67ee39a64..891a1c340 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -991,7 +991,6 @@ dependencies = [ "figment", "futures", "governor", - "hardened_malloc-rs", "http", "http-body-util", "hyper-util", @@ -1001,6 +1000,7 @@ dependencies = [ "libloading 0.9.1", "lock_api 0.5.0", "maplit", + "mimalloc", "nix", "num-traits", "openidconnect", @@ -2395,12 +2395,6 @@ dependencies = [ "tokio-util", ] -[[package]] -name = "hardened_malloc-rs" -version = "0.1.2+12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "647deb1583b14d160f85f3ff626f20b6edd366e3852c9843b06077388f794cb6" - [[package]] name = "hashbrown" version = "0.12.3" @@ -3256,6 +3250,15 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" +[[package]] +name = "libmimalloc-sys" +version = "0.1.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a45a52f43e1c16f667ccfe4dd8c85b7f7c204fd5e3bf46c5b0db9a5c3c0b8e9" +dependencies = [ + "cc", +] + [[package]] name = "libz-sys" version = "1.1.32" @@ -3429,6 +3432,15 @@ dependencies = [ "walkdir", ] +[[package]] +name = "mimalloc" +version = "0.1.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d4139bb28d14ad1facf21d5eb8825051b326e172d216b39f6d31df53cc97862" +dependencies = [ + "libmimalloc-sys", +] + [[package]] name = "mime" version = "0.3.18" diff --git a/Cargo.toml b/Cargo.toml index df89a71f0..57ca88ac6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -522,15 +522,6 @@ features = ["resource"] version = "0.5.0" default-features = false -[workspace.dependencies.hardened_malloc-rs] -version = "0.1.2" -default-features = false -features = [ - "static", - "gcc", - "light", -] - [workspace.dependencies.rustyline-async] version = "0.4.9" default-features = false @@ -610,6 +601,9 @@ features = ["unstable-msc4188"] [workspace.dependencies.serde_urlencoded] version = "0.7.1" +[workspace.dependencies.mimalloc] +version = "0.1.52" + # # Patches # diff --git a/src/core/Cargo.toml b/src/core/Cargo.toml index 335ba023a..00f59a9e0 100644 --- a/src/core/Cargo.toml +++ b/src/core/Cargo.toml @@ -26,14 +26,14 @@ conduwuit_mods = [ gzip_compression = [ "reqwest/gzip", ] -hardened_malloc = [ - "dep:hardened_malloc-rs" -] jemalloc = [ "dep:tikv-jemalloc-sys", "dep:tikv-jemalloc-ctl", "dep:tikv-jemallocator", ] +mimalloc = [ + "dep:mimalloc", +] jemalloc_conf = [] jemalloc_prof = [ "tikv-jemalloc-sys/profiling", @@ -118,14 +118,12 @@ lock_api.workspace = true hyper-util.workspace = true resolvematrix.workspace = true openidconnect.workspace = true +mimalloc.optional = true +mimalloc.workspace = true [target.'cfg(unix)'.dependencies] nix.workspace = true -[target.'cfg(all(not(target_env = "msvc"), target_os = "linux"))'.dependencies] -hardened_malloc-rs.workspace = true -hardened_malloc-rs.optional = true - [dev-dependencies] maplit.workspace = true opentelemetry_sdk.workspace = true diff --git a/src/core/alloc/hardened.rs b/src/core/alloc/hardened.rs deleted file mode 100644 index 69628ba7d..000000000 --- a/src/core/alloc/hardened.rs +++ /dev/null @@ -1,18 +0,0 @@ -//! hmalloc allocator - -#[global_allocator] -static HMALLOC: hardened_malloc_rs::HardenedMalloc = hardened_malloc_rs::HardenedMalloc; - -pub fn trim>>(_: I) -> crate::Result { Ok(()) } - -#[must_use] -//TODO: get usage -pub fn memory_usage() -> Option { None } - -#[must_use] -pub fn memory_usage_stats() -> Option<[(&'static str, usize); 6]> { None } - -#[must_use] -pub fn memory_stats(_opts: &str) -> Option { - Some("Extended statistics are not available from hardened_malloc.".to_owned()) -} diff --git a/src/core/alloc/mimalloc.rs b/src/core/alloc/mimalloc.rs new file mode 100644 index 000000000..272a4081a --- /dev/null +++ b/src/core/alloc/mimalloc.rs @@ -0,0 +1,4 @@ +use mimalloc::MiMalloc; + +#[global_allocator] +static GLOBAL: MiMalloc = MiMalloc; diff --git a/src/core/alloc/mod.rs b/src/core/alloc/mod.rs index a34809412..f137771e7 100644 --- a/src/core/alloc/mod.rs +++ b/src/core/alloc/mod.rs @@ -1,27 +1,14 @@ //! Integration with allocators -// jemalloc -#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))] +pub mod default; + +#[cfg(feature = "jemalloc")] pub mod je; -#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))] +#[cfg(feature = "jemalloc")] pub use je::{memory_stats, memory_usage, memory_usage_stats, trim}; -#[cfg(all(not(target_env = "msvc"), feature = "hardened_malloc", not(feature = "jemalloc")))] -pub mod hardened; -#[cfg(all( - not(target_env = "msvc"), - feature = "hardened_malloc", - not(feature = "jemalloc") -))] -pub use hardened::{memory_stats, memory_usage, memory_usage_stats, trim}; +#[cfg(all(feature = "mimalloc", not(feature = "jemalloc")))] +pub mod mimalloc; -#[cfg(any( - target_env = "msvc", - all(not(feature = "hardened_malloc"), not(feature = "jemalloc")) -))] -pub mod default; -#[cfg(any( - target_env = "msvc", - all(not(feature = "hardened_malloc"), not(feature = "jemalloc")) -))] +#[cfg(not(feature = "jemalloc"))] pub use default::{memory_stats, memory_usage, memory_usage_stats, trim}; diff --git a/src/core/config/check.rs b/src/core/config/check.rs index 1e3efdb5e..e7aa6649b 100644 --- a/src/core/config/check.rs +++ b/src/core/config/check.rs @@ -43,10 +43,10 @@ pub fn check(config: &Config) -> Result { )); } - if cfg!(all(feature = "hardened_malloc", feature = "jemalloc", not(target_env = "msvc"))) { + if cfg!(all(feature = "mimalloc", feature = "jemalloc")) { debug_warn!( - "hardened_malloc and jemalloc compile-time features are both enabled, this causes \ - jemalloc to be used." + "mimalloc and jemalloc compile-time features are both enabled, this causes jemalloc \ + to be used." ); } diff --git a/src/main/Cargo.toml b/src/main/Cargo.toml index 18cc054a7..db155c5bd 100644 --- a/src/main/Cargo.toml +++ b/src/main/Cargo.toml @@ -70,7 +70,6 @@ standard = [ ] full = [ "standard", - # "hardened_malloc", # Conflicts with jemalloc "jemalloc_prof", "perf_measurements", "tokio_console", @@ -96,9 +95,6 @@ gzip_compression = [ "conduwuit-router/gzip_compression", "conduwuit-service/gzip_compression", ] -hardened_malloc = [ - "conduwuit-core/hardened_malloc", -] http3 = [ "conduwuit-service/http3" ] @@ -116,6 +112,9 @@ jemalloc = [ "conduwuit-core/jemalloc", "conduwuit-service/jemalloc", ] +mimalloc = [ + "conduwuit-core/mimalloc" +] jemalloc_prof = [ "conduwuit-core/jemalloc_prof", ]