Skip to content

Commit

Permalink
chore: use memmap2 instead of mapr
Browse files Browse the repository at this point in the history
`memmap2` is maintained and contains all features from `mapr`, so using
the `mapr` fork of `memmap` is no longer needed.

Here are the changes in detail:

 - `map_anon()` in `memmap2` is always `MAP_PRIVATE`, so a call to `private()`
is no longer needed.
 - using `mlock` is similar to the `MAP_LOCKED` setting, hence it is no longer
   set. In `memmap2` the `mlock()` is just called `lock()`.
 - `MAP_PRIVATE` is done via `map_copy_read_only()`.
  • Loading branch information
vmx committed Aug 12, 2022
1 parent 380d643 commit b13601b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion storage-proofs-porep/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ storage-proofs-core = { path = "../storage-proofs-core", version = "~12.0.0", de
sha2raw = { path = "../sha2raw", version = "~7.0.0"}
filecoin-hashers = { path = "../filecoin-hashers", version = "~7.0.0", default-features = false, features = ["poseidon", "sha256"]}
merkletree = "0.22.0"
mapr = "0.8.0"
memmap2 = "0.5.6"
num-bigint = "0.4.3"
num-traits = "0.2"
rayon = "1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion storage-proofs-porep/src/stacked/vanilla/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use byteorder::{ByteOrder, LittleEndian};
use filecoin_hashers::Hasher;
use lazy_static::lazy_static;
use log::{info, trace};
use mapr::{Mmap, MmapOptions};
use memmap2::{Mmap, MmapOptions};
use rayon::prelude::{IndexedParallelIterator, ParallelIterator, ParallelSliceMut};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use generic_array::{
GenericArray,
};
use log::{debug, info};
use mapr::MmapMut;
use memmap2::MmapMut;
use merkletree::store::{DiskStore, Store, StoreConfig};
use storage_proofs_core::{
cache_key::CacheKey,
Expand Down
12 changes: 4 additions & 8 deletions storage-proofs-porep/src/stacked/vanilla/memory_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
use anyhow::Result;
use byte_slice_cast::{AsSliceOf, FromByteSlice};
use log::{info, warn};
use mapr::{Mmap, MmapMut, MmapOptions};
use memmap2::{Mmap, MmapMut, MmapOptions};

pub struct CacheReader<T> {
file: File,
Expand Down Expand Up @@ -192,8 +192,7 @@ impl<T: FromByteSlice> CacheReader<T> {
MmapOptions::new()
.offset(offset)
.len(len)
.private()
.map(file)
.map_copy_read_only(file)
.map_err(|e| e.into())
}
}
Expand Down Expand Up @@ -278,19 +277,16 @@ impl<T: FromByteSlice> CacheReader<T> {
fn allocate_layer(sector_size: usize) -> Result<MmapMut> {
match MmapOptions::new()
.len(sector_size)
.private()
.clone()
.lock()
.map_anon()
.and_then(|mut layer| {
layer.mlock()?;
layer.lock()?;
Ok(layer)
}) {
Ok(layer) => Ok(layer),
Err(err) => {
// fallback to not locked if permissions are not available
warn!("failed to lock map {:?}, falling back", err);
let layer = MmapOptions::new().len(sector_size).private().map_anon()?;
let layer = MmapOptions::new().len(sector_size).map_anon()?;
Ok(layer)
}
}
Expand Down

0 comments on commit b13601b

Please sign in to comment.