Support customized attributes for CpuController and MemController

Customized attributes are useful for customized kernels.

Usage:
	let resource = &mut cgroups::Resources::default();
	resource.cpu.attrs.insert("cpu.cfs_init_buffer_us", "10".to_string());
	// apply here

Signed-off-by: Tim Zhang <tim@hyper.sh>
This commit is contained in:
Tim Zhang
2020-11-04 18:03:42 +08:00
parent ca610bb57e
commit 0c18b0855e
3 changed files with 50 additions and 5 deletions

View File

@@ -18,8 +18,8 @@ use crate::error::*;
use crate::{parse_max_value, read_i64_from};
use crate::{
ControllIdentifier, ControllerInternal, Controllers, CpuResources, MaxValue, Resources,
Subsystem,
ControllIdentifier, ControllerInternal, Controllers, CpuResources, CustomizedAttribute,
MaxValue, Resources, Subsystem,
};
/// A controller that allows controlling the `cpu` subsystem of a Cgroup.
@@ -91,6 +91,10 @@ impl ControllerInternal for CpuController {
return Err(Error::new(ErrorKind::Other));
}
res.attrs.iter().for_each(|(k, v)| {
let _ = self.set(k, v);
})
// TODO: rt properties (CONFIG_RT_GROUP_SCHED) are not yet supported
}
@@ -306,6 +310,8 @@ impl CpuController {
}
}
impl CustomizedAttribute for CpuController {}
fn parse_cfs_quota_and_period(mut file: File) -> Result<CFSQuotaAndPeriod> {
let mut content = String::new();
file.read_to_string(&mut content)