Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
k-sareen committed Apr 23, 2024
1 parent 964ca01 commit 2167824
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/util/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ pub fn handle_mmap_error<VM: VMBinding>(error: Error, tls: VMThread) -> ! {
match error.kind() {
// From Rust nightly 2021-05-12, we started to see Rust added this ErrorKind.
ErrorKind::OutOfMemory => {
#[cfg(target_os = "linux")]
info!("{}", get_process_memory_maps());
eprintln!("{}", get_process_memory_maps());
// Signal `MmapOutOfMemory`. Expect the VM to abort immediately.
trace!("Signal MmapOutOfMemory!");
VM::VMCollection::out_of_memory(tls, AllocationError::MmapOutOfMemory);
Expand All @@ -161,8 +160,7 @@ pub fn handle_mmap_error<VM: VMBinding>(error: Error, tls: VMThread) -> ! {
if let Some(os_errno) = error.raw_os_error() {
// If it is OOM, we invoke out_of_memory() through the VM interface.
if os_errno == libc::ENOMEM {
#[cfg(target_os = "linux")]
info!("{}", get_process_memory_maps());
eprintln!("{}", get_process_memory_maps());
// Signal `MmapOutOfMemory`. Expect the VM to abort immediately.
trace!("Signal MmapOutOfMemory!");
VM::VMCollection::out_of_memory(tls, AllocationError::MmapOutOfMemory);
Expand All @@ -171,8 +169,7 @@ pub fn handle_mmap_error<VM: VMBinding>(error: Error, tls: VMThread) -> ! {
}
}
ErrorKind::AlreadyExists => {
#[cfg(target_os = "linux")]
info!("{}", get_process_memory_maps());
eprintln!("{}", get_process_memory_maps());
panic!("Failed to mmap, the address is already mapped. Should MMTk quarantine the address range first?");
}
_ => {}
Expand Down Expand Up @@ -237,7 +234,7 @@ fn wrap_libc_call<T: PartialEq>(f: &dyn Fn() -> T, expect: T) -> Result<()> {
/// Get the memory maps for the process. The returned string is a multi-line string.
/// This is only meant to be used for debugging. For example, log process memory maps after detecting a clash.
/// If we would need to parsable memory maps, I would suggest using a library instead which saves us the trouble to deal with portability.
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn get_process_memory_maps() -> String {
// print map
use std::fs::File;
Expand All @@ -248,6 +245,11 @@ pub fn get_process_memory_maps() -> String {
data
}

#[cfg(not(any(target_os = "linux", target_os = "android")))]
pub fn get_process_memory_maps() -> String {
"(process map unavailable)".to_string()
}

/// Returns the total physical memory for the system in bytes.
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
Expand Down

0 comments on commit 2167824

Please sign in to comment.