From 41d3abb88512424abaa819afdc696fd13f174302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Rodrigues=20Miguel?= Date: Fri, 30 Jul 2021 22:12:00 -0300 Subject: [PATCH] Adds `Process::oom_score_adj` --- src/process/mod.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/process/mod.rs b/src/process/mod.rs index 39887b12..9b9b7b6b 100644 --- a/src/process/mod.rs +++ b/src/process/mod.rs @@ -1109,6 +1109,22 @@ impl Process { Ok(from_str!(u32, oom.trim())) } + /// Used to adjust the badness heuristic used to select which + /// process gets killed in out of memory conditions. + /// The badness heuristic assigns a value to each candidate task ranging from 0 + /// (never kill) to 1000 (always kill) to determine which process is targeted. The + /// units are roughly a proportion along that range of allowed memory the process + /// may allocate from based on an estimation of its current memory and swap use. + /// For example, if a task is using all allowed memory, its badness score will be + /// 1000. If it is using half of its allowed memory, its score will be 500. + pub fn oom_score_adj(&self) -> ProcResult { + let path = self.root.join("oom_score_adj"); + let mut file = FileWrapper::open(&path)?; + let mut oom = String::new(); + file.read_to_string(&mut oom)?; + Ok(from_str!(u32, oom.trim())) + } + /// Set process memory information /// /// Much of this data is the same as the data from `stat()` and `status()`