Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] rust: block: add rbrd, a RAM backed block driver
@ 2026-12-02  7:17 Vitaly Wool
  2026-12-02  7:17 ` [PATCH v2 1/2] rust: page: add guarded pages Vitaly Wool
  2026-12-02  7:17 ` [PATCH v2 2/2] rust: block: add rbrd, a RAM backed block driver Vitaly Wool
  0 siblings, 2 replies; 4+ messages in thread
From: Vitaly Wool @ 2026-12-02  7:17 UTC (permalink / raw)
  To: Jens Axboe, Andreas Hindborg
  Cc: Boqun Feng, Miguel Ojeda, Gary Guo, Björn Roy Baron,
	Benno Lossin, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
	Onur Özkan, Lorenzo Stoakes, Liam R. Howlett, linux-kernel,
	linux-block, rust-for-linux, linux-mm, Vitaly Wool

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

1) a `Guarded` page kind: a reference counted page whose data is only
   accessed under a bit spinlock in `page->private`. A guard gives
   access to the page data as a byte slice while the lock is held, and
   `try_get_raw()` takes a speculative reference for lock-free lookups;
2) 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 costs very littlei now. Under parallel load rbrd matches
brd: with 16 or more threads, writes run at 98-100% of brd's rate, and
64k I/O runs at 99-103% (O_DIRECT, 1 GiB device, 24 vCPU KVM guest on
a Xeon host pinned to one NUMA node, both drivers on the same kernel,
median of 3 boots, kIOPS):

  test                   brd    rbrd   rbrd/brd
  write 4k, 16 threads  5572    5468     98%
  write 4k, 48 threads  5444    5333     98%
  randwrite 4k, 24 thr  5797    5789    100%
  randwrite 4k, 48 thr  5727    5735    100%
  read 64k, 24 threads   264     270    102%
  read 64k, 48 threads   262     266    102%
  write 64k, 24 threads  258     259    101%
  randwrite 64k, 24 thr  263     270    103%

rbrd was stress tested with data verification on 4k and 512-byte
block devices while a third device was created, used and removed in a
loop, on a normal kernel and on a KASAN, lockdep and kmemleak build:
no errors, no leaks and a clean dmesg. The Rust doctests, including
the new `alloc_guarded()` example, pass.

Changes since v1:
- Rebased onto rnull-v7.4-rc2, which provides bio segment iteration
  and request accessors.
- The per-page locking is replaced by a new `Guarded` page kind:
  a reference counted page whose data is only accessed under a bit
  spinlock in `page->private`. A `Page<Guarded>` only dereferences to
  `Page<Base>`, so safe code cannot reach its data in other ways.
  The lock guard exposes the page data as `&[u8]` / `&mut [u8]`.
- rbrd copies with the `Segment` read/write API, reads unwritten
  sectors from a zeroed page and allocates zeroed pages with
  `Page::alloc_guarded()`.

The series is based on rnull-v7.4-rc2 from Andreas' tree [1].

Igor Belousov (1):
  rust: page: add guarded pages

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 | 192 +++++++++++++
 drivers/block/rbrd/rbrd.rs     | 473 +++++++++++++++++++++++++++++++++
 rust/helpers/bit_spinlock.c    |  13 +
 rust/helpers/helpers.c         |   1 +
 rust/helpers/page.c            |   5 +
 rust/kernel/page.rs            | 235 ++++++++++++++++
 11 files changed, 941 insertions(+)
 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


base-commit: 9c0fceca4feed5f1056f55abe9c7c70731402776
--
2.39.5
[1] https://github.com/metaspace/linux



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-03  7:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02  7:17 [PATCH v2 0/2] rust: block: add rbrd, a RAM backed block driver Vitaly Wool
2026-12-02  7:17 ` [PATCH v2 1/2] rust: page: add guarded pages Vitaly Wool
2026-12-02  7:17 ` [PATCH v2 2/2] rust: block: add rbrd, a RAM backed block driver Vitaly Wool
2026-12-03  7:17   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox