Skip to content

Commit

Permalink
Merge pull request #6 from metaspace/null
Browse files Browse the repository at this point in the history
null_blk: Add description and benchmark results
  • Loading branch information
ojeda authored Sep 14, 2023
2 parents cc01ae2 + a01f13c commit aece235
Show file tree
Hide file tree
Showing 8 changed files with 12,022 additions and 0 deletions.
1 change: 1 addition & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
## Users

- [NVMe Driver](NVMe-driver.md)
- [Null Block Driver](Null-Block-Driver.md)
- [Android Binder Driver](Android-Binder-Driver.md)

# Links
Expand Down
91 changes: 91 additions & 0 deletions src/Null-Block-Driver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

# Null Block Driver

The Rust null block driver `rnull` is an effort to implement a drop in
replacement for `null_blk` in Rust.

A null block driver is a good opportunity to evaluate Rust bindings for the
block layer. It is a small and simple driver and thus should be simple to reason
about. Further, the null block driver is not usually deployed in production
environments. Thus, it should be fairly straight forward to review, and any
potential issues are not going to bring down any production workloads.

Being small and simple, the null block driver is a good place to introduce the
Linux kernel storage community to Rust. This will help prepare the community for
future Rust projects and facilitate a better maintenance process for these
projects.

[Statistics](https://lore.kernel.org/all/[email protected]/) from the
commit log of the [C `null_blk`
driver](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/log/drivers/block/null_blk?h=v6.1)
([before
move](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/log/drivers/block/null_blk_main.c?h=v6.1&id=ea17fd354ca8afd3e8962a77236b1a9a59262fdd))
show that the C null block driver has had a significant amount of memory safety
related problems in the past. 41% of fixes merged for the C null block driver
are fixes for memory safety issues. This makes the null block driver a good
candidate for rewriting in Rust.

The driver is implemented entirely in safe Rust, with all unsafe code fully
contained in the abstractions that wrap the C APIs.

## Features

Implemented features:

- `blk-mq` support
- Direct completion of IO
- Read and write requests
- Optional memory backing

Features available in the C `null_blk` driver that are currently not implemented
in this work:

- Bio-based submission
- NUMA support
- Block size configuration
- Multiple devices
- Dynamic device creation/destruction
- Soft-IRQ and timer mode
- Queue depth configuration
- Queue count configuration
- Discard operation support
- Cache emulation
- Bandwidth throttling
- Per node hctx
- IO scheduler configuration
- Blocking submission mode
- Shared tags configuration (for >1 device)
- Zoned storage support
- Bad block simulation
- Poll queues

## Resources

- [Patches for 6.6](https://github.com/metaspace/linux/tree/null_blk-next-for-6.6)
- [Original RFC Patches](https://github.com/metaspace/linux/tree/null_block-RFC)
- [Mailing List Post](https://lore.kernel.org/all/[email protected]/)

# Performance

## Setup

- 12th Gen Intel(R) Core(TM) i5-12600
- 32 GB DRAM
- 1x INTEL MEMPEK1W016GA (PCIe 3.0 x2)
- Debian Bullseye userspace

## Results

In most cases there is less than 2% difference between the Rust and C drivers.

![](./rnull/read-iops.svg)
![](./rnull/write-iops.svg)
![](./rnull/randread-iops.svg)
![](./rnull/randwrite-iops.svg)
![](./rnull/readwrite-iops.svg)
![](./rnull/randrw-iops.svg)

# Contact

Please contact Andreas Hindborg through
[Zulip](Contact.md#zulip-chat).
Loading

0 comments on commit aece235

Please sign in to comment.