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.
This commit is contained in:
Eric Coissac
2026-05-19 11:35:25 +02:00
parent 8c16b79983
commit 6e2a4c977b
+6 -10
View File
@@ -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",