From 348d1cb6719f812e699fedf66108a834fae66d42 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 16 Mar 2023 23:17:46 +0100 Subject: [PATCH] Fix used memory computation on mac and improve available memory computation --- src/apple/system.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/apple/system.rs b/src/apple/system.rs index ae50b13e9..0691a23d2 100644 --- a/src/apple/system.rs +++ b/src/apple/system.rs @@ -81,6 +81,7 @@ pub struct System { process_list: HashMap, mem_total: u64, mem_free: u64, + mem_used: u64, mem_available: u64, swap_total: u64, swap_free: u64, @@ -151,6 +152,7 @@ impl SystemExt for System { mem_total: 0, mem_free: 0, mem_available: 0, + mem_used: 0, swap_total: 0, swap_free: 0, global_cpu: Cpu::new( @@ -224,6 +226,13 @@ impl SystemExt for System { // */ self.mem_available = u64::from(stat.free_count) .saturating_add(u64::from(stat.inactive_count)) + .saturating_add(u64::from(stat.purgeable_count)) + .saturating_sub(u64::from(stat.compressor_page_count)) + .saturating_mul(self.page_size_kb); + self.mem_used = u64::from(stat.active_count) + .saturating_add(u64::from(stat.wire_count)) + .saturating_add(u64::from(stat.compressor_page_count)) + .saturating_add(u64::from(stat.speculative_count)) .saturating_mul(self.page_size_kb); self.mem_free = u64::from(stat.free_count) .saturating_sub(u64::from(stat.speculative_count)) @@ -420,7 +429,7 @@ impl SystemExt for System { } fn used_memory(&self) -> u64 { - self.mem_total - self.mem_free + self.mem_used } fn total_swap(&self) -> u64 {