Skip to content

Commit

Permalink
Merge pull request #955 from GuillaumeGomez/mac-used-memory
Browse files Browse the repository at this point in the history
Fix used memory computation on mac and improve available memory computation
  • Loading branch information
GuillaumeGomez committed Mar 16, 2023
2 parents cf40e06 + 348d1cb commit f82c205
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/apple/system.rs
Expand Up @@ -81,6 +81,7 @@ pub struct System {
process_list: HashMap<Pid, Process>,
mem_total: u64,
mem_free: u64,
mem_used: u64,
mem_available: u64,
swap_total: u64,
swap_free: u64,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f82c205

Please sign in to comment.