Struct Subsystem

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

Handler of a HugeTLB subsystem.

Implementations§

Source§

impl Subsystem

Source

pub fn size_supported(&self, size: HugepageSize) -> bool

Returns whether the system supports hugepage in size.

Note that this method returns false if the directory of this cgroup is not created yet.

§Example
use std::path::PathBuf;
use controlgroup::v1::{hugetlb::{self, HugepageSize}, Cgroup, CgroupPath, SubsystemKind};

let mut cgroup = hugetlb::Subsystem::new(
    CgroupPath::new(SubsystemKind::HugeTlb, PathBuf::from("students/charlie")));
cgroup.create()?;

let support_2mb = cgroup.size_supported(HugepageSize::Mb2);
let support_1gb = cgroup.size_supported(HugepageSize::Gb1);
Source

pub fn limit_in_bytes(&self, size: HugepageSize) -> Result<u64>

Reads the limit of hugepage TLB usage in bytes from hugetlb.<hugepage size>.limit_in_bytes file.

See the kernel’s documentation for more information about this field.

§Errors

Returns an error if failed to read and parse hugetlb.<hugepage size>.limit_in_bytes file of this cgroup.

§Examples
use std::path::PathBuf;
use controlgroup::v1::{hugetlb, Cgroup, CgroupPath, SubsystemKind};

let cgroup = hugetlb::Subsystem::new(
    CgroupPath::new(SubsystemKind::HugeTlb, PathBuf::from("students/charlie")));

let limit_in_bytes = cgroup.limit_in_bytes(hugetlb :: HugepageSize :: Mb2)?;
Source

pub fn limit_in_pages(&self, size: HugepageSize) -> Result<u64>

Reads the limit of hugepage TLB usage in bytes in pages. See limit_in_bytes method for more information.

Source

pub fn set_limit(&mut self, size: HugepageSize, limit: Limit) -> Result<()>

Sets a limit of hugepage TLB usage by writing to hugetlb.<hugepage size>.limit_in_bytes file.

See the kernel’s documentation for more information about this field.

§Errors

Returns an error if failed to write to hugetlb.<hugepage size>.limit_in_bytes file of this cgroup.

§Examples
use std::path::PathBuf;
use controlgroup::v1::{hugetlb, Cgroup, CgroupPath, SubsystemKind};

let mut cgroup = hugetlb::Subsystem::new(
    CgroupPath::new(SubsystemKind::HugeTlb, PathBuf::from("students/charlie")));

cgroup.set_limit(hugetlb::HugepageSize::Mb2, hugetlb::Limit::Pages(4))?;
Source

pub fn set_limit_in_bytes( &mut self, size: HugepageSize, bytes: u64, ) -> Result<()>

Sets a limit of hugepage TLB usage in bytes. See set_limit method for more information.

Source

pub fn set_limit_in_pages( &mut self, size: HugepageSize, pages: u64, ) -> Result<()>

Sets a limit of hugepage TLB usage in pages. See set_limit method for more information.

Source

pub fn usage_in_bytes(&self, size: HugepageSize) -> Result<u64>

Reads the current usage of hugepage TLB in bytes from hugetlb.<hugepage size>.usage_in_bytes file.

See the kernel’s documentation for more information about this field.

§Errors

Returns an error if failed to read and parse hugetlb.<hugepage size>.usage_in_bytes file of this cgroup.

§Examples
use std::path::PathBuf;
use controlgroup::v1::{hugetlb, Cgroup, CgroupPath, SubsystemKind};

let cgroup = hugetlb::Subsystem::new(
    CgroupPath::new(SubsystemKind::HugeTlb, PathBuf::from("students/charlie")));

let usage_in_bytes = cgroup.usage_in_bytes(hugetlb :: HugepageSize :: Mb2)?;
Source

pub fn usage_in_pages(&self, size: HugepageSize) -> Result<u64>

Reads the current usage of hugepage TLB in bytes in pages. See usage_in_bytes method for more information.

Source

pub fn max_usage_in_bytes(&self, size: HugepageSize) -> Result<u64>

Reads the maximum recorded usage of hugepage TLB in bytes from hugetlb.<hugepage size>.max_usage_in_bytes file.

See the kernel’s documentation for more information about this field.

§Errors

Returns an error if failed to read and parse hugetlb.<hugepage size>.max_usage_in_bytes file of this cgroup.

§Examples
use std::path::PathBuf;
use controlgroup::v1::{hugetlb, Cgroup, CgroupPath, SubsystemKind};

let cgroup = hugetlb::Subsystem::new(
    CgroupPath::new(SubsystemKind::HugeTlb, PathBuf::from("students/charlie")));

let max_usage_in_bytes = cgroup.max_usage_in_bytes(hugetlb :: HugepageSize :: Mb2)?;
Source

pub fn max_usage_in_pages(&self, size: HugepageSize) -> Result<u64>

Reads the maximum recorded usage of hugepage TLB in bytes in pages. See max_usage_in_bytes method for more information.

Source

pub fn failcnt(&self, size: HugepageSize) -> Result<u64>

Reads the number of allocation failure due to the limit, from hugetlb.<hugepage size>.failcnt file.

See the kernel’s documentation for more information about this field.

§Errors

Returns an error if failed to read and parse hugetlb.<hugepage size>.failcnt file of this cgroup.

§Examples
use std::path::PathBuf;
use controlgroup::v1::{hugetlb, Cgroup, CgroupPath, SubsystemKind};

let cgroup = hugetlb::Subsystem::new(
    CgroupPath::new(SubsystemKind::HugeTlb, PathBuf::from("students/charlie")));

let failcnt = cgroup.failcnt(hugetlb::HugepageSize::Mb2)?;

Trait Implementations§

Source§

impl Cgroup for Subsystem

Source§

fn apply(&mut self, resources: &Resources) -> Result<()>

Applies resources.hugetlb.limits if it is not empty.

Source§

fn new(path: CgroupPath) -> Self

Defines a new cgroup with a path. Read more
Source§

fn subsystem(&self) -> SubsystemKind

Returns the subsystem to which this cgroup belongs. Read more
Source§

fn path(&self) -> PathBuf

Returns the absolute path to this cgroup. Read more
Source§

fn is_root(&self) -> bool

Returns whether this cgroup is the root cgroup of a subsystem. Read more
Source§

fn root_cgroup(&self) -> Box<Self>

Returns the definition of the root cgroup for the subsystem of this cgroup. Read more
Source§

fn create(&mut self) -> Result<()>

Creates a new directory for this cgroup. Read more
Source§

fn delete(&mut self) -> Result<()>

Deletes the directory of this cgroup. Read more
Source§

fn tasks(&self) -> Result<Vec<Pid>>

Reads a list of tasks attached to this cgroup, from tasks file. The resulting tasks are represented by their thread IDs. Read more
Source§

fn add_task(&mut self, pid: impl Into<Pid>) -> Result<()>

Attaches a task to this cgroup by writing a thread ID to tasks file. Read more
Source§

fn remove_task(&mut self, pid: impl Into<Pid>) -> Result<()>

Removes a task from this cgroup by writing a thread ID to tasks file of the root cgroup. Read more
Source§

fn procs(&self) -> Result<Vec<Pid>>

Reads a list of processes attached to this cgroup, from cgroup.procs file. The resulting tasks are represented by their PIDs. Read more
Source§

fn add_proc(&mut self, pid: impl Into<Pid>) -> Result<()>

Attaches a process to this cgroup, with all threads in the same thread group at once, by writing a PID to cgroup.procs file. Read more
Source§

fn remove_proc(&mut self, pid: impl Into<Pid>) -> Result<()>

Removes a process from this cgroup, with all threads in the same thread group at once, by writing a PID to cgroup.procs file of the root cgroup. Read more
Source§

fn notify_on_release(&self) -> Result<bool>

Reads whether the system executes the executable written in release_agent file when this cgroup no longer has any task, from notify_on_release file. Read more
Source§

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

Sets whether the system executes the executable written in release_agent file when this cgroup no longer has any task, by writing to notify_on_release file. Read more
Source§

fn release_agent(&self) -> Result<String>

Reads the command to be executed when “notify on release” is triggered, i.e. this cgroup is emptied of all tasks, from release_agent file. Read more
Source§

fn set_release_agent(&mut self, agent_path: impl AsRef<[u8]>) -> Result<()>

Sets a command to be executed when “notify on release” is triggered, i.e. this cgroup is emptied of all tasks, by writing to release_agent file. Read more
Source§

fn sane_behavior(&self) -> Result<bool>

Reads whether the subsystem of this cgroup is forced to follow “sane behavior”, from cgroup.sane_behavior file. Read more
Source§

fn file_exists(&self, name: &str) -> bool

Returns whether a file with the given name exists in this cgroup. Read more
Source§

fn open_file_read(&self, name: &str) -> Result<File>

Low-level API that opens a file with read access. Read more
Source§

fn open_file_write(&mut self, name: &str) -> Result<File>

Low-level API that opens a file with write access. Read more
Source§

impl Debug for Subsystem

Source§

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

Formats the value using the given formatter. 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> 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, 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.