diff --git a/src/cgroups/v1/controller_type.rs b/src/cgroups/v1/controller_type.rs index 722d1b545..68cb25572 100644 --- a/src/cgroups/v1/controller_type.rs +++ b/src/cgroups/v1/controller_type.rs @@ -2,6 +2,7 @@ use std::fmt::Display; pub enum ControllerType { Cpu, + CpuAcct, CpuSet, Devices, HugeTlb, @@ -16,6 +17,7 @@ impl Display for ControllerType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let print = match *self { Self::Cpu => "cpu", + Self::CpuAcct => "cpuacct", Self::CpuSet => "cpuset", Self::Devices => "devices", Self::HugeTlb => "hugetlb", @@ -32,6 +34,7 @@ impl Display for ControllerType { pub const CONTROLLERS: &[ControllerType] = &[ ControllerType::Cpu, + ControllerType::CpuAcct, ControllerType::CpuSet, ControllerType::Devices, ControllerType::HugeTlb, diff --git a/src/cgroups/v1/cpuacct.rs b/src/cgroups/v1/cpuacct.rs new file mode 100644 index 000000000..3060aebcf --- /dev/null +++ b/src/cgroups/v1/cpuacct.rs @@ -0,0 +1,21 @@ +use std::{fs, path::Path}; + +use anyhow::Result; +use nix::unistd::Pid; +use oci_spec::LinuxResources; + +use crate::cgroups::common::{self, CGROUP_PROCS}; + +use super::Controller; + +pub struct CpuAcct {} + +impl Controller for CpuAcct { + fn apply(_linux_resources: &LinuxResources, cgroup_path: &Path, pid: Pid) -> Result<()> { + log::debug!("Apply cpuacct cgroup config"); + fs::create_dir_all(cgroup_path)?; + + common::write_cgroup_file(cgroup_path.join(CGROUP_PROCS), pid)?; + Ok(()) + } +} diff --git a/src/cgroups/v1/manager.rs b/src/cgroups/v1/manager.rs index 886b065d0..fd5d7a2ea 100644 --- a/src/cgroups/v1/manager.rs +++ b/src/cgroups/v1/manager.rs @@ -8,8 +8,8 @@ use nix::unistd::Pid; use procfs::process::Process; use super::{ - blkio::Blkio, controller_type::CONTROLLERS, cpu::Cpu, cpuset::CpuSet, devices::Devices, - hugetlb::Hugetlb, memory::Memory, network_classifier::NetworkClassifier, + blkio::Blkio, controller_type::CONTROLLERS, cpu::Cpu, cpuacct::CpuAcct, cpuset::CpuSet, + devices::Devices, hugetlb::Hugetlb, memory::Memory, network_classifier::NetworkClassifier, network_priority::NetworkPriority, pids::Pids, util, Controller, }; @@ -61,6 +61,7 @@ impl CgroupManager for Manager { for subsys in &self.subsystems { match subsys.0.as_str() { "cpu" => Cpu::apply(linux_resources, &subsys.1, pid)?, + "cpuacct" => CpuAcct::apply(linux_resources, &subsys.1, pid)?, "cpuset" => CpuSet::apply(linux_resources, &subsys.1, pid)?, "devices" => Devices::apply(linux_resources, &subsys.1, pid)?, "hugetlb" => Hugetlb::apply(linux_resources, &subsys.1, pid)?, diff --git a/src/cgroups/v1/mod.rs b/src/cgroups/v1/mod.rs index 7d9b75b0f..9816dc9f5 100644 --- a/src/cgroups/v1/mod.rs +++ b/src/cgroups/v1/mod.rs @@ -2,6 +2,7 @@ mod blkio; mod controller; mod controller_type; mod cpu; +mod cpuacct; mod cpuset; mod devices; mod hugetlb; diff --git a/src/cgroups/v1/util.rs b/src/cgroups/v1/util.rs index 76236c69f..7a31e28bf 100644 --- a/src/cgroups/v1/util.rs +++ b/src/cgroups/v1/util.rs @@ -40,9 +40,13 @@ pub fn get_subsystem_mount_points(subsystem: &str) -> Result { return m.mount_point.ends_with("cpu,cpuacct") || m.mount_point.ends_with("cpu"); } + if subsystem == "cpuacct" { + return m.mount_point.ends_with("cpu,cpuacct") + || m.mount_point.ends_with("cpuacct"); + } } m.mount_point.ends_with(&subsystem) }) .map(|m| m.mount_point) .ok_or_else(|| anyhow!("could not find mountpoint for {}", subsystem)) -} \ No newline at end of file +}