Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add support for cpuacct in cgroup v1. #92

Merged
merged 2 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/cgroups/v1/controller_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fmt::Display;

pub enum ControllerType {
Cpu,
CpuAcct,
CpuSet,
Devices,
HugeTlb,
Expand All @@ -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",
Expand All @@ -32,6 +34,7 @@ impl Display for ControllerType {

pub const CONTROLLERS: &[ControllerType] = &[
ControllerType::Cpu,
ControllerType::CpuAcct,
ControllerType::CpuSet,
ControllerType::Devices,
ControllerType::HugeTlb,
Expand Down
21 changes: 21 additions & 0 deletions src/cgroups/v1/cpuacct.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
}
5 changes: 3 additions & 2 deletions src/cgroups/v1/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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)?,
Expand Down
1 change: 1 addition & 0 deletions src/cgroups/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod blkio;
mod controller;
mod controller_type;
mod cpu;
mod cpuacct;
mod cpuset;
mod devices;
mod hugetlb;
Expand Down
6 changes: 5 additions & 1 deletion src/cgroups/v1/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ pub fn get_subsystem_mount_points(subsystem: &str) -> Result<PathBuf> {
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))
}
}