ironspdk
Rust runtime for SPDK. Write high-performance usermode storage drivers in Rust.
A cutting-edge Rust runtime that brings the power of modern async/await to SPDK (Storage Performance Development Kit). Build block devices and storage modules with the safety and productivity of Rust, while maintaining C-level performance.
Overview
ironspdk is an innovative framework that bridges the gap between Rust's memory safety and the raw performance of SPDK. Instead of struggling with C callbacks and manual memory management, you can now write storage drivers using idiomatic Rust with futures, channels, and all the ergonomic benefits Rust provides.
Key Features
🦀 Idiomatic Rust Programming Model
- No callback hell: Use Rust's async/await syntax and futures for natural asynchronous I/O handling
- Memory safety: Leverage Rust's ownership and borrowing system to prevent data races and memory bugs
- Type safety: Compile-time guarantees replace runtime errors
⚡ SPDK Integration
- Full SPDK primitives support: SPDK lightweight threads, I/O channels, block device descriptors, and more are exposed to Rust
- Tight runtime integration: The
ironspdkruntime executor extends the SPDK poller, allowing Rust code to seamlessly integrate with the SPDK event loop - Zero-copy I/O: Work directly with SPDK I/O vectors and DMA buffers
- Thread-safe operations: The Rust type system enforces SPDK's multiple-threads-no-locks programming model at compile time
🚀 Performance
- C-level performance: No runtime overhead - compiled to native code with optimizations
- Lock-free design: Leverages SPDK's thread-per-core architecture
- Direct FFI binding: Minimal abstraction over underlying SPDK C APIs
📦 Comprehensive I/O Abstractions
- Multiple I/O models: Support for I/O references (
IoRef), buffered I/O (IoBuf), and unifiedIoenum - I/O splitting: Advanced utilities for splitting and reordering I/O operations
- DMA buffers: First-class support for aligned DMA memory allocation and management
- Block device abstraction: Simple trait-based interface for implementing custom block devices
Architecture
Core Components
ironspdk-sys/ # Low-level C FFI bindings to SPDK
ironspdk/ # High-level Rust runtime and abstractions
├── app.rs # SpdkApp lifecycle management
├── lib.rs # Core types: Bdev, IoRef, IoBuf, SpdkThread, Tcb
├── c.rs # C FFI wrappers
├── c_enum.rs # Enum conversions
└── rpc.rs # RPC command registration
examples/raid1/ # Simple RAID1 implementation example
Runtime Executor
The ironspdk runtime leverages SPDK's poller mechanism:
- Task Control Block (Tcb): Manages async task execution on each SPDK thread
- Task scheduler: Queues and polls futures
- I/O channel management: Tracks and manages block device I/O channels per thread
- Waker integration: Custom waker implementation to notify tasks in runqueue
Usage
Basic Setup
Add to your Cargo.toml:
[]
= "1.2.56"
= "0.1"
[]
= "0.1"
= "0.1"
Create a Simple Block Device
use ;
Build & Run
# Set up environment
# Build
# Run with specific CPU cores (0xf = cores 0-3)
Examples
RAID1 Block Device
The repository includes a simple yet functional RAID1 implementation (examples/raid1/). This example demonstrates:
- Mirroring I/O across two backend block devices
- Handling read/write operations
- RPC-based management interface
Compare with SPDK's C implementation: The Rust version is significantly more concise and readable, while maintaining identical performance.
Running the RAID1 Example
# Terminal 1: Start the RAID1 driver
SPDK=/path/to/built/spdk/
PKG_CONFIG_PATH=/build/lib/pkgconfig/
# run RAID1 usermode driver example at 4 CPU cores
# Terminal 2: Create backend devices
SPDK=/path/to/built/spdk/
# Create RAID1 instance
# Export via ublk and benchmark with fio
# Run I/O benchmark
TIME=30
# Cleanup
API Overview
Core Types
SpdkApp
Main application entry point. Manages SPDK initialization, thread creation, and lifecycle.
let mut app = new;
app.on_start;
app.on_shutdown;
app.run?;
SpdkThread
Wrapper around SPDK threads. Enables spawning async tasks and inter-thread communication.
// create new SPDK thread at core 2
let thread = new_at_cores;
// run some code at this SPDK thread
thread.spawn;
// stop SPDK threads this way only
thread.request_exit;
Bdev (Trait)
Implement this trait to create custom block devices.
BdevIo
Represents a single I/O request. Provides access to request metadata and completion mechanism.
Io<'a> (Enum)
Unified interface for working with I/O data. Can be either a reference to SPDK I/O vectors or a buffered copy.
DmaBuf
DMA-allocated memory buffer with Send+Sync support for thread-safe sharing.
Lbdev
Client API for accessing lower-layer SPDK block devices.
Error Handling
All fallible operations return Result<T, Error>. The Error enum covers common SPDK scenarios:
Requirements
- Rust: 1.70+
- SPDK: Built and configured (see SPDK documentation), version v26.01 is supported
- Linux: confirmed support at 6.17+ kernels
- Privileges: Most operations require superuser access for hardware access and memory management
Performance Characteristics
- Latency: Microsecond-scale I/O latency (same as C SPDK)
- Throughput: Limited only by underlying hardware (no Rust overhead)
- CPU efficiency: Lock-free design with thread-per-core scaling
- Memory: Minimal overhead compared to C implementation
Licensing
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- BSD 3-Clause License (LICENSE-BSD-3-Clause)
at your option.
Contributing
Contributions are welcome! Please:
- Ensure all tests pass:
cargo test - Format code:
cargo fmt -- - Run clippy:
cargo clippy --locked --all --all-targets --tests -- -D warnings - Document public APIs
- Add tests for new functionality
Getting Help
- SPDK Documentation: https://spdk.io/doc/
- Rust async/await: https://rust-lang.github.io/async-book/
- Repository Issues: Open an issue on GitHub for bugs or feature requests
Roadmap
- More public API documentation
- Documentation at docs.rs
- Test coverage (cargo test)
- Additional block device examples (encryption, RAID5)
- T10 PI (DIF/DIX) support
- SPDK bdev resizing support
- Performance profiling tools
- Higher-level storage abstractions
- FreeBSD support
Related or Similar Projects
- SPDK - Storage Performance Development Kit
- Tokio - Async Rust runtime
- Rust for Linux - Bringing Rust to kernel space