Skip to content

Commit

Permalink
ffiselect: Set /proc/pid/oom_score_adj=900 for non-PoSt tasks (fileco…
Browse files Browse the repository at this point in the history
  • Loading branch information
HiberNuts committed Dec 19, 2024
1 parent b895bac commit 2e6fb66
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/ffiselect/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use crate::utils::oom::set_oom_score_adj;

pub fn spawn_task(task: Task) -> Result<Child, Error> {
let child = Command::new(task.program)
.args(&task.args)
// ... other command setup ...
.spawn()?;

// Set high OOM score for non-PoSt tasks
if !task.is_post_task() {
if let Err(e) = set_oom_score_adj(child.id() as i32, 900) {
log::warn!("Failed to set OOM score adjustment: {}", e);
// Continue execution even if setting OOM score fails
}
}

Ok(child)
}
8 changes: 8 additions & 0 deletions src/utils/oom.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use std::fs;
use std::io;
use std::path::Path;

pub fn set_oom_score_adj(pid: i32, score: i16) -> io::Result<()> {
let path = format!("/proc/{}/oom_score_adj", pid);
fs::write(Path::new(&path), score.to_string())
}

0 comments on commit 2e6fb66

Please sign in to comment.