[PATCH 1/2] block: add BLK_FEAT_ATOMIC_WRITE_MULTI

Daniel Gomez da.gomez at kernel.org
Thu Dec 3 10:56:20 PST 2026


From: Daniel Gomez <da.gomez at samsung.com>

Add a feature flag that allows the block layer to merge atomic write
commands into larger ones that are not atomic as a whole but are later
divided by the device at the atomic write boundaries, with each subrange
treated as atomic. NVMe calls this Multiple Atomicity Mode (MAM).

When the flag is set, stop limiting merged atomic writes at
the atomic write boundary and cap them at max(max_sectors,
atomic_write_max_sectors). Each individual atomic write still fits one
boundary window and every window is written atomically by the device, so
each merged write stays untorn.

The feature flag can only be enabled when an atomic write boundary
is set.

Show it as queue/atomic_write_multi, so users can tell whether atomic
writes merge across the boundary.

No consumer yet, so no behavior changes.

Signed-off-by: Daniel Gomez <da.gomez at samsung.com>
---
 Documentation/ABI/stable/sysfs-block | 13 ++++++++++++-
 block/blk-merge.c                    |  9 ++++++++-
 block/blk-settings.c                 |  5 +++++
 block/blk-sysfs.c                    |  3 +++
 block/blk.h                          |  6 +++++-
 include/linux/blk_types.h            |  2 +-
 include/linux/blkdev.h               |  7 +++++++
 7 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/Documentation/ABI/stable/sysfs-block b/Documentation/ABI/stable/sysfs-block
index 900b3fc4c72d0..19d9c250371f2 100644
--- a/Documentation/ABI/stable/sysfs-block
+++ b/Documentation/ABI/stable/sysfs-block
@@ -72,7 +72,18 @@ Description:
 		power-of-two and at least the size as in
 		atomic_write_unit_max_bytes.
 		Any attempt to merge atomic write I/Os must not result in a
-		merged I/O which crosses this boundary (if any).
+		merged I/O which crosses this boundary (if any), unless
+		atomic_write_multi is 1.
+
+
+What:		/sys/block/<disk>/queue/atomic_write_multi
+Date:		November 2026
+Contact:	Daniel Gomez <da.gomez at samsung.com>
+Description:
+		[RO] 1 if the device writes each atomic write boundary window
+		of an I/O atomically. Contiguous atomic writes may then be
+		merged across atomic_write_boundary_bytes. Each write remains
+		atomic, but the merged I/O as a whole does not. 0 otherwise.
 
 
 What:		/sys/block/<disk>/diskseq
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 501ddc01c4499..30c5845dbe558 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -575,7 +575,14 @@ static inline unsigned int blk_rq_get_max_sectors(struct request *rq,
 	struct request_queue *q = rq->q;
 	struct queue_limits *lim = &q->limits;
 	unsigned int max_sectors, boundary_sectors;
-	bool is_atomic = rq->cmd_flags & REQ_ATOMIC;
+	/*
+	 * The merged command is itself one atomic write and must not cross the
+	 * atomic write boundary. But in the BLK_FEAT_ATOMIC_WRITE_MULTI case,
+	 * the device writes each boundary window atomically, so its merged
+	 * commands are not atomic as a whole and may cross the boundary.
+	 */
+	bool is_atomic = (rq->cmd_flags & REQ_ATOMIC) &&
+			 !(lim->features & BLK_FEAT_ATOMIC_WRITE_MULTI);
 
 	if (blk_rq_is_passthrough(rq))
 		return q->limits.max_hw_sectors;
diff --git a/block/blk-settings.c b/block/blk-settings.c
index 1f5ee2453269f..f0488dedb0b80 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -309,6 +309,10 @@ static void blk_validate_atomic_write_limits(struct queue_limits *lim)
 
 	boundary_sectors = lim->atomic_write_hw_boundary >> SECTOR_SHIFT;
 
+	if (WARN_ON_ONCE((lim->features & BLK_FEAT_ATOMIC_WRITE_MULTI) &&
+			 !boundary_sectors))
+		lim->features &= ~BLK_FEAT_ATOMIC_WRITE_MULTI;
+
 	if (boundary_sectors) {
 		if (WARN_ON_ONCE(lim->atomic_write_hw_max >
 				 lim->atomic_write_hw_boundary))
@@ -333,6 +337,7 @@ static void blk_validate_atomic_write_limits(struct queue_limits *lim)
 	return;
 
 unsupported:
+	lim->features &= ~BLK_FEAT_ATOMIC_WRITE_MULTI;
 	lim->atomic_write_max_sectors = 0;
 	lim->atomic_write_boundary_sectors = 0;
 	lim->atomic_write_unit_min = 0;
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 520972676ab46..f92de9ad86ec5 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -369,6 +369,7 @@ static ssize_t queue_##_name##_show(struct gendisk *disk, char *page)	\
 
 QUEUE_SYSFS_FEATURE_SHOW(fua, BLK_FEAT_FUA);
 QUEUE_SYSFS_FEATURE_SHOW(dax, BLK_FEAT_DAX);
+QUEUE_SYSFS_FEATURE_SHOW(atomic_write_multi, BLK_FEAT_ATOMIC_WRITE_MULTI);
 
 static ssize_t queue_poll_show(struct gendisk *disk, char *page)
 {
@@ -637,6 +638,7 @@ QUEUE_LIM_RO_ENTRY(queue_atomic_write_boundary_sectors,
 		"atomic_write_boundary_bytes");
 QUEUE_LIM_RO_ENTRY(queue_atomic_write_unit_max, "atomic_write_unit_max_bytes");
 QUEUE_LIM_RO_ENTRY(queue_atomic_write_unit_min, "atomic_write_unit_min_bytes");
+QUEUE_LIM_RO_ENTRY(queue_atomic_write_multi, "atomic_write_multi");
 
 QUEUE_RO_ENTRY(queue_write_same_max, "write_same_max_bytes");
 QUEUE_LIM_RO_ENTRY(queue_max_write_zeroes_sectors, "write_zeroes_max_bytes");
@@ -757,6 +759,7 @@ static const struct attribute *const queue_attrs[] = {
 	&queue_atomic_write_boundary_sectors_entry.attr,
 	&queue_atomic_write_unit_min_entry.attr,
 	&queue_atomic_write_unit_max_entry.attr,
+	&queue_atomic_write_multi_entry.attr,
 	&queue_max_write_zeroes_sectors_entry.attr,
 	&queue_max_hw_wzeroes_unmap_sectors_entry.attr,
 	&queue_max_wzeroes_unmap_sectors_entry.attr,
diff --git a/block/blk.h b/block/blk.h
index 105fff157bfbd..61e3f918114e8 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -241,8 +241,12 @@ static inline unsigned int blk_queue_get_max_sectors(struct request *rq)
 	if (unlikely(op == REQ_OP_WRITE_ZEROES))
 		return q->limits.max_write_zeroes_sectors;
 
-	if (rq->cmd_flags & REQ_ATOMIC)
+	if (rq->cmd_flags & REQ_ATOMIC) {
+		if (q->limits.features & BLK_FEAT_ATOMIC_WRITE_MULTI)
+			return max(q->limits.max_sectors,
+				   q->limits.atomic_write_max_sectors);
 		return q->limits.atomic_write_max_sectors;
+	}
 
 	return q->limits.max_sectors;
 }
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index 1a5812fa40529..2a006f759dd3b 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -407,7 +407,7 @@ enum req_flag_bits {
 	__REQ_SWAP,		/* swap I/O */
 	__REQ_DRV,		/* for driver use */
 	__REQ_FS_PRIVATE,	/* for file system (submitter) use */
-	__REQ_ATOMIC,		/* for atomic write operations */
+	__REQ_ATOMIC,		/* for atomic write operations or carriers */
 	__REQ_DMABUF,		/* Using premmaped dma buffers */
 	/*
 	 * Command specific flags, keep last:
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 215753171cef0..6c6b445bfa381 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -360,6 +360,13 @@ typedef unsigned int __bitwise blk_features_t;
 #define BLK_FEAT_RAID_PARTIAL_STRIPES_EXPENSIVE \
 	((__force blk_features_t)(1u << 15))
 
+/*
+ * Device writes each atomic write boundary window of a command atomically. A
+ * merged REQ_ATOMIC request is then an atomic carrier command: one atomic write
+ * per bio, not atomic as a whole. Needs a non-zero atomic_write_hw_boundary.
+ */
+#define BLK_FEAT_ATOMIC_WRITE_MULTI	((__force blk_features_t)(1u << 16))
+
 /*
  * Flags automatically inherited when stacking limits.
  */

-- 
2.56.1




More information about the Linux-nvme mailing list