Skip to main content

ResourceLimits

Struct ResourceLimits 

Source
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: u64

CPU 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

Source

pub fn unlimited() -> Self

Create unlimited resource limits

Source

pub fn parse_memory(s: &str) -> Result<u64>

Parse memory limit from string (e.g., “512M”, “1G”)

Source

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.

Source

pub fn with_swap_enabled(self) -> Self

Enable swap (removes the default swap=0 restriction)

Source

pub fn with_cpu_cores(self, cores: f64) -> Result<Self>

Set CPU limit in cores (e.g., 2.5 cores)

Source

pub fn with_pids(self, max_pids: u64) -> Result<Self>

Set maximum number of PIDs

Source

pub fn with_cpu_weight(self, weight: u64) -> Result<Self>

Set CPU scheduling weight (1-10000)

Source

pub fn with_io_limit(self, limit: IoDeviceLimit) -> Self

Add an I/O device limit

Source

pub fn with_memlock(self, limit: &str) -> Result<Self>

Set RLIMIT_MEMLOCK (e.g. “8M” for io_uring ring buffers)

Source

pub fn validate_runtime_sanity(&self) -> Result<()>

Validate invariants required by runtime, cgroup, and OCI limit consumers.

Trait Implementations§

Source§

impl Clone for ResourceLimits

Source§

fn clone(&self) -> ResourceLimits

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ResourceLimits

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ResourceLimits

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more