Skip to content

mmap with MAP_PRIVATE #1313

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

Merged
merged 2 commits into from
Mar 9, 2024
Merged
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions gix-commitgraph/src/file/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ use std::{
path::Path,
};

use bstr::ByteSlice;
use memmap2::Mmap;

use crate::{
file::{
ChunkId, BASE_GRAPHS_LIST_CHUNK_ID, COMMIT_DATA_CHUNK_ID, COMMIT_DATA_ENTRY_SIZE_SANS_HASH,
EXTENDED_EDGES_LIST_CHUNK_ID, FAN_LEN, HEADER_LEN, OID_FAN_CHUNK_ID, OID_LOOKUP_CHUNK_ID, SIGNATURE,
},
File,
};
use bstr::ByteSlice;

/// The error used in [`File::at()`].
#[derive(thiserror::Error, Debug)]
Expand Down Expand Up @@ -246,7 +244,7 @@ impl TryFrom<&Path> for File {
// SAFETY: we have to take the risk of somebody changing the file underneath. Git never writes into the same file.
#[allow(unsafe_code)]
unsafe {
Mmap::map(&file)
memmap2::MmapOptions::new().map_copy_read_only(&file)
}
})
.map_err(|e| Error::Io {
Expand Down
4 changes: 1 addition & 3 deletions gix-index/src/file/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

use std::path::{Path, PathBuf};

use memmap2::Mmap;

use crate::{decode, extension, File, State};

mod error {
Expand Down Expand Up @@ -64,7 +62,7 @@ impl File {
let mut file = std::fs::File::open(&path)?;
// SAFETY: we have to take the risk of somebody changing the file underneath. Git never writes into the same file.
#[allow(unsafe_code)]
let data = unsafe { Mmap::map(&file)? };
let data = unsafe { memmap2::MmapOptions::new().map_copy_read_only(&file)? };

if !skip_hash {
// Note that even though it's trivial to offload this into a thread, which is worth it for all but the smallest
Expand Down
2 changes: 1 addition & 1 deletion gix-pack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ mod mmap {
// SAFETY: we have to take the risk of somebody changing the file underneath. Git never writes into the same file.
#[allow(unsafe_code)]
unsafe {
memmap2::Mmap::map(&file)
memmap2::MmapOptions::new().map_copy_read_only(&file)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gix-pack/tests/pack/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ mod version {
desired_kind,
|| {
let file = std::fs::File::open(fixture_path(data_path))?;
let map = unsafe { memmap2::Mmap::map(&file)? };
let map = unsafe { memmap2::MmapOptions::map_copy_read_only(&file)? };
Ok((slice_map, map))
},
pack_iter,
Expand Down
3 changes: 1 addition & 2 deletions gix-ref/src/store/packed/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ impl AsRef<[u8]> for packed::Backing {
pub mod open {
use std::path::PathBuf;

use memmap2::Mmap;
use winnow::{prelude::*, stream::Offset};

use crate::store_impl::packed;
Expand Down Expand Up @@ -81,7 +80,7 @@ pub mod open {
// SAFETY: we have to take the risk of somebody changing the file underneath. Git never writes into the same file.
#[allow(unsafe_code)]
unsafe {
Mmap::map(&std::fs::File::open(&path)?)?
memmap2::MmapOptions::new().map_copy_read_only(&std::fs::File::open(&path)?)?
},
)
};
Expand Down