Skip to content

Refactor both Mmapper impls into ChunkStateMmapper #1369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions benches/mock_bench/mmapper.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub use criterion::Criterion;

use mmtk::{
memory_manager,
util::{test_util::fixtures::*, Address},
memory_manager, mmap_anno_test,
util::{constants::BYTES_IN_PAGE, memory::MmapStrategy, test_util::fixtures::*, Address},
};

pub fn bench(c: &mut Criterion) {
Expand Down Expand Up @@ -69,4 +69,16 @@ pub fn bench(c: &mut Criterion) {
}
})
});

c.bench_function("ensure_mapped_regular", |b| {
let start = regular.align_down(BYTES_IN_PAGE);
assert!(start.is_mapped());
let strategy = MmapStrategy::new(false, mmtk::util::memory::MmapProtection::ReadWrite);
let anno = mmap_anno_test!();
b.iter(|| {
mmtk::MMAPPER
.ensure_mapped(start, 1, strategy, anno)
.unwrap();
})
});
}
16 changes: 16 additions & 0 deletions docs/userguide/src/migration/prefix.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ Notes for the mmtk-core developers:

## 0.32.0

### Removed the notion of "mmap chunk"

```admonish tldr
Constants such as `MMAP_CHUNK_BYTES` were related to the implementation details of the memory
mapper, and should not have been exposed.
```

API changes:

- module `util::conversions`
+ `mmap_chunk_align_down`: Removed.
+ `mmap_chunk_align_up`: Removed.
- module `util::heap::vm_layout`
+ `LOG_MMAP_CHUNK_BYTES`: Removed.
+ `MMAP_CHUNK_BYTES`: Removed.

### `Options` no longer differentiates between environment variables and command line arguments.

```admonish tldr
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern crate probe;

mod mmtk;
pub use mmtk::MMTKBuilder;
pub(crate) use mmtk::MMAPPER;
pub use mmtk::MMAPPER;
pub use mmtk::MMTK;

mod global_state;
Expand Down
2 changes: 1 addition & 1 deletion src/mmtk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ lazy_static! {
pub static ref VM_MAP: Box<dyn VMMap + Send + Sync> = layout::create_vm_map();

/// A global Mmapper for mmaping and protection of virtual memory.
pub static ref MMAPPER: Box<dyn Mmapper + Send + Sync> = layout::create_mmapper();
pub static ref MMAPPER: Box<dyn Mmapper> = layout::create_mmapper();
}

use crate::util::rust_util::InitializeOnce;
Expand Down
16 changes: 9 additions & 7 deletions src/policy/largeobjectspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,28 @@ impl<VM: VMBinding> SFT for LargeObjectSpace<VM> {
ptr: Address,
max_search_bytes: usize,
) -> Option<ObjectReference> {
use crate::util::heap::vm_layout::MMAP_CHUNK_BYTES;
use crate::util::metadata::vo_bit;
use crate::{util::metadata::vo_bit, MMAPPER};

// We need to check if metadata address is mapped or not. But we only check at chunk granularity.
// This records the start of a chunk that is tested to be mapped.
let mut mapped_chunk = Address::MAX;
let mmap_granularity = MMAPPER.granularity();

// We need to check if metadata address is mapped or not. But we make use of the granularity of
// the `Mmapper` to reduce the number of checks. This records the start of a grain that is
// tested to be mapped.
let mut mapped_grain = Address::MAX;

// For large object space, it is a bit special. We only need to check VO bit for each page.
let mut cur_page = ptr.align_down(BYTES_IN_PAGE);
let low_page = ptr
.saturating_sub(max_search_bytes)
.align_down(BYTES_IN_PAGE);
while cur_page >= low_page {
if cur_page < mapped_chunk {
if cur_page < mapped_grain {
if !cur_page.is_mapped() {
// If the page start is not mapped, there can't be an object in it.
return None;
}
// This is mapped. No need to check for this chunk.
mapped_chunk = cur_page.align_down(MMAP_CHUNK_BYTES);
mapped_grain = cur_page.align_down(mmap_granularity);
}
// For performance, we only check the first word which maps to the first 512 bytes in the page.
// In almost all the cases, it should be sufficient.
Expand Down
10 changes: 0 additions & 10 deletions src/util/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ pub const fn chunk_align_down(addr: Address) -> Address {
addr.align_down(BYTES_IN_CHUNK)
}

/// Align up an address to the nearest chunk at which granularity we mmap memory.
pub const fn mmap_chunk_align_up(addr: Address) -> Address {
addr.align_up(MMAP_CHUNK_BYTES)
}

/// Align down an address to the nearest chunk at which granularity we mmap memory.
pub const fn mmap_chunk_align_down(addr: Address) -> Address {
addr.align_down(MMAP_CHUNK_BYTES)
}

/// Convert size in bytes to the number of chunks (aligned up).
pub fn bytes_to_chunks_up(bytes: usize) -> usize {
(bytes + BYTES_IN_CHUNK - 1) >> LOG_BYTES_IN_CHUNK
Expand Down
Loading
Loading