-
Notifications
You must be signed in to change notification settings - Fork 346
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
Seperate adding tasks to cgroups and applying resource restrictions #111
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
use std::{ | ||
fs::{self}, | ||
path::Path, | ||
}; | ||
|
||
use crate::cgroups::{ | ||
common::{self, CGROUP_PROCS}, | ||
v1::Controller, | ||
}; | ||
use std::path::Path; | ||
|
||
use crate::cgroups::{common, v1::Controller}; | ||
use anyhow::Result; | ||
use oci_spec::{LinuxBlockIo, LinuxResources}; | ||
|
||
const CGROUP_BLKIO_THROTTLE_READ_BPS: &str = "blkio.throttle.read_bps_device"; | ||
|
@@ -17,25 +12,19 @@ const CGROUP_BLKIO_THROTTLE_WRITE_IOPS: &str = "blkio.throttle.write_iops_device | |
pub struct Blkio {} | ||
|
||
impl Controller for Blkio { | ||
fn apply( | ||
linux_resources: &LinuxResources, | ||
cgroup_root: &Path, | ||
pid: nix::unistd::Pid, | ||
) -> anyhow::Result<()> { | ||
fn apply(linux_resources: &LinuxResources, cgroup_root: &Path) -> Result<()> { | ||
log::debug!("Apply blkio cgroup config"); | ||
fs::create_dir_all(cgroup_root)?; | ||
|
||
if let Some(blkio) = &linux_resources.block_io { | ||
Self::apply(cgroup_root, blkio)?; | ||
} | ||
|
||
common::write_cgroup_file(cgroup_root.join(CGROUP_PROCS), pid)?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl Blkio { | ||
fn apply(root_path: &Path, blkio: &LinuxBlockIo) -> anyhow::Result<()> { | ||
fn apply(root_path: &Path, blkio: &LinuxBlockIo) -> Result<()> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
for trbd in &blkio.blkio_throttle_read_bps_device { | ||
common::write_cgroup_file_str( | ||
&root_path.join(CGROUP_BLKIO_THROTTLE_READ_BPS), | ||
|
@@ -70,6 +59,8 @@ impl Blkio { | |
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::fs; | ||
|
||
use super::*; | ||
use crate::cgroups::test::setup; | ||
use oci_spec::{LinuxBlockIo, LinuxThrottleDevice}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
use std::path::Path; | ||
use std::{fs, path::Path}; | ||
|
||
use anyhow::Result; | ||
use nix::unistd::Pid; | ||
|
||
use oci_spec::LinuxResources; | ||
|
||
use crate::cgroups::common::{self, CGROUP_PROCS}; | ||
|
||
pub trait Controller { | ||
fn apply(linux_resources: &LinuxResources, cgroup_root: &Path, pid: Pid) -> Result<()>; | ||
fn add_task(pid: Pid, cgroup_path: &Path) -> Result<()> { | ||
fs::create_dir_all(cgroup_path)?; | ||
common::write_cgroup_file(cgroup_path.join(CGROUP_PROCS), pid)?; | ||
Ok(()) | ||
} | ||
|
||
fn apply(linux_resources: &LinuxResources, cgroup_root: &Path) -> Result<()>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
use std::fmt::Display; | ||
|
||
#[derive(Hash, PartialEq, Eq, Debug, Clone)] | ||
pub enum ControllerType { | ||
Cpu, | ||
CpuAcct, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is slightly out of the scope of this PR, However Could you provide comments on each function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done