Skip to content

Commit

Permalink
CI for windows and macos (#222)
Browse files Browse the repository at this point in the history
* CI for windows and macos

* Disable address space reservation on windows

* Style & warnings

* Remove superfluous call
  • Loading branch information
arkpar authored Sep 15, 2023
1 parent 2c52598 commit 4ac2aca
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ env:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-22.04, macos-13-xl, windows-2022]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
Expand Down
44 changes: 22 additions & 22 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ use crate::{
};
use std::sync::atomic::{AtomicU64, Ordering};

#[cfg(not(test))]
const RESERVE_ADDRESS_SPACE: usize = 1024 * 1024 * 1024; // 1 Gb

// Use different value for tests to work around docker limits on the test machine.
#[cfg(test)]
const RESERVE_ADDRESS_SPACE: usize = 64 * 1024 * 1024; // 64 Mb

#[cfg(target_os = "linux")]
fn disable_read_ahead(file: &std::fs::File) -> std::io::Result<()> {
use std::os::unix::io::AsRawFd;
Expand Down Expand Up @@ -53,6 +46,25 @@ pub fn madvise_random(map: &mut memmap2::MmapMut) {
#[cfg(not(unix))]
pub fn madvise_random(_map: &mut memmap2::MmapMut) {}

#[cfg(not(windows))]
fn mmap(file: &std::fs::File, len: usize) -> Result<memmap2::MmapMut> {
#[cfg(not(test))]
const RESERVE_ADDRESS_SPACE: usize = 1024 * 1024 * 1024; // 1 Gb
// Use different value for tests to work around docker limits on the test machine.
#[cfg(test)]
const RESERVE_ADDRESS_SPACE: usize = 64 * 1024 * 1024; // 64 Mb

let map_len = len + RESERVE_ADDRESS_SPACE;
let mut map = try_io!(unsafe { memmap2::MmapOptions::new().len(map_len).map_mut(file) });
madvise_random(&mut map);
Ok(map)
}

#[cfg(windows)]
fn mmap(file: &std::fs::File, _len: usize) -> Result<memmap2::MmapMut> {
Ok(try_io!(unsafe { memmap2::MmapOptions::new().map_mut(file) }))
}

const GROW_SIZE_BYTES: u64 = 256 * 1024;

#[derive(Debug)]
Expand All @@ -63,10 +75,6 @@ pub struct TableFile {
pub id: TableId,
}

fn map_len(file_len: u64) -> usize {
file_len as usize + RESERVE_ADDRESS_SPACE
}

impl TableFile {
pub fn open(filepath: std::path::PathBuf, entry_size: u16, id: TableId) -> Result<Self> {
let mut capacity = 0u64;
Expand All @@ -84,9 +92,7 @@ impl TableFile {
} else {
capacity = len / entry_size as u64;
}
let mut map =
try_io!(unsafe { memmap2::MmapOptions::new().len(map_len(len)).map_mut(&file) });
madvise_random(&mut map);
let mut map = mmap(&file, len as usize)?;
Some((map, file))
} else {
None
Expand Down Expand Up @@ -152,21 +158,15 @@ impl TableFile {
let file = self.create_file()?;
let len = GROW_SIZE_BYTES;
try_io!(file.set_len(len));
let mut map = try_io!(unsafe {
memmap2::MmapOptions::new().len(RESERVE_ADDRESS_SPACE).map_mut(&file)
});
madvise_random(&mut map);
let map = mmap(&file, 0)?;
*map_and_file = Some((map, file));
len
},
Some((map, file)) => {
let new_len = try_io!(file.metadata()).len() + GROW_SIZE_BYTES;
try_io!(file.set_len(new_len));
if map.len() < new_len as usize {
let mut new_map = try_io!(unsafe {
memmap2::MmapOptions::new().len(map_len(new_len)).map_mut(&*file)
});
madvise_random(&mut new_map);
let new_map = mmap(&file, new_len as usize)?;
let old_map = std::mem::replace(map, new_map);
try_io!(old_map.flush());
// Leak the old mapping as there might be concurrent readers.
Expand Down

0 comments on commit 4ac2aca

Please sign in to comment.