Struct MemController

Source
pub struct MemController { /* private fields */ }
Expand description

A controller that allows controlling the memory subsystem of a Cgroup.

In essence, using the memory controller, the user can gather statistics about the memory usage of the tasks in the control group. Additonally, one can also set powerful limits on their memory usage.

Implementations§

Source§

impl MemController

Source

pub fn new(root: PathBuf, v2: bool) -> Self

Contructs a new MemController with root serving as the root of the control group.

Source

pub fn set_mem(&self, m: SetMemory) -> Result<()>

Source

pub fn get_mem(&self) -> Result<SetMemory>

Source

pub fn memory_stat(&self) -> Memory

Gathers overall statistics (and the current state of) about the memory usage of the control group’s tasks.

See the individual fields for more explanation, and as always, remember to consult the kernel Documentation and/or sources.

Source

pub fn kmem_stat(&self) -> Kmem

Gathers information about the kernel memory usage of the control group’s tasks.

Source

pub fn kmem_tcp_stat(&self) -> Tcp

Gathers information about the control group’s kernel memory usage where said memory is TCP-related.

Source

pub fn memswap_v2(&self) -> MemSwap

Source

pub fn memswap(&self) -> MemSwap

Gathers information about the memory usage of the control group including the swap usage (if any).

Source

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

Reset the fail counter

Source

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

Reset the kernel memory fail counter

Source

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

Reset the TCP related fail counter

Source

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

Reset the memory+swap fail counter

Source

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

Reset the max memory usage recorded

Source

pub fn set_limit(&self, limit: i64) -> Result<()>

Set the memory usage limit of the control group, in bytes.

Source

pub fn set_kmem_limit(&self, limit: i64) -> Result<()>

Set the kernel memory limit of the control group, in bytes.

Source

pub fn set_memswap_limit(&self, limit: i64) -> Result<()>

Set the memory+swap limit of the control group, in bytes.

Source

pub fn set_tcp_limit(&self, limit: i64) -> Result<()>

Set how much kernel memory can be used for TCP-related buffers by the control group.

Source

pub fn set_soft_limit(&self, limit: i64) -> Result<()>

Set the soft limit of the control group, in bytes.

This limit is enforced when the system is nearing OOM conditions. Contrast this with the hard limit, which is always enforced.

Source

pub fn set_swappiness(&self, swp: u64) -> Result<()>

Set how likely the kernel is to swap out parts of the address space used by the control group.

Note that a value of zero does not imply that the process will not be swapped out.

Source

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

Source

pub fn register_oom_event(&self, key: &str) -> Result<Receiver<String>>

Trait Implementations§

Source§

impl Clone for MemController

Source§

fn clone(&self) -> MemController

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for MemController

Source§

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

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

impl<'a> From<&'a Subsystem> for &'a MemController

Source§

fn from(sub: &'a Subsystem) -> &'a MemController

Converts to this type from the input type.

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> Controller for T
where T: ControllerInternal,

Source§

fn apply(&self, res: &Resources) -> Result<(), Error>

Apply a set of resources to the Controller, invoking its internal functions to pass the kernel the information.

Source§

fn create(&self)

Create this controller

Source§

fn set_notify_on_release(&self, enable: bool) -> Result<(), Error>

Set notify_on_release

Source§

fn set_release_agent(&self, path: &str) -> Result<(), Error>

Set release_agent

Source§

fn exists(&self) -> bool

Does this controller already exist?

Source§

fn delete(&self) -> Result<(), Error>

Delete the controller.

Source§

fn add_task(&self, pid: &CgroupPid) -> Result<(), Error>

Attach a task to this controller.

Source§

fn add_task_by_tgid(&self, pid: &CgroupPid) -> Result<(), Error>

Attach a task to this controller by thread group id.

Source§

fn procs(&self) -> Vec<CgroupPid>

Get the list of procs that this controller has.

Source§

fn tasks(&self) -> Vec<CgroupPid>

Get the list of tasks that this controller has.

Source§

fn set_cgroup_type(&self, cgroup_type: &str) -> Result<(), Error>

set cgroup.type

Source§

fn get_cgroup_type(&self) -> Result<String, Error>

get cgroup.type

Source§

fn control_type(&self) -> Controllers

Source§

fn path(&self) -> &Path

The file system path to the controller.
Source§

fn v2(&self) -> bool

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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.