pub struct ResourceLimits {
pub memory_bytes: Option<u64>,
pub memory_high: Option<u64>,
pub memory_swap_max: Option<u64>,
pub cpu_quota_us: Option<u64>,
pub cpu_period_us: u64,
pub cpu_weight: Option<u64>,
pub pids_max: Option<u64>,
pub io_limits: Vec<IoDeviceLimit>,
pub memlock_bytes: Option<u64>,
}Expand description
Resource limits configuration
Fields§
§memory_bytes: Option<u64>Memory limit in bytes (None = unlimited)
memory_high: Option<u64>Memory soft limit in bytes (auto-set to 90% of memory_bytes)
memory_swap_max: Option<u64>Swap limit in bytes (Some(0) = disable swap)
cpu_quota_us: Option<u64>CPU quota in microseconds per period
cpu_period_us: u64CPU period in microseconds (default: 100000 = 100ms)
cpu_weight: Option<u64>CPU scheduling weight (1-10000)
pids_max: Option<u64>Maximum number of PIDs (None = unlimited)
io_limits: Vec<IoDeviceLimit>Per-device I/O limits
memlock_bytes: Option<u64>RLIMIT_MEMLOCK in bytes (None = use default 64KB). io_uring requires a larger limit (e.g. 8M) for ring buffers.
Implementations§
Source§impl ResourceLimits
impl ResourceLimits
Sourcepub fn parse_memory(s: &str) -> Result<u64>
pub fn parse_memory(s: &str) -> Result<u64>
Parse memory limit from string (e.g., “512M”, “1G”)
Sourcepub fn with_memory(self, limit: &str) -> Result<Self>
pub fn with_memory(self, limit: &str) -> Result<Self>
Set memory limit from string (e.g., “512M”, “1G”)
Automatically sets memory_high to 90% of the hard limit and disables swap (memory_swap_max = 0) unless swap was explicitly enabled.
Sourcepub fn with_swap_enabled(self) -> Self
pub fn with_swap_enabled(self) -> Self
Enable swap (removes the default swap=0 restriction)
Sourcepub fn with_cpu_cores(self, cores: f64) -> Result<Self>
pub fn with_cpu_cores(self, cores: f64) -> Result<Self>
Set CPU limit in cores (e.g., 2.5 cores)
Sourcepub fn with_cpu_weight(self, weight: u64) -> Result<Self>
pub fn with_cpu_weight(self, weight: u64) -> Result<Self>
Set CPU scheduling weight (1-10000)
Sourcepub fn with_io_limit(self, limit: IoDeviceLimit) -> Self
pub fn with_io_limit(self, limit: IoDeviceLimit) -> Self
Add an I/O device limit
Sourcepub fn with_memlock(self, limit: &str) -> Result<Self>
pub fn with_memlock(self, limit: &str) -> Result<Self>
Set RLIMIT_MEMLOCK (e.g. “8M” for io_uring ring buffers)
Trait Implementations§
Source§impl Clone for ResourceLimits
impl Clone for ResourceLimits
Source§fn clone(&self) -> ResourceLimits
fn clone(&self) -> ResourceLimits
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more