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

ffiselect: Set /proc/pid/oom_score_adj=900 for non-PoSt tasks (#329) #349

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
ffiselect: Set /proc/pid/oom_score_adj=900 for non-PoSt tasks (#329)
HiberNuts committed Dec 19, 2024
commit 2e6fb663be8265f80577f0c9cf78c0732bdbde32
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())
}