Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/agent-data-plane/configuration/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ Controls whether the global memory limiter exerts backpressure as memory usage a

### `memory_mode`

Controls how the calculated memory bounds are reconciled against `memory_limit`. The default is `disabled`. Accepted values: `disabled` skips bounds validation and applies no memory limiting; `permissive` logs a warning when the bounds do not fit within the limit and starts anyway; `strict` refuses to start. Under `permissive` and `strict`, the global memory limiter is active only when a limit is in effect (configured or detected from cgroups) and `enable_global_limiter` is `true`.
Controls how the calculated memory bounds are reconciled against `memory_limit`. The default is `disabled`. Accepted values: `disabled` skips bounds validation and applies no memory limiting; `permissive` logs a warning when the bounds do not fit within the limit and starts anyway; `strict` refuses to start. Under `permissive` and `strict`, the global memory limiter is active only when a limit is in effect (configured or detected from cgroups) and `enable_global_limiter` is `true`. These modes also enable a byte budget for admission independently of the global limiter. It tracks the configured process limit and the Linux cgroup v2 limit separately when both exist. The `disabled` mode does not create a byte budget.



Expand Down
5 changes: 4 additions & 1 deletion lib/datadog-agent/config-overlay-model/src/saluki_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,10 @@ pub static SALUKI_KEYS: &[SalukiKey] = &[
no memory limiting; `permissive` logs a warning when the bounds do not fit within the \
limit and starts anyway; `strict` refuses to start. Under `permissive` and `strict`, \
the global memory limiter is active only when a limit is in effect (configured or \
detected from cgroups) and `enable_global_limiter` is `true`.",
detected from cgroups) and `enable_global_limiter` is `true`. These modes also \
enable a byte budget for admission independently of the global limiter. It tracks \
the configured process limit and the Linux cgroup v2 limit separately when both \
exist. The `disabled` mode does not create a byte budget.",
),
},
];
45 changes: 40 additions & 5 deletions lib/saluki-app/src/accounting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use saluki_api::{DynamicRoute, EndpointType};
use saluki_common::resource_tracking::{ResourceGroupRegistry, ResourceStats, ResourceStatsSnapshot};
use saluki_common::{collections::FastHashMap, sync::shutdown::ShutdownHandle};
use saluki_core::accounting::{
ComponentBounds, ComponentRegistry, ComponentRegistryHandle, MemoryGrant, MemoryLimiter,
ByteBudget, CgroupMemory, ComponentBounds, ComponentRegistry, ComponentRegistryHandle, MemoryGrant, MemoryLimiter,
};
use saluki_core::{
diagnostic::DiagnosticsEmitter,
Expand All @@ -23,7 +23,7 @@ use tracing::{error, info, warn};
/// Bounds validation and global memory limiter behavior.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum MemoryMode {
/// Bounds validation is skipped, and no memory limiting is applied.
/// Bounds verification, cooperative backpressure, and byte-budget admission are disabled.
#[default]
Disabled,

Expand Down Expand Up @@ -72,6 +72,10 @@ pub struct MemoryBoundsConfiguration {
/// When no memory limit is configured and `DOCKER_DD_AGENT` is set to a non-empty value, the limit is read from the
/// process cgroup instead.
///
/// In permissive and strict modes, an opt-in byte budget tracks configured process and finite cgroup v2 limits
/// independently. The budget uses the smaller remaining allowance, even when cooperative backpressure is disabled.
/// Disabled mode does not create a byte budget.
///
/// See [`MemoryMode`] for details on the behavior of each mode.
///
/// # Errors
Expand Down Expand Up @@ -111,7 +115,30 @@ pub fn initialize_memory_bounds(
_ => MemoryLimiter::noop(),
};

Ok(limiter)
let budget = if configuration.memory_mode == MemoryMode::Disabled {
None
} else {
match (configuration.memory_limit, CgroupMemory::detect()) {
(Some(limit), Some(cgroup)) => Some(
ByteBudget::for_process_and_cgroup_memory_limits(limit.as_u64() as usize, cgroup)
.ok_or_else(|| generic_error!("Process and cgroup memory usage cannot be monitored."))?,
),
(None, Some(cgroup)) => Some(
ByteBudget::for_memory_limit(cgroup.limit(), move || cgroup.current()).ok_or_else(|| {
generic_error!("Cgroup memory usage cannot be monitored for byte-budget admission.")
})?,
),
(_, None) => memory_limit
.map(|limit| {
ByteBudget::for_process_memory_limit(limit.as_u64() as usize).ok_or_else(|| {
generic_error!("Process memory usage cannot be monitored for byte-budget admission.")
})
})
.transpose()?,
}
};

Ok(limiter.with_byte_budget(budget))
}

fn verify_bounds_for_mode(
Expand Down Expand Up @@ -433,11 +460,15 @@ mod tests {
fn disabled_memory_mode_skips_bounds_verification() {
let registry = registry_with_firm_bound(64 * 1024 * 1024);

initialize_memory_bounds(
let limiter = initialize_memory_bounds(
config_with_limit(ByteSize::b(1024), MemoryMode::Disabled),
registry.root(),
)
.expect("disabled mode should not verify bounds");
assert!(
limiter.byte_budget().is_none(),
"disabled mode leaves admission unbounded even with an explicit limit"
);
}

#[test]
Expand All @@ -459,11 +490,15 @@ mod tests {
fn permissive_memory_mode_tolerates_bounds_exceeding_the_limit() {
let registry = registry_with_firm_bound(64 * 1024 * 1024);

initialize_memory_bounds(
let limiter = initialize_memory_bounds(
config_with_limit(ByteSize::b(1024), MemoryMode::Permissive),
registry.root(),
)
.expect("bounds larger than the limit should be non-fatal in permissive mode");
assert!(
limiter.byte_budget().is_some(),
"configured bounding attaches admission without backoff"
);
}

#[test]
Expand Down
Loading