From b13601b965478bc8349f76cc45b4dd48e2500d0b Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Thu, 4 Aug 2022 16:23:21 +0200 Subject: [PATCH] chore: use memmap2 instead of mapr `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()`. --- storage-proofs-porep/Cargo.toml | 2 +- storage-proofs-porep/src/stacked/vanilla/cache.rs | 2 +- .../src/stacked/vanilla/create_label/multi.rs | 2 +- .../src/stacked/vanilla/memory_handling.rs | 12 ++++-------- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/storage-proofs-porep/Cargo.toml b/storage-proofs-porep/Cargo.toml index 794b3522b1..f78e2c4557 100644 --- a/storage-proofs-porep/Cargo.toml +++ b/storage-proofs-porep/Cargo.toml @@ -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" diff --git a/storage-proofs-porep/src/stacked/vanilla/cache.rs b/storage-proofs-porep/src/stacked/vanilla/cache.rs index dc3ec6ce67..6c9c0e0304 100644 --- a/storage-proofs-porep/src/stacked/vanilla/cache.rs +++ b/storage-proofs-porep/src/stacked/vanilla/cache.rs @@ -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}; diff --git a/storage-proofs-porep/src/stacked/vanilla/create_label/multi.rs b/storage-proofs-porep/src/stacked/vanilla/create_label/multi.rs index e3a9ca38ec..e662a838dc 100644 --- a/storage-proofs-porep/src/stacked/vanilla/create_label/multi.rs +++ b/storage-proofs-porep/src/stacked/vanilla/create_label/multi.rs @@ -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, diff --git a/storage-proofs-porep/src/stacked/vanilla/memory_handling.rs b/storage-proofs-porep/src/stacked/vanilla/memory_handling.rs index 5d3b1d0e63..8180f2f961 100644 --- a/storage-proofs-porep/src/stacked/vanilla/memory_handling.rs +++ b/storage-proofs-porep/src/stacked/vanilla/memory_handling.rs @@ -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 { file: File, @@ -192,8 +192,7 @@ impl CacheReader { MmapOptions::new() .offset(offset) .len(len) - .private() - .map(file) + .map_copy_read_only(file) .map_err(|e| e.into()) } } @@ -278,19 +277,16 @@ impl CacheReader { fn allocate_layer(sector_size: usize) -> Result { 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) } }