fix(ci): repair post-merge build gates

This commit is contained in:
Zhengchao An
2026-08-24 16:10:24 +08:00
committed by GitHub
parent d293ed71e5
commit 7d3f5545e7
11 changed files with 139 additions and 41 deletions
+1 -2
View File
@@ -57,7 +57,7 @@ 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", "dep:rustfs-mimalloc-sys"]
mimalloc = ["dep:rustfs-mimalloc"]
jemalloc = ["dep:tikv-jemallocator"]
hotpath = [
"hotpath/hotpath",
@@ -345,7 +345,6 @@ rustfs-mimalloc = { workspace = true, optional = true }
libsystemd.workspace = true
[target.'cfg(not(target_os = "windows"))'.dependencies]
rustfs-mimalloc-sys = { workspace = true, optional = true }
tikv-jemallocator = { version = "0.6", optional = true }
[dev-dependencies]
+15 -5
View File
@@ -169,15 +169,25 @@ impl AllocatorReclaimController {
/// Return the allocator backend name used by reclaim and memory metrics.
pub fn allocator_backend() -> &'static str {
#[cfg(not(target_os = "windows"))]
#[cfg(all(feature = "mimalloc", not(target_os = "windows")))]
{
"mimalloc"
}
#[cfg(target_os = "windows")]
#[cfg(all(feature = "mimalloc", 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 {
@@ -368,15 +378,15 @@ pub fn allocator_reclaim_controller_snapshot(ctx: &CancellationToken) -> Allocat
)
}
#[cfg(not(target_os = "windows"))]
#[cfg(all(feature = "mimalloc", not(target_os = "windows")))]
fn collect_allocator_memory(force: bool) -> Result<(), String> {
rustfs_mimalloc::MiMalloc::collect(force);
Ok(())
}
#[cfg(target_os = "windows")]
#[cfg(not(all(feature = "mimalloc", not(target_os = "windows"))))]
fn collect_allocator_memory(_force: bool) -> Result<(), String> {
Err("allocator reclaim is not supported on Windows".to_string())
Err("allocator reclaim requires mimalloc on a non-Windows target".to_string())
}
/// Execute one allocator collection and publish the outcome metrics.
+1 -3
View File
@@ -65,8 +65,6 @@ use super::storage_api::object_usecase::contract::http::HTTPPreconditions;
use super::storage_api::object_usecase::contract::namespace::NamespaceLocking;
use super::storage_api::object_usecase::contract::object::{ObjectIO as _, ObjectOperations as _};
use super::storage_api::object_usecase::contract::range::HTTPRangeSpec;
#[cfg(test)]
use super::storage_api::object_usecase::data_usage::apply_bucket_usage_memory_overlay;
use super::storage_api::object_usecase::data_usage::{
quota_object_size, record_bucket_delete_marker_memory, record_bucket_object_delete_memory,
record_bucket_object_version_write_memory, record_bucket_object_write_memory,
@@ -18082,7 +18080,7 @@ mod tests {
async fn observed_bucket_usage(bucket: &str) -> Option<u64> {
let mut usage = rustfs_data_usage::DataUsageInfo::default();
crate::app::storage_api::object_usecase::data_usage::apply_bucket_usage_memory_overlay(&mut usage).await;
apply_bucket_usage_memory_overlay(&mut usage).await;
usage.buckets_usage.get(bucket).map(|value| value.size)
}
+5
View File
@@ -52,6 +52,11 @@
//! 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
+65 -6
View File
@@ -12,14 +12,29 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#[cfg(all(feature = "hotpath", feature = "hotpath-alloc"))]
#[cfg(all(
feature = "hotpath",
feature = "hotpath-alloc",
feature = "mimalloc",
not(feature = "jemalloc")
))]
use std::alloc::{GlobalAlloc, Layout};
#[cfg(all(feature = "hotpath", feature = "hotpath-alloc"))]
#[cfg(all(
feature = "hotpath",
feature = "hotpath-alloc",
feature = "mimalloc",
not(feature = "jemalloc")
))]
#[derive(Default)]
struct MiMallocAllocator;
#[cfg(all(feature = "hotpath", feature = "hotpath-alloc"))]
#[cfg(all(
feature = "hotpath",
feature = "hotpath-alloc",
feature = "mimalloc",
not(feature = "jemalloc")
))]
// SAFETY: allocation operations are forwarded unchanged to MiMalloc, so
// MiMalloc's GlobalAlloc guarantees apply to every returned pointer and layout.
#[allow(unsafe_code)]
@@ -45,21 +60,65 @@ unsafe impl GlobalAlloc for MiMallocAllocator {
}
}
#[cfg(all(feature = "hotpath", feature = "hotpath-alloc"))]
#[cfg(all(
feature = "hotpath",
feature = "hotpath-alloc",
feature = "mimalloc",
not(feature = "jemalloc")
))]
#[global_allocator]
static GLOBAL: hotpath::CountingAllocator<MiMallocAllocator> = hotpath::CountingAllocator::with(MiMallocAllocator);
#[cfg(not(all(feature = "hotpath", feature = "hotpath-alloc")))]
#[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"))
))]
#[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")
))]
#[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", not(target_os = "windows")))]
#[cfg(all(
test,
feature = "hotpath",
feature = "hotpath-alloc",
feature = "mimalloc",
not(feature = "jemalloc"),
not(target_os = "windows")
))]
mod tests {
#[test]
// SAFETY: This test inspects a live allocation pointer with mimalloc's heap
+16 -1
View File
@@ -17,6 +17,7 @@ use rustfs_io_metrics::{
record_cpu_usage, record_memory_usage, record_process_memory_split,
};
use serde::Serialize;
#[cfg(any(feature = "mimalloc", test))]
use serde_json::Value;
use std::path::Path;
use std::sync::{Arc, Mutex, OnceLock};
@@ -228,6 +229,7 @@ fn read_cgroup_memory_snapshot() -> Option<CgroupMemorySnapshot> {
read_cgroup_v2().or_else(read_cgroup_v1)
}
#[cfg(feature = "mimalloc")]
fn read_allocator_memory_snapshot() -> Option<AllocatorMemorySnapshot> {
let json = rustfs_mimalloc::MiMalloc::stats_json();
if json.is_empty() {
@@ -240,6 +242,12 @@ fn read_allocator_memory_snapshot() -> Option<AllocatorMemorySnapshot> {
})
}
#[cfg(not(feature = "mimalloc"))]
fn read_allocator_memory_snapshot() -> Option<AllocatorMemorySnapshot> {
None
}
#[cfg(any(feature = "mimalloc", test))]
fn numeric_json_value(value: &Value) -> Option<u64> {
match value {
Value::Number(number) => number
@@ -250,6 +258,7 @@ fn numeric_json_value(value: &Value) -> Option<u64> {
}
}
#[cfg(any(feature = "mimalloc", test))]
fn numeric_json_field(value: &Value, field: &str) -> Option<u64> {
match value {
Value::Object(fields) => fields
@@ -261,6 +270,7 @@ fn numeric_json_field(value: &Value, field: &str) -> Option<u64> {
}
}
#[cfg(any(feature = "mimalloc", test))]
fn mimalloc_stat_field(value: &Value, metric: &str, field: &str) -> Option<u64> {
match value {
Value::Object(fields) => {
@@ -277,10 +287,12 @@ fn mimalloc_stat_field(value: &Value, metric: &str, field: &str) -> Option<u64>
}
}
#[cfg(any(feature = "mimalloc", test))]
fn mimalloc_stat_current(value: &Value, metric: &str) -> Option<u64> {
mimalloc_stat_field(value, metric, "current")
}
#[cfg(any(feature = "mimalloc", test))]
fn mimalloc_stat_sum(value: &Value, metrics: &[&str], field: &str) -> Option<u64> {
metrics
.iter()
@@ -289,6 +301,7 @@ fn mimalloc_stat_sum(value: &Value, metrics: &[&str], field: &str) -> Option<u64
.filter(|value| *value > 0)
}
#[cfg(any(feature = "mimalloc", 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"];
@@ -545,8 +558,10 @@ mod tests {
#[test]
fn read_allocator_memory_snapshot_uses_mimalloc_stats_json() {
let snapshot = super::read_allocator_memory_snapshot();
#[cfg(not(target_os = "windows"))]
#[cfg(all(feature = "mimalloc", not(target_os = "windows")))]
assert!(snapshot.is_some(), "allocator snapshot should be available on non-Windows");
#[cfg(not(feature = "mimalloc"))]
assert!(snapshot.is_none(), "allocator snapshot should be absent without mimalloc");
}
#[test]