fix(allocator): restore validated jemalloc target gating (#3236)

* fix(allocator): restore validated jemalloc target gating

Restrict the global allocator and jemalloc profiling paths to linux-gnu-x86_64 so Linux ARM64 builds fall back to mimalloc again.

Update the runtime profiling, allocator reclaim, and admin profiling handlers to use the same target gating and avoid exposing jemalloc-only code on unsupported targets.

Verification:
- cargo fmt --all
- cargo fmt --all --check
- cargo check -p rustfs
- make pre-commit

* fix(profiling): restore non-jemalloc platform behavior

Restore CPU profiling support on macOS while keeping jemalloc-backed memory profiling restricted to validated linux-gnu-x86_64 targets.

Also restore Unix log directory permission hardening so the allocator regression fix does not roll back unrelated observability behavior on other supported platforms.

Verification in progress:
- cargo fmt --all
- cargo check -p rustfs
- make pre-commit (running)

* fix(profiling): qualify periodic memory log macros

Use explicit tracing macro paths in periodic jemalloc memory profiling logging so builds do not fail when the local target configuration excludes those branches from the current import set.

Verification:
- cargo fmt --all
- cargo check -p rustfs

* fix(profiling): gate unsupported memory helper

Restrict the unsupported memory profiling helper to non-linux-gnu-x86_64 targets so Linux builds do not emit dead_code warnings for an unreachable fallback.

Verification:
- cargo fmt --all
- cargo check -p rustfs
This commit is contained in:
houseme
2026-06-06 16:22:29 +08:00
committed by GitHub
parent 60f14cb0f1
commit 6db4c3538d
10 changed files with 81 additions and 47 deletions
+1 -1
View File
@@ -71,7 +71,7 @@ zstd = { workspace = true, features = ["zstdmt"] }
sysinfo = { workspace = true }
nvml-wrapper = { workspace = true, optional = true }
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies]
[target.'cfg(any(target_os = "macos", all(target_os = "linux", target_env = "gnu", target_arch = "x86_64")))'.dependencies]
pyroscope = { workspace = true }
jemalloc_pprof = { workspace = true }
+6 -6
View File
@@ -41,9 +41,9 @@ pub struct OtelGuard {
pub(crate) meter_provider: Option<SdkMeterProvider>,
/// Optional logger provider for OTLP log export.
pub(crate) logger_provider: Option<SdkLoggerProvider>,
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(any(target_os = "macos", all(target_os = "linux", target_env = "gnu", target_arch = "x86_64")))]
pub(crate) profiling_agent: Option<pyroscope::PyroscopeAgent<pyroscope::pyroscope::PyroscopeAgentRunning>>,
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"))]
pub(crate) memory_profiling_agent: Option<pyroscope::PyroscopeAgent<pyroscope::pyroscope::PyroscopeAgentRunning>>,
/// Handle to the background log-cleanup task; aborted on drop.
pub(crate) cleanup_handle: Option<tokio::task::JoinHandle<()>>,
@@ -60,9 +60,9 @@ impl std::fmt::Debug for OtelGuard {
s.field("tracer_provider", &self.tracer_provider.is_some())
.field("meter_provider", &self.meter_provider.is_some())
.field("logger_provider", &self.logger_provider.is_some());
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(any(target_os = "macos", all(target_os = "linux", target_env = "gnu", target_arch = "x86_64")))]
s.field("profiling_agent", &self.profiling_agent.is_some());
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"))]
s.field("memory_profiling_agent", &self.memory_profiling_agent.is_some());
s.field("cleanup_handle", &self.cleanup_handle.is_some())
.field("tracing_guard", &self.tracing_guard.is_some())
@@ -95,7 +95,7 @@ impl Drop for OtelGuard {
eprintln!("Logger shutdown error: {err:?}");
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(any(target_os = "macos", all(target_os = "linux", target_env = "gnu", target_arch = "x86_64")))]
if let Some(agent) = self.profiling_agent.take() {
match agent.stop() {
Err(err) => eprintln!("Profiling agent stop error: {err:?}"),
@@ -105,7 +105,7 @@ impl Drop for OtelGuard {
}
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"))]
if let Some(agent) = self.memory_profiling_agent.take() {
match agent.stop() {
Err(err) => eprintln!("Memory profiling agent stop error: {err:?}"),
+4 -4
View File
@@ -155,9 +155,9 @@ fn init_stdout_only(_config: &OtelConfig, logger_level: &str, is_production: boo
tracer_provider: None,
meter_provider: None,
logger_provider: None,
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(any(target_os = "macos", all(target_os = "linux", target_env = "gnu", target_arch = "x86_64")))]
profiling_agent: None,
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"))]
memory_profiling_agent: None,
tracing_guard: Some(guard),
stdout_guard: None,
@@ -291,9 +291,9 @@ fn init_file_logging_internal(
tracer_provider: None,
meter_provider: None,
logger_provider: None,
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(any(target_os = "macos", all(target_os = "linux", target_env = "gnu", target_arch = "x86_64")))]
profiling_agent: None,
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"))]
memory_profiling_agent: None,
tracing_guard: Some(guard),
stdout_guard,
+7 -7
View File
@@ -164,10 +164,10 @@ pub(super) fn init_observability_http(
// ── Meter provider (HTTP) ─────────────────────────────────────────────────
let meter_provider = build_meter_provider(&metric_ep, config, res.clone(), &service_name, use_stdout)?;
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(any(target_os = "macos", all(target_os = "linux", target_env = "gnu", target_arch = "x86_64")))]
let profiling_agent = init_profiler(config);
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"))]
let memory_profiling_agent = init_memory_profiler(config);
// ── Logger Logic ──────────────────────────────────────────────────────────
@@ -210,7 +210,7 @@ pub(super) fn init_observability_http(
let file_logging_result = (|| -> Result<_, TelemetryError> {
fs::create_dir_all(log_directory).map_err(|e| TelemetryError::Io(e.to_string()))?;
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(unix)]
crate::telemetry::local::ensure_dir_permissions(log_directory)?;
let rotation_str = config
@@ -317,9 +317,9 @@ pub(super) fn init_observability_http(
tracer_provider,
meter_provider,
logger_provider,
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(any(target_os = "macos", all(target_os = "linux", target_env = "gnu", target_arch = "x86_64")))]
profiling_agent,
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"))]
memory_profiling_agent,
tracing_guard,
stdout_guard,
@@ -496,7 +496,7 @@ fn build_logger_provider(
/// Returns `None` when profiling export is disabled, when no usable
/// profiling endpoint is configured, or when building or starting the agent
/// fails.
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(any(target_os = "macos", all(target_os = "linux", target_env = "gnu", target_arch = "x86_64")))]
fn init_profiler(config: &OtelConfig) -> Option<pyroscope::PyroscopeAgent<pyroscope::pyroscope::PyroscopeAgentRunning>> {
use pyroscope::backend::{BackendConfig, PprofConfig, pprof_backend};
use pyroscope::pyroscope::PyroscopeAgentBuilder;
@@ -541,7 +541,7 @@ fn init_profiler(config: &OtelConfig) -> Option<pyroscope::PyroscopeAgent<pyrosc
///
/// Returns `None` when profiling export is disabled, the endpoint is missing,
/// jemalloc profiling is not activated, or the agent fails to build/start.
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"))]
fn init_memory_profiler(config: &OtelConfig) -> Option<pyroscope::PyroscopeAgent<pyroscope::pyroscope::PyroscopeAgentRunning>> {
use pyroscope::backend::jemalloc_backend;
use pyroscope::pyroscope::PyroscopeAgentBuilder;