Skip to content

Commit 0246fbe

Browse files
committed
Fix mmap
1 parent 35e434e commit 0246fbe

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/generic_storage/mmap_vec.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
use std::fs::{File, OpenOptions};
2-
use std::ops::{Deref, DerefMut};
3-
use std::path::Path;
1+
use std::{
2+
fs::{File, OpenOptions},
3+
ops::{Deref, DerefMut},
4+
path::Path,
5+
};
46

57
use bytemuck::Pod;
68
use color_eyre::eyre::bail;
7-
use mmap_rs::{MmapMut, MmapOptions};
9+
use mmap_rs::{MmapFlags, MmapMut, MmapOptions};
810

911
const META_SIZE: usize = std::mem::size_of::<usize>();
1012

@@ -86,6 +88,7 @@ impl<T> MmapVec<T> {
8688
let mmap = MmapOptions::new(byte_len)
8789
.expect("cannot create memory map")
8890
.with_file(&file, 0)
91+
.with_flags(MmapFlags::SHARED)
8992
.map_mut()
9093
.expect("cannot build memory map");
9194

@@ -159,6 +162,7 @@ impl<T> MmapVec<T> {
159162
MmapOptions::new(new_file_len)
160163
.expect("cannot create memory map")
161164
.with_file(&self.file, 0)
165+
.with_flags(MmapFlags::SHARED)
162166
.map_mut()
163167
.expect("cannot build memory map"),
164168
);

src/lazy_merkle_tree.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::merkle_tree::{Branch, Hasher, Proof};
21
use std::{
32
fs::OpenOptions,
43
io::Write,
@@ -9,10 +8,12 @@ use std::{
98
sync::{Arc, Mutex},
109
};
1110

12-
use mmap_rs::{MmapMut, MmapOptions};
11+
use mmap_rs::{MmapFlags, MmapMut, MmapOptions};
1312
use rayon::prelude::*;
1413
use thiserror::Error;
1514

15+
use crate::merkle_tree::{Branch, Hasher, Proof};
16+
1617
pub trait VersionMarker {}
1718
#[derive(Debug)]
1819
pub struct Canonical;
@@ -1142,6 +1143,7 @@ impl<H: Hasher> MmapMutWrapper<H> {
11421143
MmapOptions::new(usize::try_from(buf_len as u64).expect("file size truncated"))
11431144
.expect("cannot create memory map")
11441145
.with_file(&file, 0)
1146+
.with_flags(MmapFlags::SHARED)
11451147
.map_mut()
11461148
.expect("cannot build memory map")
11471149
};
@@ -1188,6 +1190,7 @@ impl<H: Hasher> MmapMutWrapper<H> {
11881190
)
11891191
.expect("cannot create memory map")
11901192
.with_file(&file, 0)
1193+
.with_flags(MmapFlags::SHARED)
11911194
.map_mut()
11921195
.expect("cannot build memory map")
11931196
};
@@ -1229,9 +1232,10 @@ pub enum DenseMMapError {
12291232

12301233
#[cfg(test)]
12311234
mod tests {
1235+
use hex_literal::hex;
1236+
12321237
use super::*;
12331238
use crate::merkle_tree::{test::Keccak256, Hasher};
1234-
use hex_literal::hex;
12351239

12361240
struct TestHasher;
12371241

0 commit comments

Comments
 (0)