Skip to content

Commit

Permalink
madvise on linux only
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Jun 5, 2024
1 parent 01e4a87 commit fbacc24
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub(crate) mod os {

#[cfg(feature = "mmap")]
pub(crate) mod mmap {
use memmap2::{Advice, Mmap, MmapOptions};
use memmap2::{Mmap, MmapOptions};

use super::*;

Expand All @@ -172,9 +172,13 @@ pub(crate) mod mmap {

fn open(&self, path: &Path) -> io::Result<Box<dyn RandomAccessFile>> {
let file = fs::File::open(path)?;

// Safety: Contract forwarded to MmapFilesystem::new().
let mmap = unsafe { MmapOptions::new().map(&file)? };
mmap.advise(Advice::Random)?;

#[cfg(unix)]
mmap.advise(memmap2::Advice::Random)?;

Ok(Box::new(MmapRandomAccessFile { mmap }))
}
}
Expand Down

0 comments on commit fbacc24

Please sign in to comment.