Hello,
Resending: my earlier posting of this cover letter went out without
the patches threaded to it. Sorry for the noise.
This RFC proposes an operator- and application-controlled write stream
interface on top of the existing write stream plumbing
(sqe->write_stream, bio->bi_write_stream, and the NVMe FDP placement
translation, which are unchanged by this series):
1/3 block: distinguish unspecified and explicit device-default write streams
2/3 io_uring: add IORING_WRITE_STREAM_DEFAULT for explicit device-default placement
3/3 blk-cgroup: add cgroup-based write stream placement
The series is based on the block tree's for-next branch (see the
base-commit below).
Motivation and background are described in our HotStorage '26 paper:
Link: https://doi.org/10.1145/3837053.3837343
Motivation
NVMe Flexible Data Placement reduces write amplification by grouping
similarly-aged data into per-reclaim-unit placement handles, and the
kernel already lets a single application tag writes through io_uring.
Two gaps remain:
(a) an operator cannot place whole workloads per cgroup without
modifying applications, and
(b) an application cannot force the device-default placement and be
sure that no policy overrides that choice.
The series addresses the root cause shared by both: write stream zero
currently means both "unspecified" and "device default", so lower-
precedence producers cannot tell whether a stream was requested. The
resulting precedence, most specific first, is:
explicit io_uring stream (including DEFAULT)
> inode write hint
> cgroup io.stream
> device default (0)
Patch 1 introduces the WRITE_STREAM_NONE sentinel for unspecified
streams, resolves it centrally before the bio reaches the driver, and
carries ki_write_stream through kiocb_clone() used by forwarded direct
I/O. Patch 2 adds the explicit-default UAPI value, decided at prep
time so it survives async re-issues. Patch 3 adds the io.stream cgroup
v2 interface: per-device upsert entries, "inherit" reset, explicit 0,
validation against device queue limits, lazy policy activation, and a
single-word policy state read locklessly under RCU, with writers
serialized by the queue lock held across blkg_conf_prep().
Runtime verification
We exercised the series, as posted, on an NVMe 2.0 FDP device (8 RUHs)
with bpftrace observers at blkcg_set_iostream() entry/return,
__submit_bio() and the nvme_setup_cmd() dsmgmt export:
- explicit streams 2/5/8 -> placement IDs 1/4/7 (tracepoint-verified)
- IORING_WRITE_STREAM_DEFAULT -> concrete 0, no placement exported,
not overridable by an io.stream policy
- stream > max_write_streams -> -EINVAL, no bio issued
- io.stream explicit value observed end-to-end; nested cgroup
inherits the parent's entry; explicit io.stream 0 resolves the
sentinel to 0
- io.stream rejects streams above the device limit and the reserved
255 with -EINVAL, and devices without write streams with
-EOPNOTSUPP; the root cgroup has no io.stream file
- the inode write hint beats the io.stream value, as documented
- IOSQE_ASYNC: an explicit stream, IORING_WRITE_STREAM_DEFAULT and
the submitting task's cgroup association all survive io-wq
deferral
- a 512K direct write splits into multiple bios; all keep the stream
- 64 concurrent writers with a common stream: 64/64 tagged, stable,
no warnings
- buffered writeback on a mounted ext4: writeback bios adopt the
first-dirtying cgroup via wbc_init_bio() and carry the resulting
placement ID to the device; the nested cgroup inherits the
parent's entry, explicit 0 and the child's own entry override it,
and "inherit" restores the parent's value
Each patch builds without warnings at W=1, with
CONFIG_BLK_CGROUP_IOSTREAM both enabled and disabled.
Not yet verified (please treat accordingly)
- WAF improvements on a production multi-tenant workload are not yet
measured; device-level fdp status counters moved consistently with
the placement IDs, but per-case deltas were below the background
noise of the test setup
RFC aspects we would like feedback on
- the API shape of io.stream (per-device "MAJ:MIN <stream>" string,
upsert and inherit semantics, explicit 0 as a real entry)
- the WRITE_STREAM_NONE sentinel as a u8 reservation, which caps
addressable streams at 254 through the io_uring interface and
excludes 255 from io.stream
- whether io.stream belongs in io.* under cgroup v2, and its
interaction with the existing io controller file hierarchy
- buffered writeback semantics: attribution to the writeback owner is
arguably what an operator wants, but degenerate share cases deserve
a second opinion
No MAINTAINERS update is needed: block/ is covered by the BLOCK LAYER
entry, and the io_uring paths by the IO_URING entry.
Tool use
This series was developed with substantial help from LLM coding
assistants, in an interactive session rather than from a single prompt.
The assistant drafted a large part of the implementation (the
WRITE_STREAM_NONE sentinel and its central resolution, the fops.c
precedence rework, the kiocb_clone() propagation, and the io.stream
single-word policy state and its RCU lifetime), the changelogs, the
cgroup-v2.rst section and this cover letter. It also wrote the
io_uring and bpftrace test harnesses used for the runtime verification
above, and rebased the series onto the current tree. I made the design
decisions, directed and reviewed the testing, and reviewed, revised and
take responsibility for all of the code and text.
Suho Son (3):
block: distinguish unspecified and explicit device-default write
streams
io_uring: add IORING_WRITE_STREAM_DEFAULT for explicit device-default
placement
blk-cgroup: add cgroup-based write stream placement
Documentation/admin-guide/cgroup-v2.rst | 58 ++++-
block/Kconfig | 16 ++
block/Makefile | 1 +
block/bio.c | 3 +-
block/blk-core.c | 14 ++
block/blk-iostream.c | 315 ++++++++++++++++++++++++
block/blk-iostream.h | 18 ++
block/fops.c | 25 +-
include/linux/blk_types.h | 13 +
include/linux/fs.h | 11 +-
include/linux/io_uring_types.h | 4 +
include/uapi/linux/io_uring.h | 26 ++
io_uring/rw.c | 16 ++
13 files changed, 510 insertions(+), 10 deletions(-)
create mode 100644 block/blk-iostream.c
create mode 100644 block/blk-iostream.h
base-commit: d09b6d9d1fcce0770c1824c8b2b8ab153f2672d2
--
2.43.0