fix(build): restore mimalloc workspace dependency

This commit is contained in:
Zhengchao An
2026-08-24 17:26:54 +08:00
committed by GitHub
parent 8f2b91f79b
commit 8bd6d8c4db
9 changed files with 32 additions and 119 deletions
Generated
+1 -21
View File
@@ -9235,6 +9235,7 @@ dependencies = [
"rustfs-log-analyzer",
"rustfs-madmin",
"rustfs-mimalloc",
"rustfs-mimalloc-sys",
"rustfs-notify",
"rustfs-object-capacity",
"rustfs-object-data-cache",
@@ -9273,7 +9274,6 @@ dependencies = [
"temp-env",
"tempfile",
"thiserror 2.0.20",
"tikv-jemallocator",
"time",
"tokio",
"tokio-rustls",
@@ -11999,26 +11999,6 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "tikv-jemalloc-sys"
version = "0.6.1+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd8aa5b2ab86a2cefa406d889139c162cbb230092f7d1d7cbc1716405d852a3b"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "tikv-jemallocator"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0359b4327f954e0567e69fb191cf1436617748813819c94b8cd4a431422d053a"
dependencies = [
"libc",
"tikv-jemalloc-sys",
]
[[package]]
name = "time"
version = "0.3.55"
+2
View File
@@ -210,6 +210,7 @@ sha1 = "0.11.0"
sha2 = "0.11.0"
subtle = "2.6"
zeroize = { version = "1.9.0" }
proptest = "1"
# Time and Date
chrono = { version = "0.4.45" }
@@ -352,6 +353,7 @@ dav-server = "0.11.0"
# Performance Analysis and Memory Profiling
rustfs-mimalloc = { version = "0.5.0" }
rustfs-mimalloc-sys = { version = "0.5.0" }
hotpath = { version = "0.24.0", default-features = false }
# Snapshot testing for output format regression detection
insta = { version = "1.48" }
+2
View File
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#![recursion_limit = "256"]
mod error;
pub mod heal;
+2
View File
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#![recursion_limit = "256"]
//! HS-01 (rustfs/backlog#1865): MRF intent pipeline integration tests.
//!
//! Drives the real consumer loop (`spawn_mrf_consumer`) against a real
+3 -6
View File
@@ -56,9 +56,6 @@ rio-v2 = ["rustfs-ecstore/rio-v2"]
pyroscope = ["rustfs-obs/pyroscope"]
# Tokio runtime telemetry. Requires `--cfg tokio_unstable`; use `make build-profiling`.
dial9 = ["rustfs-obs/dial9"]
# Allocator features
mimalloc = ["dep:rustfs-mimalloc"]
jemalloc = ["dep:tikv-jemallocator"]
hotpath = [
"hotpath/hotpath",
"hotpath/tokio",
@@ -339,13 +336,13 @@ opentelemetry = { workspace = true }
tracing-opentelemetry = { workspace = true }
# Data structures
hashbrown = { workspace = true, features = ["serde", "rayon"] }
rustfs-mimalloc = { workspace = true, optional = true }
rustfs-mimalloc = { workspace = true }
[target.'cfg(target_os = "linux")'.dependencies]
libsystemd.workspace = true
[target.'cfg(not(target_os = "windows"))'.dependencies]
tikv-jemallocator = { version = "0.6", optional = true }
rustfs-mimalloc-sys = { workspace = true }
[dev-dependencies]
uuid = { workspace = true, features = ["v4", "v5", "fast-rng", "macro-diagnostics"] }
@@ -354,7 +351,7 @@ tempfile = { workspace = true }
aws-config = { workspace = true }
anyhow = { workspace = true }
insta = { workspace = true, features = ["yaml", "json"] }
proptest = "1"
proptest = { workspace = true }
tokio = { workspace = true, features = ["test-util", "fs", "rt-multi-thread"] }
temp-env = { workspace = true, features = ["async_closure"] }
tracing-subscriber = { workspace = true, features = ["env-filter", "time"] }
+4 -14
View File
@@ -169,25 +169,15 @@ impl AllocatorReclaimController {
/// Return the allocator backend name used by reclaim and memory metrics.
pub fn allocator_backend() -> &'static str {
#[cfg(all(feature = "mimalloc", not(target_os = "windows")))]
#[cfg(not(target_os = "windows"))]
{
"mimalloc"
}
#[cfg(all(feature = "mimalloc", target_os = "windows"))]
#[cfg(target_os = "windows")]
{
"mimalloc-windows"
}
#[cfg(all(not(feature = "mimalloc"), feature = "jemalloc"))]
{
"jemalloc"
}
#[cfg(not(any(feature = "mimalloc", feature = "jemalloc")))]
{
"system"
}
}
fn active_requests() -> u64 {
@@ -378,13 +368,13 @@ pub fn allocator_reclaim_controller_snapshot(ctx: &CancellationToken) -> Allocat
)
}
#[cfg(all(feature = "mimalloc", not(target_os = "windows")))]
#[cfg(not(target_os = "windows"))]
fn collect_allocator_memory(force: bool) -> Result<(), String> {
rustfs_mimalloc::MiMalloc::collect(force);
Ok(())
}
#[cfg(not(all(feature = "mimalloc", not(target_os = "windows"))))]
#[cfg(target_os = "windows")]
fn collect_allocator_memory(_force: bool) -> Result<(), String> {
Err("allocator reclaim requires mimalloc on a non-Windows target".to_string())
}
-5
View File
@@ -52,11 +52,6 @@
//! tests where you start one server in a background task, run all your
//! tests, and then shut it down.
#[cfg(all(feature = "mimalloc", feature = "jemalloc"))]
compile_error!("allocator features 'mimalloc' and 'jemalloc' are mutually exclusive");
#[cfg(all(feature = "jemalloc", target_os = "windows"))]
compile_error!("allocator feature 'jemalloc' is not supported on Windows");
/// Scope-based hotpath measurement for `#[async_trait]` methods, where
/// `#[hotpath::measure]` would only time the boxed-future construction.
/// The guard records wall time from this statement until the enclosing
+7 -62
View File
@@ -12,29 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#[cfg(all(
feature = "hotpath",
feature = "hotpath-alloc",
feature = "mimalloc",
not(feature = "jemalloc")
))]
#[cfg(all(feature = "hotpath", feature = "hotpath-alloc", not(target_os = "windows")))]
use std::alloc::{GlobalAlloc, Layout};
#[cfg(all(
feature = "hotpath",
feature = "hotpath-alloc",
feature = "mimalloc",
not(feature = "jemalloc")
))]
#[cfg(all(feature = "hotpath", feature = "hotpath-alloc", not(target_os = "windows")))]
#[derive(Default)]
struct MiMallocAllocator;
#[cfg(all(
feature = "hotpath",
feature = "hotpath-alloc",
feature = "mimalloc",
not(feature = "jemalloc")
))]
#[cfg(all(feature = "hotpath", feature = "hotpath-alloc", not(target_os = "windows")))]
// SAFETY: allocation operations are forwarded unchanged to MiMalloc, so
// MiMalloc's GlobalAlloc guarantees apply to every returned pointer and layout.
#[allow(unsafe_code)]
@@ -60,65 +45,25 @@ unsafe impl GlobalAlloc for MiMallocAllocator {
}
}
#[cfg(all(
feature = "hotpath",
feature = "hotpath-alloc",
feature = "mimalloc",
not(feature = "jemalloc")
))]
#[cfg(all(feature = "hotpath", feature = "hotpath-alloc", not(target_os = "windows")))]
#[global_allocator]
static GLOBAL: hotpath::CountingAllocator<MiMallocAllocator> = hotpath::CountingAllocator::with(MiMallocAllocator);
#[cfg(all(
feature = "hotpath",
feature = "hotpath-alloc",
feature = "jemalloc",
not(feature = "mimalloc"),
not(target_os = "windows")
))]
#[global_allocator]
static GLOBAL: hotpath::CountingAllocator<tikv_jemallocator::Jemalloc> =
hotpath::CountingAllocator::with(tikv_jemallocator::Jemalloc);
#[cfg(all(
feature = "hotpath",
feature = "hotpath-alloc",
not(any(feature = "mimalloc", feature = "jemalloc"))
))]
#[cfg(all(feature = "hotpath", feature = "hotpath-alloc", target_os = "windows"))]
#[global_allocator]
static GLOBAL: hotpath::CountingAllocator<std::alloc::System> = hotpath::CountingAllocator::with(std::alloc::System);
#[cfg(all(
not(all(feature = "hotpath", feature = "hotpath-alloc")),
feature = "mimalloc",
not(feature = "jemalloc")
))]
#[cfg(all(not(all(feature = "hotpath", feature = "hotpath-alloc")), not(target_os = "windows")))]
#[global_allocator]
static GLOBAL: rustfs_mimalloc::MiMalloc = rustfs_mimalloc::MiMalloc;
#[cfg(all(
not(all(feature = "hotpath", feature = "hotpath-alloc")),
feature = "jemalloc",
not(feature = "mimalloc"),
not(target_os = "windows")
))]
#[global_allocator]
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
fn main() {
let _hotpath_guard = hotpath::HotpathGuardBuilder::new("main").build();
rustfs::startup_entrypoint::run_process();
}
#[cfg(all(
test,
feature = "hotpath",
feature = "hotpath-alloc",
feature = "mimalloc",
not(feature = "jemalloc"),
not(target_os = "windows")
))]
#[cfg(all(test, feature = "hotpath", feature = "hotpath-alloc", not(target_os = "windows")))]
mod tests {
#[test]
// SAFETY: This test inspects a live allocation pointer with mimalloc's heap
+11 -11
View File
@@ -17,7 +17,7 @@ use rustfs_io_metrics::{
record_cpu_usage, record_memory_usage, record_process_memory_split,
};
use serde::Serialize;
#[cfg(any(feature = "mimalloc", test))]
#[cfg(any(not(target_os = "windows"), test))]
use serde_json::Value;
use std::path::Path;
use std::sync::{Arc, Mutex, OnceLock};
@@ -229,7 +229,7 @@ fn read_cgroup_memory_snapshot() -> Option<CgroupMemorySnapshot> {
read_cgroup_v2().or_else(read_cgroup_v1)
}
#[cfg(feature = "mimalloc")]
#[cfg(not(target_os = "windows"))]
fn read_allocator_memory_snapshot() -> Option<AllocatorMemorySnapshot> {
let json = rustfs_mimalloc::MiMalloc::stats_json();
if json.is_empty() {
@@ -242,12 +242,12 @@ fn read_allocator_memory_snapshot() -> Option<AllocatorMemorySnapshot> {
})
}
#[cfg(not(feature = "mimalloc"))]
#[cfg(target_os = "windows")]
fn read_allocator_memory_snapshot() -> Option<AllocatorMemorySnapshot> {
None
}
#[cfg(any(feature = "mimalloc", test))]
#[cfg(any(not(target_os = "windows"), test))]
fn numeric_json_value(value: &Value) -> Option<u64> {
match value {
Value::Number(number) => number
@@ -258,7 +258,7 @@ fn numeric_json_value(value: &Value) -> Option<u64> {
}
}
#[cfg(any(feature = "mimalloc", test))]
#[cfg(any(not(target_os = "windows"), test))]
fn numeric_json_field(value: &Value, field: &str) -> Option<u64> {
match value {
Value::Object(fields) => fields
@@ -270,7 +270,7 @@ fn numeric_json_field(value: &Value, field: &str) -> Option<u64> {
}
}
#[cfg(any(feature = "mimalloc", test))]
#[cfg(any(not(target_os = "windows"), test))]
fn mimalloc_stat_field(value: &Value, metric: &str, field: &str) -> Option<u64> {
match value {
Value::Object(fields) => {
@@ -287,12 +287,12 @@ fn mimalloc_stat_field(value: &Value, metric: &str, field: &str) -> Option<u64>
}
}
#[cfg(any(feature = "mimalloc", test))]
#[cfg(any(not(target_os = "windows"), test))]
fn mimalloc_stat_current(value: &Value, metric: &str) -> Option<u64> {
mimalloc_stat_field(value, metric, "current")
}
#[cfg(any(feature = "mimalloc", test))]
#[cfg(any(not(target_os = "windows"), test))]
fn mimalloc_stat_sum(value: &Value, metrics: &[&str], field: &str) -> Option<u64> {
metrics
.iter()
@@ -301,7 +301,7 @@ fn mimalloc_stat_sum(value: &Value, metrics: &[&str], field: &str) -> Option<u64
.filter(|value| *value > 0)
}
#[cfg(any(feature = "mimalloc", test))]
#[cfg(any(not(target_os = "windows"), test))]
fn parse_mimalloc_stats_json(stats_json: &str) -> Option<AllocatorMemoryObservation> {
let value = serde_json::from_str::<Value>(stats_json).ok()?;
let malloc_metrics = ["malloc_normal", "malloc_huge"];
@@ -558,9 +558,9 @@ mod tests {
#[test]
fn read_allocator_memory_snapshot_uses_mimalloc_stats_json() {
let snapshot = super::read_allocator_memory_snapshot();
#[cfg(all(feature = "mimalloc", not(target_os = "windows")))]
#[cfg(not(target_os = "windows"))]
assert!(snapshot.is_some(), "allocator snapshot should be available on non-Windows");
#[cfg(not(feature = "mimalloc"))]
#[cfg(target_os = "windows")]
assert!(snapshot.is_none(), "allocator snapshot should be absent without mimalloc");
}