diff --git a/procfs-core/src/partitions.rs b/procfs-core/src/partitions.rs index ef297d5..41a6586 100644 --- a/procfs-core/src/partitions.rs +++ b/procfs-core/src/partitions.rs @@ -18,7 +18,7 @@ pub struct PartitionEntry { /// Number of 1024 byte blocks pub blocks: u64, /// Device name - pub name: String + pub name: String, } impl super::FromBufRead for Vec { @@ -37,9 +37,9 @@ impl super::FromBufRead for Vec { let partition_entry = PartitionEntry { major, - minor, - blocks, - name + minor, + blocks, + name, }; vec.push(partition_entry); @@ -49,7 +49,6 @@ impl super::FromBufRead for Vec { } } - #[test] fn test_partitions() { use crate::FromBufRead; diff --git a/procfs/src/process/mod.rs b/procfs/src/process/mod.rs index 111aed2..d05ddf7 100644 --- a/procfs/src/process/mod.rs +++ b/procfs/src/process/mod.rs @@ -587,12 +587,29 @@ impl Process { /// A higher score means that the process is more likely to be selected by the OOM-killer. /// The basis for this score is the amount of memory used by the process, plus other factors. /// + /// Values range from 0 (never kill) to 1000 (always kill) inclusive. + /// /// (Since linux 2.6.11) - pub fn oom_score(&self) -> ProcResult { + pub fn oom_score(&self) -> ProcResult { let mut file = FileWrapper::open_at(&self.root, &self.fd, "oom_score")?; let mut oom = String::new(); file.read_to_string(&mut oom)?; - Ok(from_str!(u32, oom.trim())) + Ok(from_str!(u16, oom.trim())) + } + + /// Adjust score value is added to the oom score before choosing processes to kill. + /// + /// Values range from -1000 (never kill) to 1000 (always kill) inclusive. + pub fn oom_score_adj(&self) -> ProcResult { + let mut file = FileWrapper::open_at(&self.root, &self.fd, "oom_score_adj")?; + let mut oom = String::new(); + file.read_to_string(&mut oom)?; + Ok(from_str!(i16, oom.trim())) + } + + pub fn set_oom_score_adj(&self, new_oom_score_adj: i16) -> ProcResult<()> { + let path = self.root.join("oom_score_adj"); + write_value(path, new_oom_score_adj) } /// Set process memory information diff --git a/procfs/src/process/tests.rs b/procfs/src/process/tests.rs index c31181b..ec7e4e3 100644 --- a/procfs/src/process/tests.rs +++ b/procfs/src/process/tests.rs @@ -174,6 +174,10 @@ fn test_all() { check_unwrap(&prc, prc.mountinfo()); check_unwrap(&prc, prc.mountstats()); check_unwrap(&prc, prc.oom_score()); + if let Some(oom_score_adj) = check_unwrap(&prc, prc.oom_score_adj()) { + assert!(oom_score_adj >= -1000 && oom_score_adj <= 1000); + check_unwrap(&prc, prc.set_oom_score_adj(oom_score_adj)); + } if let Some(tasks) = check_unwrap(&prc, prc.tasks()) { for task in tasks { diff --git a/support.md b/support.md index 69e7c19..3744633 100644 --- a/support.md +++ b/support.md @@ -36,7 +36,7 @@ This is an approximate list of all the files under the `/proc` mount, and an ind * [ ] `/proc/[pid]/numa_maps` * [ ] `/proc/[pid]/oom_adj` * [x] `/proc/[pid]/oom_score` - * [ ] `/proc/[pid]/oom_score_adj` + * [x] `/proc/[pid]/oom_score_adj` * [ ] `/proc/[pid]/pagemap` * [ ] `/proc/[pid]/personality` * [x] `/proc/[pid]/root`