mirror of
https://github.com/mii443/izoli.git
synced 2025-08-22 16:05:40 +00:00
add memory.max
This commit is contained in:
@ -29,6 +29,7 @@ fn main() {
|
||||
max: CGroupLimitValue::Max,
|
||||
period: 100000,
|
||||
}),
|
||||
memory_max: Some(CGroupLimitValue::Value(1024 * 1024 * 2)),
|
||||
..Default::default()
|
||||
}),
|
||||
new_net: true,
|
||||
|
@ -53,6 +53,11 @@ impl CGroup {
|
||||
self.set_cpu_max(cpu_max)?;
|
||||
}
|
||||
|
||||
if let Some(memory_max) = &option.memory_max {
|
||||
info!("setting memory.max");
|
||||
self.set_memory_max(memory_max)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -204,6 +209,25 @@ impl CGroup {
|
||||
self.write("cpu.max", &to_write)
|
||||
}
|
||||
|
||||
// memory read
|
||||
|
||||
pub fn get_memory_max(&self) -> Result<CGroupLimitValue<u32>, std::io::Error> {
|
||||
let max = self.read("memory.max")?;
|
||||
|
||||
Ok(CGroupLimitValue::from_str(&max).unwrap())
|
||||
}
|
||||
|
||||
// memory write
|
||||
|
||||
pub fn set_memory_max(
|
||||
&self,
|
||||
memory_limit: &CGroupLimitValue<u32>,
|
||||
) -> Result<(), std::io::Error> {
|
||||
let to_write = memory_limit.to_string();
|
||||
|
||||
self.write("memory.max", &to_write)
|
||||
}
|
||||
|
||||
fn write_value<T>(&self, name: &str, value: T) -> Result<(), std::io::Error>
|
||||
where
|
||||
T: fmt::Display,
|
||||
|
@ -1,6 +1,7 @@
|
||||
use super::cpu_limit::CpuLimit;
|
||||
use super::{cpu_limit::CpuLimit, limit_value::CGroupLimitValue};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub struct CGroupOption {
|
||||
pub cpu_max: Option<CpuLimit>,
|
||||
pub memory_max: Option<CGroupLimitValue<u32>>,
|
||||
}
|
||||
|
Reference in New Issue
Block a user