Skip to content

Commit

Permalink
feat: introduce fs device config builder to auto detect config (#354)
Browse files Browse the repository at this point in the history
* feat: introduce fs device config builder to auto detect config

Signed-off-by: MrCroxx <mrcroxx@outlook.com>

* fix: fix build on macos

Signed-off-by: MrCroxx <mrcroxx@outlook.com>

* fix: try fix ci by ignoring the freespace check

Signed-off-by: MrCroxx <mrcroxx@outlook.com>

* fix: fix freespace on macos

Signed-off-by: MrCroxx <mrcroxx@outlook.com>

* fix: use frsize instead of bsize on both macos and linux

Signed-off-by: MrCroxx <mrcroxx@outlook.com>

* chore: disable freespace test on CI

Signed-off-by: MrCroxx <mrcroxx@outlook.com>

---------

Signed-off-by: MrCroxx <mrcroxx@outlook.com>
  • Loading branch information
MrCroxx committed Apr 17, 2024
1 parent 9a8b3d4 commit e6fdc11
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 28 deletions.
8 changes: 8 additions & 0 deletions .github/template/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ jobs:
- name: Run rust test with coverage (igored tests)
env:
RUST_BACKTRACE: 1
CI: true
run: |
cargo llvm-cov --no-report nextest --run-ignored ignored-only --no-capture --workspace
- name: Run rust test with coverage
env:
RUST_BACKTRACE: 1
CI: true
run: |
cargo llvm-cov --no-report nextest
- name: Generate codecov report
Expand Down Expand Up @@ -130,6 +132,7 @@ jobs:
RUSTFLAGS: "--cfg tokio_unstable"
RUST_LOG: info
TOKIO_WORKER_THREADS: 1
CI: true
run: |-
cargo build --all --features deadlock
mkdir -p $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/deadlock
Expand Down Expand Up @@ -159,13 +162,15 @@ jobs:
RUST_BACKTRACE: 1
RUSTFLAGS: "-Zsanitizer=address --cfg tokio_unstable"
RUST_LOG: info
CI: true
run: |-
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} test --lib --bins --tests --target x86_64-unknown-linux-gnu -- --nocapture
- name: Run foyer-storage-bench With Address Sanitizer
env:
RUST_BACKTRACE: 1
RUSTFLAGS: "-Zsanitizer=address --cfg tokio_unstable"
RUST_LOG: info
CI: true
run: |-
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} build --all --target x86_64-unknown-linux-gnu
mkdir -p $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/asan
Expand Down Expand Up @@ -205,13 +210,15 @@ jobs:
RUST_BACKTRACE: 1
RUSTFLAGS: "-Zsanitizer=leak --cfg tokio_unstable"
RUST_LOG: info
CI: true
run: |-
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} test --lib --bins --tests --target x86_64-unknown-linux-gnu -- --nocapture
- name: Run foyer-storage-bench With Leak Sanitizer
env:
RUST_BACKTRACE: 1
RUSTFLAGS: "-Zsanitizer=leak --cfg tokio_unstable"
RUST_LOG: info
CI: true
run: |-
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} build --all --target x86_64-unknown-linux-gnu
mkdir -p $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/lsan
Expand Down Expand Up @@ -255,6 +262,7 @@ jobs:
RUSTFLAGS: "--cfg tokio_unstable --cfg madsim"
RUST_LOG: info
TOKIO_WORKER_THREADS: 1
CI: true
run: |-
cargo clippy --all-targets
- name: Run nextest (madsim)
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ jobs:
- name: Run rust test with coverage (igored tests)
env:
RUST_BACKTRACE: 1
CI: true
run: |
cargo llvm-cov --no-report nextest --run-ignored ignored-only --no-capture --workspace
- name: Run rust test with coverage
env:
RUST_BACKTRACE: 1
CI: true
run: |
cargo llvm-cov --no-report nextest
- name: Generate codecov report
Expand Down Expand Up @@ -137,6 +139,7 @@ jobs:
RUSTFLAGS: "--cfg tokio_unstable"
RUST_LOG: info
TOKIO_WORKER_THREADS: 1
CI: true
run: |-
cargo build --all --features deadlock
mkdir -p $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/deadlock
Expand Down Expand Up @@ -166,13 +169,15 @@ jobs:
RUST_BACKTRACE: 1
RUSTFLAGS: "-Zsanitizer=address --cfg tokio_unstable"
RUST_LOG: info
CI: true
run: |-
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} test --lib --bins --tests --target x86_64-unknown-linux-gnu -- --nocapture
- name: Run foyer-storage-bench With Address Sanitizer
env:
RUST_BACKTRACE: 1
RUSTFLAGS: "-Zsanitizer=address --cfg tokio_unstable"
RUST_LOG: info
CI: true
run: |-
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} build --all --target x86_64-unknown-linux-gnu
mkdir -p $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/asan
Expand Down Expand Up @@ -212,13 +217,15 @@ jobs:
RUST_BACKTRACE: 1
RUSTFLAGS: "-Zsanitizer=leak --cfg tokio_unstable"
RUST_LOG: info
CI: true
run: |-
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} test --lib --bins --tests --target x86_64-unknown-linux-gnu -- --nocapture
- name: Run foyer-storage-bench With Leak Sanitizer
env:
RUST_BACKTRACE: 1
RUSTFLAGS: "-Zsanitizer=leak --cfg tokio_unstable"
RUST_LOG: info
CI: true
run: |-
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} build --all --target x86_64-unknown-linux-gnu
mkdir -p $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/lsan
Expand Down Expand Up @@ -262,6 +269,7 @@ jobs:
RUSTFLAGS: "--cfg tokio_unstable --cfg madsim"
RUST_LOG: info
TOKIO_WORKER_THREADS: 1
CI: true
run: |-
cargo clippy --all-targets
- name: Run nextest (madsim)
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ jobs:
- name: Run rust test with coverage (igored tests)
env:
RUST_BACKTRACE: 1
CI: true
run: |
cargo llvm-cov --no-report nextest --run-ignored ignored-only --no-capture --workspace
- name: Run rust test with coverage
env:
RUST_BACKTRACE: 1
CI: true
run: |
cargo llvm-cov --no-report nextest
- name: Generate codecov report
Expand Down Expand Up @@ -136,6 +138,7 @@ jobs:
RUSTFLAGS: "--cfg tokio_unstable"
RUST_LOG: info
TOKIO_WORKER_THREADS: 1
CI: true
run: |-
cargo build --all --features deadlock
mkdir -p $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/deadlock
Expand Down Expand Up @@ -165,13 +168,15 @@ jobs:
RUST_BACKTRACE: 1
RUSTFLAGS: "-Zsanitizer=address --cfg tokio_unstable"
RUST_LOG: info
CI: true
run: |-
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} test --lib --bins --tests --target x86_64-unknown-linux-gnu -- --nocapture
- name: Run foyer-storage-bench With Address Sanitizer
env:
RUST_BACKTRACE: 1
RUSTFLAGS: "-Zsanitizer=address --cfg tokio_unstable"
RUST_LOG: info
CI: true
run: |-
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} build --all --target x86_64-unknown-linux-gnu
mkdir -p $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/asan
Expand Down Expand Up @@ -211,13 +216,15 @@ jobs:
RUST_BACKTRACE: 1
RUSTFLAGS: "-Zsanitizer=leak --cfg tokio_unstable"
RUST_LOG: info
CI: true
run: |-
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} test --lib --bins --tests --target x86_64-unknown-linux-gnu -- --nocapture
- name: Run foyer-storage-bench With Leak Sanitizer
env:
RUST_BACKTRACE: 1
RUSTFLAGS: "-Zsanitizer=leak --cfg tokio_unstable"
RUST_LOG: info
CI: true
run: |-
cargo +${{ env.RUST_TOOLCHAIN_NIGHTLY }} build --all --target x86_64-unknown-linux-gnu
mkdir -p $GITHUB_WORKSPACE/foyer-data/foyer-storage-bench/lsan
Expand Down Expand Up @@ -261,6 +268,7 @@ jobs:
RUSTFLAGS: "--cfg tokio_unstable --cfg madsim"
RUST_LOG: info
TOKIO_WORKER_THREADS: 1
CI: true
run: |-
cargo clippy --all-targets
- name: Run nextest (madsim)
Expand Down
1 change: 1 addition & 0 deletions foyer-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bytes = "1"
cfg-if = "1"
foyer-workspace-hack = { version = "0.4", path = "../foyer-workspace-hack" }
itertools = "0.12"
nix = { version = "0.28", features = ["fs"] }
parking_lot = { version = "0.12", features = ["arc_lock"] }
paste = "1.0"
tokio = { workspace = true }
Expand Down
61 changes: 61 additions & 0 deletions foyer-common/src/fs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2024 Foyer Project Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::path::Path;

use nix::{errno::Errno, sys::statvfs::statvfs};

pub fn freespace(path: impl AsRef<Path>) -> Result<usize, Errno> {
let stat = statvfs(path.as_ref())?;
let res = stat.blocks_available() as usize * stat.fragment_size() as usize;
Ok(res)
}

#[cfg(test)]
mod tests {
use std::{
env::{current_dir, var},
process::Command,
};

use super::*;
use itertools::Itertools;

#[test]
#[ignore]
fn test() {
if var("CI").unwrap_or("".to_string()) != "true" {
let dir = current_dir().unwrap();
let path = dir.as_os_str().to_str().unwrap();

println!("{}", path);

let v1 = freespace(path).unwrap();
let df = String::from_utf8(Command::new("df").args(["-P", path]).output().unwrap().stdout).unwrap();
let bs: usize = df.trim().split('\n').next().unwrap().split_whitespace().collect_vec()[1]
.strip_suffix("-blocks")
.unwrap()
.parse()
.unwrap();
let av: usize = df.trim().split('\n').last().unwrap().split_whitespace().collect_vec()[3]
.parse()
.unwrap();
let v2 = bs * av;

println!("{}", df);

assert_eq!(v1, v2);
}
}
}
3 changes: 3 additions & 0 deletions foyer-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ pub mod range;
pub mod rate;
pub mod rated_ticket;
pub mod runtime;

#[cfg(any(target_os = "linux", target_os = "macos"))]
pub mod fs;
2 changes: 1 addition & 1 deletion foyer-storage-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ async fn main() {
let device_config = FsDeviceConfig {
dir: PathBuf::from(&args.dir),
capacity: args.capacity * 1024 * 1024,
file_capacity: args.region_size * 1024 * 1024,
file_size: args.region_size * 1024 * 1024,
align: args.align,
io_size: args.io_size,
};
Expand Down
8 changes: 4 additions & 4 deletions foyer-storage/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,10 @@ mod tests {

let device = FsDevice::open(FsDeviceConfig {
dir: tempdir.path().into(),
capacity: 256 * 1024, // 256 KiB
file_capacity: 64 * 1024, // 64 KiB
align: 4 * 1024, // 4 KiB
io_size: 16 * 1024, // 16 KiB
capacity: 256 * 1024, // 256 KiB
file_size: 64 * 1024, // 64 KiB
align: 4 * 1024, // 4 KiB
io_size: 16 * 1024, // 16 KiB
})
.await
.unwrap();
Expand Down
Loading

0 comments on commit e6fdc11

Please sign in to comment.