Skip to content

Commit

Permalink
Merge pull request #16 from tsturzl/main
Browse files Browse the repository at this point in the history
add memory cgroup controller
  • Loading branch information
utam0k authored May 24, 2021
2 parents 3f13a58 + b808f30 commit 910514e
Show file tree
Hide file tree
Showing 7 changed files with 358 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
expect_err_num=8
act_err_num=0
cd $(go env GOPATH)/src/github.com/opencontainers/runtime-tools
test_cases=("default/default.t" "linux_cgroups_devices/linux_cgroups_devices.t" "linux_cgroups_hugetlb/linux_cgroups_hugetlb.t" "linux_cgroups_pids/linux_cgroups_pids.t")
test_cases=("default/default.t" "linux_cgroups_devices/linux_cgroups_devices.t" "linux_cgroups_hugetlb/linux_cgroups_hugetlb.t" "linux_cgroups_pids/linux_cgroups_pids.t", "linux_cgroups_memory/linux_cgroups_memory.t")
for case in "${test_cases[@]}"; do
title="Running $case"
if [ 0 -ne $(sudo RUNTIME=$GITHUB_WORKSPACE/target/x86_64-unknown-linux-gnu/debug/youki ./validation/$case | grep "not ok" | wc -l) ]; then
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
/target
.vagrant/

tags
tags.lock
tags.temp
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ mio = { version = "0.7", features = ["os-ext", "os-poll"] }
chrono = "0.4"
once_cell = "1.6.0"
futures = { version = "0.3", features = ["thread-pool"] }
regex = "1.5"
regex = "1.5"
2 changes: 2 additions & 0 deletions src/cgroups/controller_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub enum ControllerType {
Devices,
HugeTlb,
Pids,
Memory,
}

impl ToString for ControllerType {
Expand All @@ -12,6 +13,7 @@ impl ToString for ControllerType {
Self::Devices => "devices".into(),
Self::HugeTlb => "hugetlb".into(),
Self::Pids => "pids".into(),
Self::Memory => "memory".into(),
}
}
}
13 changes: 6 additions & 7 deletions src/cgroups/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ use procfs::process::Process;

use crate::{cgroups::ControllerType, spec::LinuxResources, utils::PathBufExt};

use super::{devices::Devices, hugetlb::Hugetlb, pids::Pids, Controller};
use super::{devices::Devices, hugetlb::Hugetlb, memory::Memory, pids::Pids, Controller};

const CONTROLLERS: &[ControllerType] = &[
ControllerType::Devices,
ControllerType::HugeTlb,
ControllerType::Memory,
ControllerType::Pids,
];

pub struct Manager {
subsystems: HashMap<String, PathBuf>,
}
Expand All @@ -36,6 +38,7 @@ impl Manager {
match subsys.0.as_str() {
"devices" => Devices::apply(linux_resources, &subsys.1, pid)?,
"hugetlb" => Hugetlb::apply(linux_resources, &subsys.1, pid)?,
"memory" => Memory::apply(linux_resources, &subsys.1, pid)?,
"pids" => Pids::apply(linux_resources, &subsys.1, pid)?,
_ => continue,
}
Expand All @@ -59,17 +62,13 @@ impl Manager {
let mount = Process::myself()?
.mountinfo()?
.into_iter()
.filter(|m| m.fs_type == "cgroup" && m.mount_point.ends_with(subsystem))
.collect::<Vec<_>>()
.pop()
.find(|m| m.fs_type == "cgroup" && m.mount_point.ends_with(subsystem))
.unwrap();

let cgroup = Process::myself()?
.cgroups()?
.into_iter()
.filter(|c| c.controllers.contains(&subsystem.to_owned()))
.collect::<Vec<_>>()
.pop()
.find(|c| c.controllers.contains(&subsystem.to_owned()))
.unwrap();

let p = if cgroup_path.to_string_lossy().into_owned().is_empty() {
Expand Down
Loading

0 comments on commit 910514e

Please sign in to comment.