* [RFC PATCH RESEND 0/3] block: cgroup-based and explicit write stream placement for NVMe FDP
[not found] <CGME20261123051521epcms2p2445107f926f3acaa2d51c5e12abea90e@epcms2p2>
@ 2026-11-23 5:15 ` Suho Son
[not found] ` <CGME20261123051521epcms2p2445107f926f3acaa2d51c5e12abea90e@epcms2p7>
2026-11-23 5:17 ` [RFC PATCH RESEND 2/3] io_uring: add IORING_WRITE_STREAM_DEFAULT for explicit device-default placement Suho Son
1 sibling, 1 reply; 3+ messages in thread
From: Suho Son @ 2026-11-23 5:15 UTC (permalink / raw)
To: axboe, linux-block
Cc: tj, hannes, mkoutny, corbet, skhan, rdunlap, viro, brauner, jack,
io-uring, cgroups, linux-fsdevel, linux-doc, linux-kernel,
ngeol564, KiYoung Lee, JinHeon Kim, Suho Son
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* [RFC PATCH RESEND 1/3] block: distinguish unspecified and explicit device-default write streams
[not found] ` <CGME20261123051521epcms2p2445107f926f3acaa2d51c5e12abea90e@epcms2p7>
@ 2026-11-23 5:16 ` Suho Son
0 siblings, 0 replies; 3+ messages in thread
From: Suho Son @ 2026-11-23 5:16 UTC (permalink / raw)
To: axboe, linux-block
Cc: tj, hannes, mkoutny, corbet, skhan, rdunlap, viro, brauner, jack,
io-uring, cgroups, linux-fsdevel, linux-doc, linux-kernel,
ngeol564, KiYoung Lee, JinHeon Kim, Suho Son
From: Suho Son <suho.son@samsung.com>
bio->bi_write_stream uses zero to mean two different things: "the
issuer did not express a stream" and "place this write in the
device-default stream". With the io_uring per-I/O attribute and the
inode write hint as the only producers this conflation is harmless,
but it prevents a later, lower-precedence producer from telling
whether a stream was requested at all.
Introduce WRITE_STREAM_NONE ((u8)-1) as the "unset" sentinel and
initialize bios with it in bio_init()/bio_reset(). Resolve any
residual sentinel to the device default (0) in
submit_bio_noacct_nocheck(), before the bio can be turned into a
request or merged, so drivers never observe the sentinel regardless
of kernel configuration.
In blkdev_direct_IO(), keep the existing precedence and add the
missing distinction: a concrete stream is validated against the
device limit; otherwise the inode write hint is used if it was
actually set (WRITE_LIFE_NOT_SET no longer maps to stream 0);
otherwise the sentinel is left for later resolution.
Also carry ki_write_stream through kiocb_clone(), which is used by
forwarded direct I/O (fs/backing-file.c, fs/erofs/ishare.c), so a
clone does not silently drop the issuer's stream selection.
No driver changes: NVMe converts bi_write_stream to FDP placement
identifiers as before.
Signed-off-by: Suho Son <suho.son@samsung.com>
---
block/bio.c | 3 ++-
block/blk-core.c | 12 ++++++++++++
block/fops.c | 25 +++++++++++++++++++------
include/linux/blk_types.h | 13 +++++++++++++
include/linux/fs.h | 11 ++++++++++-
5 files changed, 56 insertions(+), 8 deletions(-)
diff --git a/block/bio.c b/block/bio.c
index b0fcc69de6535..0fbf0dfefe85c 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -223,7 +223,7 @@ void bio_init(struct bio *bio, struct block_device *bdev, struct bio_vec *table,
bio->bi_flags = 0;
bio->bi_ioprio = 0;
bio->bi_write_hint = 0;
- bio->bi_write_stream = 0;
+ bio->bi_write_stream = WRITE_STREAM_NONE;
bio->bi_status = 0;
bio->bi_bvec_gap_bit = 0;
bio->bi_iter.bi_sector = 0;
@@ -278,6 +278,7 @@ void bio_reset(struct bio *bio, struct block_device *bdev, blk_opf_t opf)
bio_uninit(bio);
memset(bio, 0, BIO_RESET_BYTES);
atomic_set(&bio->__bi_remaining, 1);
+ bio->bi_write_stream = WRITE_STREAM_NONE;
bio->bi_io_vec = bv;
bio->bi_bdev = bdev;
if (bio->bi_bdev)
diff --git a/block/blk-core.c b/block/blk-core.c
index 2ee079c1ce150..5054a6e21020c 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -765,6 +765,18 @@ void submit_bio_noacct_nocheck(struct bio *bio, bool split)
blk_cgroup_bio_start(bio);
+ /*
+ * Resolve the write-stream sentinel before the bio can be turned into
+ * a request or merged. By now every higher-precedence producer has had
+ * its chance (an io_uring per-I/O attribute at init time, io.stream via
+ * bio_set_ioprio()); a field still holding WRITE_STREAM_NONE expressed
+ * no stream, so it falls back to the device default (0). This is the
+ * single point that guarantees the sentinel never reaches the driver,
+ * independent of CONFIG_BLK_CGROUP_IOSTREAM.
+ */
+ if (bio->bi_write_stream == WRITE_STREAM_NONE)
+ bio->bi_write_stream = 0;
+
if (!bio_flagged(bio, BIO_TRACE_COMPLETION)) {
trace_block_bio_queue(bio);
/*
diff --git a/block/fops.c b/block/fops.c
index a0ccadaa9c79d..4dab46da49032 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -417,20 +417,33 @@ static ssize_t blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
if (iov_iter_rw(iter) == WRITE) {
u16 max_write_streams = bdev_max_write_streams(bdev);
- if (iocb->ki_write_stream) {
+ if (iocb->ki_write_stream &&
+ iocb->ki_write_stream != WRITE_STREAM_NONE) {
if (iocb->ki_write_stream > max_write_streams)
return -EINVAL;
- } else if (max_write_streams) {
+ } else if (max_write_streams &&
+ !(iocb->ki_flags & IOCB_WRITE_STREAM_EXPLICIT)) {
enum rw_hint write_hint =
file_inode(iocb->ki_filp)->i_write_hint;
/*
- * Just use the write hint as write stream for block
- * device writes. This assumes no file system is
- * mounted that would use the streams differently.
+ * No concrete stream was expressed on this I/O and
+ * the issuer did not request the device default
+ * explicitly either (in which case the concrete
+ * stream 0 is kept so neither the inode write hint
+ * nor a cgroup io.stream value applies). Use the
+ * inode write hint as the write stream for block
+ * device writes (this assumes no file system is
+ * mounted that would use the streams differently);
+ * otherwise leave the field as WRITE_STREAM_NONE so a
+ * lower-precedence producer (io.stream) can fill it
+ * in at submit time.
*/
- if (write_hint <= max_write_streams)
+ if (write_hint != WRITE_LIFE_NOT_SET &&
+ write_hint <= max_write_streams)
iocb->ki_write_stream = write_hint;
+ else
+ iocb->ki_write_stream = WRITE_STREAM_NONE;
}
}
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index 1a5812fa40529..016707437702f 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -203,6 +203,19 @@ typedef __u32 __bitwise blk_opf_t;
typedef unsigned int blk_qc_t;
#define BLK_QC_T_NONE -1U
+/*
+ * Sentinel value for bi_write_stream / ki_write_stream meaning "no write
+ * stream expressed". Distinguished from an explicit request for the
+ * device-default stream (0): a concrete stream set by an issuer (e.g. an
+ * io_uring per-I/O write attribute) always wins, while a field still holding
+ * WRITE_STREAM_NONE lets a lower-precedence producer (io.stream) fill it in.
+ * The submit path converts any residual WRITE_STREAM_NONE to 0 before the bio
+ * reaches the driver. Both fields are u8, so the sentinel is (u8)-1 = 255;
+ * kernel interfaces limit selectable stream identifiers to 0..254, so the
+ * sentinel never collides with a stream an issuer can request.
+ */
+#define WRITE_STREAM_NONE ((u8)-1)
+
/*
* main unit of I/O for the block layer and lower layers (ie drivers and
* stacking drivers)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 99caef43ff3c4..e796a1858e187 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -357,6 +357,13 @@ struct readahead_control;
/* kiocb is a read or write operation submitted by fs/aio.c. */
#define IOCB_AIO_RW (1 << 22)
#define IOCB_HAS_METADATA (1 << 23)
+/*
+ * The issuer explicitly requested the device-default write stream
+ * (IORING_WRITE_STREAM_DEFAULT in the io_uring SQE): ki_write_stream
+ * holds a concrete 0 and must not be overridden by the inode write hint
+ * or a cgroup io.stream value.
+ */
+#define IOCB_WRITE_STREAM_EXPLICIT BIT(24)
/* for use in trace events */
#define TRACE_IOCB_STRINGS \
@@ -374,7 +381,8 @@ struct readahead_control;
{ IOCB_NOIO, "NOIO" }, \
{ IOCB_ALLOC_CACHE, "ALLOC_CACHE" }, \
{ IOCB_AIO_RW, "AIO_RW" }, \
- { IOCB_HAS_METADATA, "AIO_HAS_METADATA" }
+ { IOCB_HAS_METADATA, "AIO_HAS_METADATA" }, \
+ { IOCB_WRITE_STREAM_EXPLICIT, "WRITE_STREAM_EXPLICIT" }
struct kiocb {
struct file *ki_filp;
@@ -2202,6 +2210,7 @@ static inline void kiocb_clone(struct kiocb *kiocb, struct kiocb *kiocb_src,
.ki_filp = filp,
.ki_flags = kiocb_src->ki_flags,
.ki_ioprio = kiocb_src->ki_ioprio,
+ .ki_write_stream = kiocb_src->ki_write_stream,
.ki_pos = kiocb_src->ki_pos,
};
}
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [RFC PATCH RESEND 2/3] io_uring: add IORING_WRITE_STREAM_DEFAULT for explicit device-default placement
[not found] <CGME20261123051521epcms2p2445107f926f3acaa2d51c5e12abea90e@epcms2p2>
2026-11-23 5:15 ` [RFC PATCH RESEND 0/3] block: cgroup-based and explicit write stream placement for NVMe FDP Suho Son
@ 2026-11-23 5:17 ` Suho Son
1 sibling, 0 replies; 3+ messages in thread
From: Suho Son @ 2026-11-23 5:17 UTC (permalink / raw)
To: axboe, linux-block
Cc: tj, hannes, mkoutny, corbet, skhan, rdunlap, viro, brauner, jack,
io-uring, cgroups, linux-fsdevel, linux-doc, linux-kernel,
ngeol564, KiYoung Lee, JinHeon Kim, Suho Son
From: Suho Son <suho.son@samsung.com>
Add a reserved sqe->write_stream value, IORING_WRITE_STREAM_DEFAULT
((__u8)-1), that explicitly requests the device-default stream for a
write. Unlike an omitted (zero) stream, which lets the kernel derive
one from the inode write hint or, with the cgroup policy added later
in this series, a per-cgroup io.stream value, the reserved value pins
the write to the device default and suppresses both.
The value is translated once in __io_prep_rw() into a request flag
(REQ_F_STREAM_DEFAULT); io_rw_init_file() then converts it into a
concrete stream 0 plus IOCB_WRITE_STREAM_EXPLICIT. Deciding at prep
time is required for re-issues, where ki_write_stream has already
been rewritten to zero, so the selection survives kiocb
reinitialization and IOSQE_ASYNC deferral.
The reservation is visible in the UAPI: 255 previously failed
validation with -EINVAL on any real device, so no working application
regresses, but a hypothetical device advertising more than 254
streams can no longer have its stream 255 selected through this
interface.
Signed-off-by: Suho Son <suho.son@samsung.com>
---
include/linux/io_uring_types.h | 4 ++++
include/uapi/linux/io_uring.h | 26 ++++++++++++++++++++++++++
io_uring/rw.c | 16 ++++++++++++++++
3 files changed, 46 insertions(+)
diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h
index 1468bcb028930..550928cd4ad95 100644
--- a/include/linux/io_uring_types.h
+++ b/include/linux/io_uring_types.h
@@ -622,6 +622,8 @@ enum {
REQ_F_SQE_COPIED_BIT,
REQ_F_IOPOLL_BIT,
REQ_F_DMABUF_BIT,
+ /* sqe->write_stream is IORING_WRITE_STREAM_DEFAULT */
+ REQ_F_STREAM_DEFAULT_BIT,
/* not a real bit, just to check we're not overflowing the space */
__REQ_F_LAST_BIT,
@@ -719,6 +721,8 @@ enum {
REQ_F_IOPOLL = IO_REQ_FLAG(REQ_F_IOPOLL_BIT),
/* there is a dma map attached to request that needs to be dropped */
REQ_F_DMABUF = IO_REQ_FLAG(REQ_F_DMABUF_BIT),
+ /* sqe->write_stream was IORING_WRITE_STREAM_DEFAULT (see io_rw_init_file()) */
+ REQ_F_STREAM_DEFAULT = IO_REQ_FLAG(REQ_F_STREAM_DEFAULT_BIT),
};
struct io_tw_req {
diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index cf1afd11bb871..3ae504d9ec1a0 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -122,6 +122,32 @@ struct io_uring_sqe {
/* sqe->attr_type_mask flags */
#define IORING_RW_ATTR_FLAG_PI (1U << 0)
+/*
+ * sqe->write_stream reserved value for explicitly requesting the
+ * device-default write stream.
+ *
+ * sqe->write_stream carries a per-I/O write stream identifier for write
+ * requests to block devices that support write streams (e.g. NVMe FDP):
+ *
+ * 0 the issuer does not express a stream; the kernel may
+ * then derive one from the file's write lifetime hint
+ * or, if configured, from the cgroup's io.stream
+ * policy.
+ * 1..max an explicit stream identifier, validated against the
+ * device's max_write_streams.
+ * 255 (below) an explicit request for the device-default stream.
+ * This overrides both the inode write hint and any
+ * cgroup io.stream value: the I/O is placed as if no
+ * stream had been requested by anyone.
+ *
+ * Any other value above the device's max_write_streams is rejected with
+ * -EINVAL, as before. Note that a value of 255 can therefore no longer
+ * select stream 255 on a hypothetical device offering that many streams;
+ * the bio-level write stream field uses 255 as its "unset" sentinel, so
+ * stream identifiers are effectively limited to 1..254 through this
+ * interface.
+ */
+#define IORING_WRITE_STREAM_DEFAULT ((__u8)-1)
/* PI attribute information in sqe->attr_ptr for IORING_RW_ATTR_FLAG_PI: */
struct io_uring_attr_pi {
__u16 flags;
diff --git a/io_uring/rw.c b/io_uring/rw.c
index 3ecb842147a4d..d1d154533bf14 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -273,6 +273,8 @@ static int __io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe,
}
rw->kiocb.ki_flags = 0;
rw->kiocb.ki_write_stream = READ_ONCE(sqe->write_stream);
+ if (rw->kiocb.ki_write_stream == IORING_WRITE_STREAM_DEFAULT)
+ io_req_set_flags(req, REQ_F_STREAM_DEFAULT);
if (req->ctx->flags & IORING_SETUP_IOPOLL)
rw->kiocb.ki_complete = io_complete_rw_iopoll;
@@ -851,6 +853,20 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode, int rw_type)
if (unlikely(ret))
return ret;
+ /*
+ * IORING_WRITE_STREAM_DEFAULT is an explicit request for the
+ * device-default stream: carry it as a concrete stream 0 plus a
+ * marker, so neither the inode write hint nor a cgroup io.stream
+ * value can override the issuer's choice. The request flag is set
+ * once at prep time and survives the ki_flags reinitialization
+ * above as well as async re-issues, where ki_write_stream has
+ * already been rewritten to 0.
+ */
+ if (req->flags & REQ_F_STREAM_DEFAULT) {
+ kiocb->ki_write_stream = 0;
+ kiocb->ki_flags |= IOCB_WRITE_STREAM_EXPLICIT;
+ }
+
/*
* If the file is marked O_NONBLOCK, still allow retry for it if it
* supports async. Otherwise it's impossible to use O_NONBLOCK files
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-23 5:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CGME20261123051521epcms2p2445107f926f3acaa2d51c5e12abea90e@epcms2p2>
2026-11-23 5:15 ` [RFC PATCH RESEND 0/3] block: cgroup-based and explicit write stream placement for NVMe FDP Suho Son
[not found] ` <CGME20261123051521epcms2p2445107f926f3acaa2d51c5e12abea90e@epcms2p7>
2026-11-23 5:16 ` [RFC PATCH RESEND 1/3] block: distinguish unspecified and explicit device-default write streams Suho Son
2026-11-23 5:17 ` [RFC PATCH RESEND 2/3] io_uring: add IORING_WRITE_STREAM_DEFAULT for explicit device-default placement Suho Son
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®