Skip to content

Commit

Permalink
Use sysinfo instead of sys-info-rs (#827)
Browse files Browse the repository at this point in the history
  • Loading branch information
k-sareen authored May 22, 2023
1 parent 12e800a commit 440b57c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ spin = "0.9.5"
static_assertions = "1.1.0"
strum = "0.24"
strum_macros = "0.24"
sys-info = "0.9"
sysinfo = "0.29"

[dev-dependencies]
paste = "1.0.8"
Expand Down
19 changes: 8 additions & 11 deletions src/util/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::util::Address;
use crate::vm::{Collection, VMBinding};
use libc::{PROT_EXEC, PROT_NONE, PROT_READ, PROT_WRITE};
use std::io::{Error, Result};
use sysinfo::{System, SystemExt};

pub fn result_is_mapped(result: Result<()>) -> bool {
match result {
Expand Down Expand Up @@ -192,17 +193,13 @@ pub fn get_process_memory_maps() -> String {
}

/// Returns the total physical memory for the system in bytes.
pub(crate) fn get_system_total_memory() -> usize {
match sys_info::mem_info() {
Ok(mem_info) => mem_info.total as usize,
Err(e) => {
warn!(
"Failed to get sys_info::mem_info: {:?}. Return 1G in get_system_total_memory()",
e
);
1024 * 1024 * 1024
}
}
pub(crate) fn get_system_total_memory() -> u64 {
// TODO: Note that if we want to get system info somewhere else in the future, we should
// refactor this instance into some global struct. sysinfo recommends sharing one instance of
// `System` instead of making multiple instances.
// See https://docs.rs/sysinfo/0.29.0/sysinfo/index.html#usage for more info
let sys = System::new_all();
sys.total_memory()
}

#[cfg(test)]
Expand Down

0 comments on commit 440b57c

Please sign in to comment.