Skip to content

Commit

Permalink
Rename MmapAnno to MmapAnnotation
Browse files Browse the repository at this point in the history
  • Loading branch information
wks committed Nov 25, 2024
1 parent b196709 commit de848c4
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/mmtk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<VM: VMBinding> MMTK<VM> {
/// Create an MMTK instance. This is not public. Bindings should use [`MMTKBuilder::build`].
pub(crate) fn new(options: Arc<Options>) -> Self {
// Set the static variable for mmap annotation.
crate::util::memory::MMAP_ANNO.store(*options.mmap_anno, Ordering::SeqCst);
crate::util::memory::MMAP_ANNOTATION.store(*options.mmap_annotation, Ordering::SeqCst);

// Initialize SFT first in case we need to use this in the constructor.
// The first call will initialize SFT map. Other calls will be blocked until SFT map is initialized.
Expand Down
4 changes: 2 additions & 2 deletions src/policy/lockfreeimmortalspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::util::heap::gc_trigger::GCTrigger;
use crate::util::heap::layout::vm_layout::vm_layout;
use crate::util::heap::PageResource;
use crate::util::heap::VMRequest;
use crate::util::memory::MmapAnno;
use crate::util::memory::MmapAnnotation;
use crate::util::memory::MmapStrategy;
use crate::util::metadata::side_metadata::SideMetadataContext;
use crate::util::metadata::side_metadata::SideMetadataSanity;
Expand Down Expand Up @@ -246,7 +246,7 @@ impl<VM: VMBinding> LockFreeImmortalSpace<VM> {
start,
aligned_total_bytes,
strategy,
&MmapAnno::Space {
&MmapAnnotation::Space {
name: space.get_name(),
},
)
Expand Down
2 changes: 1 addition & 1 deletion src/policy/space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub trait Space<VM: VMBinding>: 'static + SFT + Sync + Downcast {
res.start,
res.pages,
self.common().mmap_strategy(),
&memory::MmapAnno::Space {
&memory::MmapAnnotation::Space {
name: self.get_name(),
},
)
Expand Down
6 changes: 3 additions & 3 deletions src/util/heap/layout/byte_map_mmapper.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::mmapper::MapState;
use super::Mmapper;
use crate::util::memory::MmapAnno;
use crate::util::memory::MmapAnnotation;
use crate::util::Address;

use crate::util::constants::*;
Expand Down Expand Up @@ -50,7 +50,7 @@ impl Mmapper for ByteMapMmapper {
start: Address,
pages: usize,
strategy: MmapStrategy,
anno: &MmapAnno,
anno: &MmapAnnotation,
) -> Result<()> {
let start_chunk = Self::address_to_mmap_chunks_down(start);
let end_chunk = Self::address_to_mmap_chunks_up(start + pages_to_bytes(pages));
Expand Down Expand Up @@ -81,7 +81,7 @@ impl Mmapper for ByteMapMmapper {
start: Address,
pages: usize,
strategy: MmapStrategy,
anno: &MmapAnno,
anno: &MmapAnnotation,
) -> Result<()> {
let start_chunk = Self::address_to_mmap_chunks_down(start);
let end_chunk = Self::address_to_mmap_chunks_up(start + pages_to_bytes(pages));
Expand Down
6 changes: 3 additions & 3 deletions src/util/heap/layout/fragmented_mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::Mmapper;
use crate::util::constants::BYTES_IN_PAGE;
use crate::util::conversions;
use crate::util::heap::layout::vm_layout::*;
use crate::util::memory::{MmapAnno, MmapStrategy};
use crate::util::memory::{MmapAnnotation, MmapStrategy};
use crate::util::Address;
use atomic::{Atomic, Ordering};
use std::cell::UnsafeCell;
Expand Down Expand Up @@ -94,7 +94,7 @@ impl Mmapper for FragmentedMapper {
mut start: Address,
pages: usize,
strategy: MmapStrategy,
anno: &MmapAnno,
anno: &MmapAnnotation,
) -> Result<()> {
debug_assert!(start.is_aligned_to(BYTES_IN_PAGE));

Expand Down Expand Up @@ -153,7 +153,7 @@ impl Mmapper for FragmentedMapper {
mut start: Address,
pages: usize,
strategy: MmapStrategy,
anno: &MmapAnno,
anno: &MmapAnnotation,
) -> Result<()> {
let end = start + conversions::pages_to_bytes(pages);
// Iterate over the slabs covered
Expand Down
10 changes: 5 additions & 5 deletions src/util/heap/layout/mmapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub trait Mmapper: Sync {
start: Address,
pages: usize,
strategy: MmapStrategy,
anno: &MmapAnno,
anno: &MmapAnnotation,
) -> Result<()>;

/// Ensure that a range of pages is mmapped (or equivalent). If the
Expand All @@ -55,7 +55,7 @@ pub trait Mmapper: Sync {
start: Address,
pages: usize,
strategy: MmapStrategy,
anno: &MmapAnno,
anno: &MmapAnnotation,
) -> Result<()>;

/// Is the page pointed to by this address mapped? Returns true if
Expand Down Expand Up @@ -95,7 +95,7 @@ impl MapState {
state: &Atomic<MapState>,
mmap_start: Address,
strategy: MmapStrategy,
anno: &MmapAnno,
anno: &MmapAnnotation,
) -> Result<()> {
trace!(
"Trying to map {} - {}",
Expand Down Expand Up @@ -123,7 +123,7 @@ impl MapState {
state: &Atomic<MapState>,
mmap_start: Address,
strategy: MmapStrategy,
anno: &MmapAnno,
anno: &MmapAnnotation,
) -> Result<()> {
trace!(
"Trying to quarantine {} - {}",
Expand Down Expand Up @@ -168,7 +168,7 @@ impl MapState {
state_slices: &[&[Atomic<MapState>]],
mmap_start: Address,
strategy: MmapStrategy,
anno: &MmapAnno,
anno: &MmapAnnotation,
) -> Result<()> {
trace!(
"Trying to bulk-quarantine {} - {}",
Expand Down
32 changes: 16 additions & 16 deletions src/util/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const MMAP_FLAGS: libc::c_int = libc::MAP_ANON | libc::MAP_PRIVATE | libc::MAP_F
const MMAP_FLAGS: libc::c_int = libc::MAP_ANON | libc::MAP_PRIVATE | libc::MAP_FIXED;

/// This static variable controls whether we annotate mmapped memory region using `prctl`. It can be
/// set via `Options::mmap_anno` or the `MMTK_MMAP_ANNO` environment variable.
/// set via `Options::mmap_annotation` or the `MMTK_MMAP_ANNOTATION` environment variable.
///
/// FIXME: Since it is set via `Options`, it is in theory a decision per MMTk instance. However, we
/// currently don't have a good design for multiple MMTk instances, so we use static variable for
/// now.
pub(crate) static MMAP_ANNO: AtomicBool = AtomicBool::new(true);
pub(crate) static MMAP_ANNOTATION: AtomicBool = AtomicBool::new(true);

/// Strategy for performing mmap
#[derive(Debug, Copy, Clone)]
Expand Down Expand Up @@ -110,8 +110,8 @@ pub enum HugePageSupport {
///
/// On 32-bit architecture, side metadata are allocated in a chunked fasion. One single `mmap`
/// region will contain many different metadata. In that case, we simply annotate the whole region
/// with a `MmapAnno::SideMeta` where `meta` is `"all"`.
pub enum MmapAnno<'a> {
/// with a `MmapAnnotation::SideMeta` where `meta` is `"all"`.
pub enum MmapAnnotation<'a> {
Space { name: &'a str },
SideMeta { space: &'a str, meta: &'a str },
Test { file: &'a str, line: u32 },
Expand All @@ -121,20 +121,20 @@ pub enum MmapAnno<'a> {
#[macro_export]
macro_rules! mmap_anno_test {
() => {
&$crate::util::memory::MmapAnno::Test {
&$crate::util::memory::MmapAnnotation::Test {
file: file!(),
line: line!(),
}
};
}

impl<'a> std::fmt::Display for MmapAnno<'a> {
impl<'a> std::fmt::Display for MmapAnnotation<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
MmapAnno::Space { name } => write!(f, "mmtk:space:{name}"),
MmapAnno::SideMeta { space, meta } => write!(f, "mmtk:sidemeta:{space}:{meta}"),
MmapAnno::Test { file, line } => write!(f, "mmtk:test:{file}:{line}"),
MmapAnno::Misc { name } => write!(f, "mmtk:misc:{name}"),
MmapAnnotation::Space { name } => write!(f, "mmtk:space:{name}"),
MmapAnnotation::SideMeta { space, meta } => write!(f, "mmtk:sidemeta:{space}:{meta}"),
MmapAnnotation::Test { file, line } => write!(f, "mmtk:test:{file}:{line}"),
MmapAnnotation::Misc { name } => write!(f, "mmtk:misc:{name}"),
}
}
}
Expand Down Expand Up @@ -174,7 +174,7 @@ pub unsafe fn dzmmap(
start: Address,
size: usize,
strategy: MmapStrategy,
anno: &MmapAnno,
anno: &MmapAnnotation,
) -> Result<()> {
let flags = libc::MAP_ANON | libc::MAP_PRIVATE | libc::MAP_FIXED;
let ret = mmap_fixed(start, size, flags, strategy, anno);
Expand All @@ -193,7 +193,7 @@ pub fn dzmmap_noreplace(
start: Address,
size: usize,
strategy: MmapStrategy,
anno: &MmapAnno,
anno: &MmapAnnotation,
) -> Result<()> {
let flags = MMAP_FLAGS;
let ret = mmap_fixed(start, size, flags, strategy, anno);
Expand All @@ -213,7 +213,7 @@ pub fn mmap_noreserve(
start: Address,
size: usize,
mut strategy: MmapStrategy,
anno: &MmapAnno,
anno: &MmapAnnotation,
) -> Result<()> {
strategy.prot = MmapProtection::NoAccess;
let flags = MMAP_FLAGS | libc::MAP_NORESERVE;
Expand All @@ -225,7 +225,7 @@ fn mmap_fixed(
size: usize,
flags: libc::c_int,
strategy: MmapStrategy,
_anno: &MmapAnno,
_anno: &MmapAnnotation,
) -> Result<()> {
let ptr = start.to_mut_ptr();
let prot = strategy.prot.into_native_flags();
Expand All @@ -235,7 +235,7 @@ fn mmap_fixed(
)?;

#[cfg(target_os = "linux")]
if MMAP_ANNO.load(std::sync::atomic::Ordering::SeqCst) {
if MMAP_ANNOTATION.load(std::sync::atomic::Ordering::SeqCst) {
// `PR_SET_VMA` is new in Linux 5.17. We compile against a version of the `libc` crate that
// has the `PR_SET_VMA_ANON_NAME` constant. When runnning on an older kernel, it will not
// recognize this attribute and will return `EINVAL`. However, `prctl` may return `EINVAL`
Expand Down Expand Up @@ -334,7 +334,7 @@ pub fn handle_mmap_error<VM: VMBinding>(
///
/// This function is currently left empty for non-linux, and should be implemented in the future.
/// As the function is only used for assertions, MMTk will still run even if we never panic.
pub(crate) fn panic_if_unmapped(_start: Address, _size: usize, _anno: &MmapAnno) {
pub(crate) fn panic_if_unmapped(_start: Address, _size: usize, _anno: &MmapAnnotation) {
#[cfg(target_os = "linux")]
{
let flags = MMAP_FLAGS;
Expand Down
10 changes: 5 additions & 5 deletions src/util/metadata/side_metadata/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::*;
use crate::util::constants::{BYTES_IN_PAGE, BYTES_IN_WORD, LOG_BITS_IN_BYTE};
use crate::util::conversions::raw_align_up;
use crate::util::heap::layout::vm_layout::BYTES_IN_CHUNK;
use crate::util::memory::{self, MmapAnno};
use crate::util::memory::{self, MmapAnnotation};
use crate::util::metadata::metadata_val_traits::*;
#[cfg(feature = "vo_bit")]
use crate::util::metadata::vo_bit::VO_BIT_SIDE_METADATA_SPEC;
Expand Down Expand Up @@ -125,7 +125,7 @@ impl SideMetadataSpec {
memory::panic_if_unmapped(
meta_start,
BYTES_IN_PAGE,
&MmapAnno::Misc {
&MmapAnnotation::Misc {
name: "assert_metadata_mapped",
},
);
Expand Down Expand Up @@ -1433,7 +1433,7 @@ impl SideMetadataContext {
space_name: &str,
) -> Result<()> {
for spec in self.global.iter() {
let anno = MmapAnno::SideMeta {
let anno = MmapAnnotation::SideMeta {
space: space_name,
meta: spec.name,
};
Expand All @@ -1460,7 +1460,7 @@ impl SideMetadataContext {
// address space size as the current not-chunked approach.
#[cfg(target_pointer_width = "64")]
{
let anno = MmapAnno::SideMeta {
let anno = MmapAnnotation::SideMeta {
space: space_name,
meta: spec.name,
};
Expand All @@ -1484,7 +1484,7 @@ impl SideMetadataContext {
lsize,
max
);
let anno = MmapAnno::SideMeta {
let anno = MmapAnnotation::SideMeta {
space: space_name,
meta: "all",
};
Expand Down
4 changes: 2 additions & 2 deletions src/util/metadata/side_metadata/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::SideMetadataSpec;
use crate::util::constants::LOG_BYTES_IN_PAGE;
use crate::util::constants::{BITS_IN_WORD, BYTES_IN_PAGE, LOG_BITS_IN_BYTE};
use crate::util::heap::layout::vm_layout::VMLayout;
use crate::util::memory::{MmapAnno, MmapStrategy};
use crate::util::memory::{MmapAnnotation, MmapStrategy};
#[cfg(target_pointer_width = "32")]
use crate::util::metadata::side_metadata::address_to_chunked_meta_address;
use crate::util::Address;
Expand Down Expand Up @@ -126,7 +126,7 @@ pub(super) fn try_mmap_contiguous_metadata_space(
size: usize,
spec: &SideMetadataSpec,
no_reserve: bool,
anno: &MmapAnno,
anno: &MmapAnnotation,
) -> Result<usize> {
debug_assert!(start.is_aligned_to(BYTES_IN_PAGE));
debug_assert!(size % BYTES_IN_PAGE == 0);
Expand Down
6 changes: 3 additions & 3 deletions src/util/metadata/side_metadata/helpers_32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::SideMetadataSpec;
use crate::util::{
constants::{self, LOG_BITS_IN_BYTE},
heap::layout::vm_layout::{BYTES_IN_CHUNK, CHUNK_MASK, LOG_BYTES_IN_CHUNK},
memory::{self, MmapAnno},
memory::{self, MmapAnnotation},
Address,
};
use std::io::Result;
Expand Down Expand Up @@ -112,7 +112,7 @@ pub(super) fn try_map_per_chunk_metadata_space(
size: usize,
local_per_chunk: usize,
no_reserve: bool,
anno: &MmapAnno,
anno: &MmapAnnotation,
) -> Result<usize> {
let mut aligned_start = start.align_down(BYTES_IN_CHUNK);
let aligned_end = (start + size).align_up(BYTES_IN_CHUNK);
Expand Down Expand Up @@ -176,7 +176,7 @@ pub(super) fn try_mmap_metadata_chunk(
start: Address,
local_per_chunk: usize,
no_reserve: bool,
anno: &MmapAnno,
anno: &MmapAnnotation,
) -> Result<()> {
debug_assert!(start.is_aligned_to(BYTES_IN_CHUNK));

Expand Down
2 changes: 1 addition & 1 deletion src/util/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ options! {
/// Enable mmap annotation. By default, every time MMTk core calls `mmap`, it will annotate the
/// mapped memory range with human-readable names, which can be seen in `/proc/pid/maps`.
/// Setting this option to `false` will disable this annotation.
mmap_anno: bool [env_var: true, command_line: true] [always_valid] = true
mmap_annotation: bool [env_var: true, command_line: true] [always_valid] = true
}

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions src/util/raw_memory_freelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::memory::MmapStrategy;
use crate::util::address::Address;
use crate::util::constants::*;
use crate::util::conversions;
use crate::util::memory::MmapAnno;
use crate::util::memory::MmapAnnotation;

/** log2 of the number of bits used by a free list entry (two entries per unit) */
const LOG_ENTRY_BITS: usize = LOG_BITS_IN_INT as _;
Expand Down Expand Up @@ -203,7 +203,7 @@ impl RawMemoryFreeList {
start,
bytes,
self.strategy,
&MmapAnno::Misc {
&MmapAnnotation::Misc {
name: "RawMemoryFreeList",
},
);
Expand Down

0 comments on commit de848c4

Please sign in to comment.