system_info/unix/posix/
mem.rs

1//! Memory information.
2
3pub use crate::data::mem::SystemMemory;
4
5impl SystemMemory {
6    ///Fetches system information, if not available returns with all members set to 0.
7    pub fn new() -> Self {
8        let (total_count, avail_count, size) = unsafe {
9            let total_count = libc::sysconf(libc::_SC_PHYS_PAGES);
10            let avail_count = libc::sysconf(libc::_SC_AVPHYS_PAGES);
11            let size = libc::sysconf(libc::_SC_PAGE_SIZE);
12            if total_count == -1 || avail_count == -1 || size == -1 {
13                return Self {
14                    total: 0,
15                    avail: 0,
16                }
17            }
18
19            (total_count as u64, avail_count as u64, size as u64)
20        };
21
22        Self {
23            total: total_count.saturating_mul(size),
24            avail: avail_count.saturating_mul(size),
25        }
26    }
27}