Skip to main content

CgroupOps

Trait CgroupOps 

Source
pub trait CgroupOps:
    Send
    + Sync
    + 'static {
    // Required methods
    fn id(&self) -> u64;
    fn add_process(&self, thread_group: &ThreadGroup) -> Result<(), Errno>;
    fn new_child(&self, name: &FsStr) -> Result<CgroupHandle, Errno>;
    fn get_children(&self) -> Result<Vec<CgroupHandle>, Errno>;
    fn get_child(&self, name: &FsStr) -> Result<CgroupHandle, Errno>;
    fn remove_child(&self, name: &FsStr) -> Result<CgroupHandle, Errno>;
    fn get_pids(&self, kernel: &Kernel) -> Vec<pid_t> ⓘ;
    fn kill(&self);
    fn is_populated(&self) -> bool;
    fn freezer(&self) -> Option<&dyn FreezerOps>;
    fn cpuset(&self) -> Option<&dyn CpusetOps>;

    // Provided method
    fn add_task(&self, task: &Task) -> Result<(), Errno> { ... }
}
Expand description

Common operations of all cgroups.

Required Methods§

Source

fn id(&self) -> u64

Returns the unique ID of the cgroup. ID of root cgroup is 0.

Source

fn add_process(&self, thread_group: &ThreadGroup) -> Result<(), Errno>

Add a process to a cgroup. Errors if the cgroup has been deleted.

Source

fn new_child(&self, name: &FsStr) -> Result<CgroupHandle, Errno>

Create a new sub-cgroup as a child of this cgroup. Errors if the cgroup is deleted, or a child with name already exists.

Source

fn get_children(&self) -> Result<Vec<CgroupHandle>, Errno>

Gets all children of this cgroup.

Source

fn get_child(&self, name: &FsStr) -> Result<CgroupHandle, Errno>

Gets the child with name, errors if not found.

Source

fn remove_child(&self, name: &FsStr) -> Result<CgroupHandle, Errno>

Remove a child from this cgroup and return it, if found. Errors if cgroup is deleted, or a child with name is not found.

Source

fn get_pids(&self, kernel: &Kernel) -> Vec<pid_t> ⓘ

Return all pids that belong to this cgroup.

Source

fn kill(&self)

Kills all processes in the cgroup and its descendants.

Source

fn is_populated(&self) -> bool

Whether the cgroup or any of its descendants have any processes.

Source

fn freezer(&self) -> Option<&dyn FreezerOps>

Returns freezer ops if freezer controller is supported.

Source

fn cpuset(&self) -> Option<&dyn CpusetOps>

Returns cpuset ops if cpuset controller is supported.

Provided Methods§

Source

fn add_task(&self, task: &Task) -> Result<(), Errno>

Add a single task (thread) to a cgroup via the cgroup v1 tasks interface.

Current semantics and limitations (see https://fxbug.dev/401298305):

  • Cgroup membership (CgroupPidTable and CgroupState::processes) is currently tracked per ThreadGroup (keyed by the thread-group leader) rather than per thread.
  • In hierarchies with active cpuset tracking, add_task updates Task::cpuset_path and the scheduler role only for task (preserving per-thread cpuset_path placements of other threads in the group). If task is the thread-group leader, it also updates the thread group’s membership entry in the hierarchy.
  • In hierarchies without cpuset tracking (e.g. freezer or named hierarchies), add_task falls back to add_process(task.thread_group()), migrating the entire thread group.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§