mirror of
https://github.com/kata-containers/cgroups-rs.git
synced 2026-08-05 02:13:23 +00:00
@@ -8,7 +8,6 @@
|
||||
//!
|
||||
//! Currently, we only support the cgroupv1 hierarchy, but in the future we will add support for
|
||||
//! the Unified Hierarchy.
|
||||
use nix::sys::statfs;
|
||||
|
||||
use std::fs::{self, File};
|
||||
use std::io::BufRead;
|
||||
@@ -220,6 +219,8 @@ pub const UNIFIED_MOUNTPOINT: &'static str = "/sys/fs/cgroup";
|
||||
|
||||
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
|
||||
pub fn is_cgroup2_unified_mode() -> bool {
|
||||
use nix::sys::statfs;
|
||||
|
||||
let path = Path::new(UNIFIED_MOUNTPOINT);
|
||||
let fs_stat = statfs::statfs(path);
|
||||
if fs_stat.is_err() {
|
||||
|
||||
@@ -619,7 +619,7 @@ impl Subsystem {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_controller(&self) -> &dyn Controller {
|
||||
pub fn to_controller(&self) -> &dyn Controller {
|
||||
match self {
|
||||
Subsystem::Pid(cont) => cont,
|
||||
Subsystem::Mem(cont) => cont,
|
||||
@@ -638,7 +638,7 @@ impl Subsystem {
|
||||
}
|
||||
}
|
||||
|
||||
fn controller_name(&self) -> String {
|
||||
pub fn controller_name(&self) -> String {
|
||||
self.to_controller().control_type().to_string()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -733,6 +733,15 @@ impl MemController {
|
||||
})
|
||||
}
|
||||
|
||||
/// Reset the max memory usage recorded
|
||||
pub fn reset_max_usage(&self) -> Result<()> {
|
||||
self.open_path("memory.max_usage_in_bytes", true)
|
||||
.and_then(|mut file| {
|
||||
file.write_all("0".to_string().as_ref())
|
||||
.map_err(|e| Error::with_cause(WriteFailed, e))
|
||||
})
|
||||
}
|
||||
|
||||
/// Set the memory usage limit of the control group, in bytes.
|
||||
pub fn set_limit(&self, limit: i64) -> Result<()> {
|
||||
let mut file = "memory.limit_in_bytes";
|
||||
|
||||
Reference in New Issue
Block a user