From 6e2a4c977b7ed76b7180faa0af060f05498c6095 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Tue, 19 May 2026 11:35:25 +0200 Subject: [PATCH] fix: Replace unreliable memory pressure check with swap indicator The previous `major_faults > 10` check is unreliable on macOS, as it counts file-backed mmap page-ins rather than true memory pressure. This change replaces it with `swaps > 0`, a more accurate cross-platform indicator of RAM exhaustion. The swap diagnosis message is also updated to clarify that the working set exceeds available RAM, and comments are added to document this rationale. --- src/obisys/src/lib.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/obisys/src/lib.rs b/src/obisys/src/lib.rs index d058467..5867eca 100644 --- a/src/obisys/src/lib.rs +++ b/src/obisys/src/lib.rs @@ -117,24 +117,20 @@ fn diagnose(s: &StageStats, n_cores: usize) -> Diagnosis { let cpu_pct = eff * 100.0; let io_ops = s.in_blocks + s.out_blocks; + // swaps > 0 is the only reliable cross-platform indicator of true RAM exhaustion. + // ru_majflt is intentionally excluded: on macOS it counts all file-backed mmap + // page-ins (even from page cache), making it useless as a memory-pressure signal + // for mmap-heavy code. On Linux it is more meaningful, but swaps covers the + // severe case on both platforms. if s.swaps > 0 { return Diagnosis { tag: "swapping", detail: Some(format!( - "swapped {} time(s) — severe memory pressure, consider increasing RAM", + "swapped {} time(s) — working set exceeds available RAM", s.swaps, )), }; } - if s.major_faults > 10 { - return Diagnosis { - tag: "mem pressure", - detail: Some(format!( - "{} major page faults — working set exceeds available RAM", - s.major_faults, - )), - }; - } if eff < 0.3 && io_ops > 100 { return Diagnosis { tag: "disk I/O",