[PATCH 0/3] rust: block: add rbrd, a RAM backed block driver

From: Vitaly Wool

Date: Tue Nov 17 2026 - 18:32:31 EST


This series adds rbrd, a RAM backed block driver written in Rust that
works like brd, together with the Rust abstractions it needs:

1. bio segment iteration and request accessors for blk-mq drivers;
2. reference counting, raw pointer conversions and a bit spinlock in
`page->private` for `Page`;
3. the driver itself, configured through configfs like rnull. Its pages
are kept in a flat array of atomic page pointers, so finding, adding
or removing a page takes no lock.

Unlike brd, rbrd never lets a read and a write copy the same page at
the same time: each copy holds the page's bit spinlock. brd allows
this race, so a read that overlaps a write can return a torn mix of
old and new data. In Rust the race would also be undefined behaviour.

This guarantee has a cost. rbrd is slower than brd, mostly for writes
(4k random O_DIRECT I/O, 8 vCPU guest, mean of 9 runs, kIOPS):

test brd rbrd change
read, 8 threads 2048 2012 -2%
read, 1 thread 512 463 -10%
write, 1 thread 583 470 -19%
write, 4 threads 1693 1472 -13%
write, 8 threads 2004 1563 -22%

We think this is a small price for page integrity: a RAM disk is still
far faster than any real device, and a block device should never
return data that was never written. The gap has not been profiled
yet, so not all of it is necessarily due to the lock. With a single
lock for the whole device instead of one per page, 8-thread reads were
20-28% slower than brd.

The series is based on rust-next (v7.4-rc3). Patches 2 and 3 were
written with the Claude Code AI coding assistant, which also did the
testing.

Igor B (2):
rust: block: add bio segment iteration and request accessors
rust: page: add reference counting, raw pointers and a private bit
lock

Vitaly Wool (1):
rust: block: add rbrd, a RAM backed block driver

MAINTAINERS | 1 +
drivers/block/Kconfig | 1 +
drivers/block/Makefile | 1 +
drivers/block/rbrd/Kconfig | 17 ++
drivers/block/rbrd/Makefile | 2 +
drivers/block/rbrd/configfs.rs | 188 ++++++++++++++
drivers/block/rbrd/rbrd.rs | 420 +++++++++++++++++++++++++++++++
rust/bindings/bindings_helper.h | 1 +
rust/helpers/bit_spinlock.c | 13 +
rust/helpers/blk.c | 14 ++
rust/helpers/helpers.c | 1 +
rust/helpers/page.c | 10 +
rust/kernel/block.rs | 1 +
rust/kernel/block/bio.rs | 253 +++++++++++++++++++
rust/kernel/block/mq.rs | 5 +-
rust/kernel/block/mq/gen_disk.rs | 25 ++
rust/kernel/block/mq/request.rs | 81 +++++-
rust/kernel/page.rs | 160 ++++++++++++
18 files changed, 1192 insertions(+), 2 deletions(-)
create mode 100644 drivers/block/rbrd/Kconfig
create mode 100644 drivers/block/rbrd/Makefile
create mode 100644 drivers/block/rbrd/configfs.rs
create mode 100644 drivers/block/rbrd/rbrd.rs
create mode 100644 rust/helpers/bit_spinlock.c
create mode 100644 rust/kernel/block/bio.rs

--
2.39.5