[PATCH 0/2] Support for Multiple Atomicity Mode

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


NVMe has 2 atomic modes: Single Atomicity Mode (SAM) and Multiple
Atomicity Mode (MAM). In SAM mode, as per spec, commands that cross
the atomic boundaries may or may not be guaranteed to be atomic. In MAM
mode, commands that cross the atomic boundaries will be guaranteed to
be atomic at the LBA subrange atomic boundaries, resulting in multiple
atomic operations.

This series adds a new block layer feature BLK_FEAT_ATOMIC_WRITE_MULTI
that gets enabled when an NVMe controller exposes MAM guarantees. In
this case, and when the block IO requests are SAM compliant, allow
the block layer to merge atomic command requests that are contiguous
in the LBA ranges, leveraging block plug-merge infra, and effectively
increasing the size of the command up to the maximum hardware
capabilities. The merged command is not atomic as a whole, so it becomes
a carrier of multiple atomic commands. This is possible because the
RWF_ATOMIC that the user has requested is honored at the LBA subrange
later at the controller side when the carrier command is split at the
atomic boundaries.

MAM QEMU NVMe series [1] covers emulation functionality for testing.

How to expose MAM to users is left as follow-up. Early suggestions can
be found in the RFC [2].

I've also tested on hardware with MAM support, with fio sequential
atomic writes of 16 KiB through io_uring:

fio --name=atomic-write-max --filename=/dev/nvme0n1 \
  --rw=write --bs=16k \
  --ioengine=io_uring \
  --iodepth=$((16 * D)) --iodepth_batch_submit=16 \
  --iodepth_batch_complete_min=16 \
  --atomic=1 --direct=1 \
  --time_based --ramp_time=10 --runtime=120 \
  --numjobs=N

* Merged atomics have now parity with plain writes: throughput, latency
and command count.
* Fewer commands for the same amount of data. E.g. 16x with 256 KiB
commands.
* +1.6% throughput when the link is not saturated (1 job, 2 CPUs).
* Up to +0.6% throughput when the link is saturated (48 jobs).
* p99 latency at least 2.3x lower at queue depth 4 and up.
* 36% less CPU time at queue depth 16, mostly from interrupt handling.
* No change for plain writes, or for atomic writes that do not merge.

Command line logs covering functionality with nvme-cli, fio and
blktrace:

nvme id-ns -H /dev/nvme0n1
NVME Identify Namespace 1:
{..}
nsfeat  : 0x76
  [7:7] : 0     NPRG, NPRA and NORS are Not Supported
  [6:6] : 0x1   Multiple Atomicity Mode applies to write operations
  [5:4] : 0x3   NPWG, NPWA, NPDG, NPDGL, NPDA, and NOWS are Supported
{..}

Sequential atomic write workflows can benefit from the block layer
plug-merge as the following fio atomic write workload:

fio --name=atomic-merge --filename=/dev/nvme0n1 \
  --rw=write --bs=16k --size=64k \
  --ioengine=io_uring \
  --iodepth=4 --iodepth_batch_submit=4 \
  --atomic=1 --direct=1

The output below from btrace confirms the merging results into one
single command:

btrace /dev/nvme0n1
259,2    3        1     0.000000000  2725  Q  WS 0 + 32 [fio]
259,2    3        2     0.000003450  2725  G  WS 0 + 32 [fio]
259,2    3        3     0.000004250  2725  P   N [fio]
259,2    3        4     0.000005440  2725  Q  WS 32 + 32 [fio]
259,2    3        5     0.000006400  2725  M  WS 32 + 32 [fio]
259,2    3        6     0.000007360  2725  Q  WS 64 + 32 [fio]
259,2    3        7     0.000007490  2725  M  WS 64 + 32 [fio]
259,2    3        8     0.000008340  2725  Q  WS 96 + 32 [fio]
259,2    3        9     0.000008460  2725  M  WS 96 + 32 [fio]
259,2    3       10     0.000009270  2725  U   N [fio] 1
259,2    3       11     0.000013460  2725  D  WS 0 + 128 [fio]
259,2    3       12     0.000239642     0  C  WS 0 + 128 [0]

Also tested with QEMU [1], with and without multipath. Under multipath,
the four writes of the fio atomic-merge job above reach one path as a
single command, as on a single-path namespace:

  /sys/block/nvme2c2n1/stat writes=1 merges=3

Link: https://lore.kernel.org/all/20260825-nvme-mam-v1-0-afc38ac713ef@samsung.com/ [1]

Signed-off-by: Daniel Gomez <da.gomez at samsung.com>
---
Changes in v1:
- Drop RFC and update cover letter as well as commit messages.
- block: say what REQ_ATOMIC means on a merged request (Arthur).
- block: add queue/atomic_write_multi (Arthur).
- nvme: set the flag on the multipath head.
- nvme: validate each bio of a merged request (Arthur).
- nvme: require NABSN, NAWUN, NABSPF and NAWUPF alike (Arthur).
- nvme: warn for each namespace, with the four values (Arthur).
- Link to RFC: https://patch.msgid.link/20260929-nvme-mam-v1-0-48dcbe79cece@samsung.com [2]

---
Daniel Gomez (2):
      block: add BLK_FEAT_ATOMIC_WRITE_MULTI
      nvme: enable multiple atomicity mode

 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 ++-
 drivers/nvme/host/core.c             | 74 ++++++++++++++++++++++++++++++------
 include/linux/blk_types.h            |  2 +-
 include/linux/blkdev.h               |  7 ++++
 include/linux/nvme.h                 |  1 +
 9 files changed, 104 insertions(+), 16 deletions(-)
---
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
change-id: 20260929-nvme-mam-073f2ed13bdc

Best regards,
--  
Daniel Gomez <da.gomez at samsung.com>




More information about the Linux-nvme mailing list