diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 8fbba2ea..9e59bbee 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -13,6 +13,12 @@ readme.workspace = true exclude.workspace = true publish = false +# `tonic` is not used directly in example code, but it must be listed as a dep so the `ot` feature +# can opt into the tonic-backed gRPC transport for `opentelemetry-otlp` (`grpc-tonic`). +# Tell cargo-machete to ignore it so CI doesn't flag it as unused. +[package.metadata.cargo-machete] +ignored = ["tonic"] + [features] serde = ["foyer/serde"] jaeger = ["fastrace-jaeger"] @@ -56,12 +62,6 @@ tokio = { workspace = true, features = ["full"] } tonic = { workspace = true, optional = true } tracing = { workspace = true } -# `tonic` is not used directly in example code, but it must be listed as a dep so the `ot` feature -# can opt into the tonic-backed gRPC transport for `opentelemetry-otlp` (`grpc-tonic`). -# Tell cargo-machete to ignore it so CI doesn't flag it as unused. -[package.metadata.cargo-machete] -ignored = ["tonic"] - [[example]] name = "memory" path = "memory.rs" diff --git a/foyer-bench/Cargo.toml b/foyer-bench/Cargo.toml index e9f9b9c1..e412a706 100644 --- a/foyer-bench/Cargo.toml +++ b/foyer-bench/Cargo.toml @@ -13,13 +13,14 @@ readme.workspace = true exclude.workspace = true [features] -default = ["jemalloc"] +default = ["jemalloc", "io_uring"] deadlock = ["parking_lot/deadlock_detection", "foyer/deadlock"] tokio-console = ["dep:console-subscriber"] strict_assertions = ["foyer/strict_assertions"] jemalloc = ["dep:tikv-jemallocator"] jeprof = ["jemalloc", "tikv-jemallocator?/profiling"] tracing = ["fastrace/enable", "foyer/tracing", "dep:fastrace-jaeger"] +io_uring = ["foyer/io_uring"] [dependencies] anyhow = { workspace = true } diff --git a/foyer-bench/src/main.rs b/foyer-bench/src/main.rs index 431494b1..9a7d9135 100644 --- a/foyer-bench/src/main.rs +++ b/foyer-bench/src/main.rs @@ -37,7 +37,7 @@ use analyze::{Metrics, analyze, monitor}; use bytesize::ByteSize; use clap::{ArgGroup, Parser, builder::PossibleValuesParser}; use exporter::PrometheusExporter; -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", feature = "io_uring"))] use foyer::UringIoEngineConfig; use foyer::{ BlockEngineConfig, Code, Compression, Device, DeviceBuilder, EngineConfig, FifoConfig, FifoPicker, @@ -592,7 +592,7 @@ async fn benchmark(args: Args) { } builder.boxed() } - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", feature = "io_uring"))] "io_uring" => UringIoEngineConfig::new() .with_threads(args.io_uring_threads) .with_cpus(args.io_uring_cpus.clone()) diff --git a/foyer-storage/Cargo.toml b/foyer-storage/Cargo.toml index b8588738..4d5ddfdb 100644 --- a/foyer-storage/Cargo.toml +++ b/foyer-storage/Cargo.toml @@ -24,6 +24,11 @@ strict_assertions = [ "foyer-common/strict_assertions", "foyer-memory/strict_assertions", ] +# Enable the io_uring based I/O engine. Linux only. +# This feature pulls in the `io-uring` crate, which ships prebuilt syscall +# bindings only for a limited set of architectures. Disable this feature to +# build foyer on architectures unsupported by `io-uring` (e.g. armv7). +io_uring = ["dep:io-uring", "dep:core_affinity"] [dependencies] allocator-api2 = { workspace = true } @@ -53,8 +58,8 @@ twox-hash = { workspace = true, features = ["xxhash32", "xxhash64"] } zstd = { workspace = true } [target.'cfg(target_os = "linux")'.dependencies] -core_affinity = { workspace = true } -io-uring = { workspace = true } +core_affinity = { workspace = true, optional = true } +io-uring = { workspace = true, optional = true } [dev-dependencies] bytesize = { workspace = true } diff --git a/foyer-storage/src/io/engine/mod.rs b/foyer-storage/src/io/engine/mod.rs index a67c110c..a90971b4 100644 --- a/foyer-storage/src/io/engine/mod.rs +++ b/foyer-storage/src/io/engine/mod.rs @@ -16,7 +16,7 @@ pub mod monitor; pub mod noop; pub mod psync; -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", feature = "io_uring"))] pub mod uring; use std::{ @@ -132,7 +132,7 @@ mod tests { use super::*; #[cfg(not(madsim))] - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", feature = "io_uring"))] use crate::io::engine::uring::UringIoEngineConfig; use crate::io::{ bytes::IoSliceMut, @@ -171,7 +171,7 @@ mod tests { let dir = tempdir().unwrap(); #[cfg(not(madsim))] - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", feature = "io_uring"))] { let path = dir.path().join("test_file_1"); let device = build_test_file_device(&path).unwrap(); diff --git a/foyer-storage/src/prelude.rs b/foyer-storage/src/prelude.rs index 3b98e1e6..e59dff75 100644 --- a/foyer-storage/src/prelude.rs +++ b/foyer-storage/src/prelude.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", feature = "io_uring"))] pub use crate::io::engine::uring::{UringIoEngine, UringIoEngineConfig}; pub use crate::{ compress::Compression, diff --git a/foyer/Cargo.toml b/foyer/Cargo.toml index 078fcb1b..0a9d9155 100644 --- a/foyer/Cargo.toml +++ b/foyer/Cargo.toml @@ -13,7 +13,14 @@ readme.workspace = true exclude.workspace = true [package.metadata.docs.rs] -features = ["serde", "tracing", "nightly", "deadlock", "strict_assertions"] +features = [ + "serde", + "tracing", + "nightly", + "deadlock", + "strict_assertions", + "io_uring", +] rustdoc-args = ["--cfg", "docsrs"] [package.metadata.cargo-udeps.ignore] @@ -21,7 +28,7 @@ rustdoc-args = ["--cfg", "docsrs"] development = ["jiff"] [features] -default = ["runtime-tokio"] +default = ["runtime-tokio", "io_uring"] clap = ["foyer-storage/clap"] serde = ["foyer-common/serde", "foyer-storage/serde"] nightly = ["foyer-storage/nightly", "foyer-memory/nightly"] @@ -40,6 +47,10 @@ strict_assertions = [ ] runtime-tokio = ["tokio/runtime-tokio"] runtime-madsim-tokio = ["tokio/runtime-madsim-tokio"] +# Enable the io_uring based I/O engine. Linux only. Disable to build on +# architectures where the `io-uring` crate has no prebuilt syscall bindings +# (e.g. armv7). +io_uring = ["foyer-storage/io_uring"] [dependencies] anyhow = { workspace = true } diff --git a/foyer/src/prelude.rs b/foyer/src/prelude.rs index 655e903c..502e5916 100644 --- a/foyer/src/prelude.rs +++ b/foyer/src/prelude.rs @@ -14,7 +14,7 @@ #[cfg(feature = "tracing")] pub use crate::common::tracing::TracingOptions; -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", feature = "io_uring"))] pub use crate::storage::{UringIoEngine, UringIoEngineConfig}; pub use crate::{ common::{