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

fix child process mem #706

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions rasp/librasp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ version-compare = "0.0.10"
coarsetime = "0.1"
wait-timeout = "0.2.0"
lazy_static = "1.4.0"
cgroups-rs = "0.2.6"

# plugins
plugins = { path = "../../plugins/lib/rust"}
Expand Down
24 changes: 22 additions & 2 deletions rasp/librasp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,28 @@ pub mod async_command {
use anyhow::{anyhow, Result};
use libc::{kill, SIGKILL};
use log::*;

use cgroups_rs::{self, cgroup_builder::CgroupBuilder, CgroupPid, Controller};
use crate::comm::Control;

pub fn set_child_cgroup(pid: i32) -> Result<()> {
let hier = cgroups_rs::hierarchies::auto();
let child_cg = CgroupBuilder::new("rasp_child_cgroup")
.memory()
.memory_hard_limit(1024 * 1024 * 200)
.done()
.cpu()
.quota(1000 * 10).done()
.build(hier);
// start


let mems: &cgroups_rs::memory::MemController = child_cg.controller_of().unwrap();
mems.add_task(&CgroupPid::from(pid as u64))?;
let cpus: &cgroups_rs::cpu::CpuController = child_cg.controller_of().unwrap();
cpus.add_task(&CgroupPid::from(pid as u64))?;
return Ok(());
}

pub fn run_async_process(command: &mut Command) -> Result<(ExitStatus, String, String)> {
// start
let mut child = match command
Expand All @@ -37,6 +56,7 @@ pub mod async_command {
}
};
let pid = child.id();
set_child_cgroup(pid as i32)?;
let (stdout, stderr) = (child.stdout.take(), child.stderr.take());
let child_ctrl = Control::new();
let mut wait_child_ctrl = child_ctrl.clone();
Expand All @@ -53,7 +73,7 @@ pub mod async_command {
return Ok(status);
}
Ok(None) => {
sleep(Duration::from_secs(1));
// sleep(Duration::from_secs(1));
}
Err(e) => {
warn!("attempting wait failed: {}", e);
Expand Down
2 changes: 1 addition & 1 deletion rasp/librasp/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl RASPManager {
})
}
}
let mut need_write_config = true;
let mut need_write_config = false;
for m in messages.iter() {
if m.message_type >= 12 && m.message_type <= 14 {
need_write_config = false;
Expand Down
Loading