[RFC PATCH v2] xfs: add a mount option to force atomic CoW

From: Wayne Gao

Date: Sat Nov 28 2026 - 13:12:55 EST


Comparing hardware-backed and software-backed atomic page writes
requires a predictable way to select each implementation on the same
device and kernel build. Triggering fallback through fragmentation or
misalignment changes the file layout and does not reliably keep later
writes on the software path.

Add a force_atomic_cow mount option to select the existing software
CoW implementation for RWF_ATOMIC writes. Keep hardware-first selection
as the default and leave non-atomic write routing unchanged.

Require software atomic write support and reject attempts to enable
the option through remount or by mounting an existing filesystem
instance again. Changing the policy requires a full unmount and mount.

Report no separate optimized atomic write size while software CoW is
forced, and document the mount option and its restrictions.

Signed-off-by: Wayne Gao <wayne.gao1@xxxxxxxxxxxx>
---
Hi Carlos, Dave, John and Pankaj,

Thank you for the feedback on v1.

This v2 replaces the runtime sysfs interface with a mount-only option.
I realise that Dave's suggestion was to consider configuration at the
block-device layer, not to endorse an XFS mount option. This patch is
therefore an alternative for discussion, not a claim that the layering
question has been resolved.

My use case is test and performance characterisation of fixed-size
database page writes when evaluating RWF_ATOMIC-based torn-page
protection, including potential alternatives to doublewrite and
full-page images. I want to compare the hardware and software atomic
write implementations on the same hardware and kernel build, keeping
request sizes and synchronization policy constant.

The motivation for a non-debug interface is to avoid changing the
kernel build configuration between measurements. It is not a
production requirement to disable working hardware offload.

The current block queue atomic-limit attributes are read-only. I
understand John's concern about changing atomic limits while requests
are in flight. This proposal leaves the advertised device limits
unchanged and fixes XFS's implementation choice for the lifetime of
the filesystem instance.

Feedback on whether this belongs in XFS, at the block/driver layer,
or only in an out-of-tree testing mechanism is welcome.

Changes since v1:
- Replace the runtime sysfs control with a mount-only option.
- Use an XFS mount feature bit instead of a runtime boolean.
- Reject enabling the option on remount or an existing instance.
- Replace the sysfs ABI documentation with mount-option documentation.
- Rebase onto xfs for-next at the base commit listed below.

Validation:
- git diff --check passed.
- checkpatch passed with BIT_MACRO and CAMELCASE excluded to retain
the existing XFS mount-bit and option-naming conventions.
- The exported patch was checked against the local worktree.
- Linux kernel build, mounted-XFS tests and fstests have not been run.

This RFC requests interface and semantic feedback. It does not make
runtime performance claims and is not ready for merging.

v1:
https://lore.kernel.org/linux-xfs/LV0PR10MB997684D5CA8A6AC037F6D1CD8AB9472@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/

Related discussion:
https://lore.kernel.org/linux-xfs/awXuAESDkLr1nd3n@dread/
https://lore.kernel.org/linux-xfs/a337f9fc-b6ef-48c4-ad98-52972b10b4c9@xxxxxxxxx/

Thanks,
Wayne

Documentation/admin-guide/xfs.rst | 28 +++++++++++++++++++++++
fs/xfs/xfs_file.c | 7 +++---
fs/xfs/xfs_iops.c | 4 ++++
fs/xfs/xfs_mount.h | 2 ++
fs/xfs/xfs_super.c | 38 ++++++++++++++++++++++++++++++-
5 files changed, 75 insertions(+), 4 deletions(-)

diff --git a/Documentation/admin-guide/xfs.rst b/Documentation/admin-guide/xfs.rst
index acdd4b659..d91c61785 100644
--- a/Documentation/admin-guide/xfs.rst
+++ b/Documentation/admin-guide/xfs.rst
@@ -59,6 +59,34 @@ When mounting an XFS filesystem, the following options are accepted.
across the entire filesystem rather than just on directories
configured to use it.

+ force_atomic_cow
+ Force ``RWF_ATOMIC`` writes to use software copy-on-write (CoW),
+ even when hardware atomic writes are possible. This is intended
+ for testing and comparing the atomic write implementations without
+ changing the block device's advertised capabilities. Writes without
+ ``RWF_ATOMIC`` retain their existing behaviour.
+
+ This option requires software atomic write support (currently the
+ reflink feature) and is available without ``CONFIG_XFS_DEBUG``.
+ Existing atomic write size, alignment and direct I/O requirements
+ still apply. CoW can require space allocation even for overwrites,
+ and ``RWF_NOWAIT`` writes can return ``EAGAIN``. Software write
+ failures are not retried using hardware atomic writes.
+
+ The default is to prefer hardware atomic writes and fall back to
+ software CoW when needed. This option can only be enabled when
+ creating a new filesystem instance, not by remounting or adding a
+ mount of an existing instance. All mounts of that instance share
+ the setting. Omitting this option on remount does not disable it;
+ repeating it when already enabled is accepted. To change it, fully
+ unmount the filesystem and mount it again with or without
+ ``force_atomic_cow``. The setting is not stored on disk.
+
+ While enabled, ``statx`` reports ``stx_atomic_write_unit_max_opt``
+ as zero, indicating that there is no separate hardware-optimized
+ size range and ``stx_atomic_write_unit_max`` is the optimized limit.
+ The other atomic write limits are unchanged.
+
inode32 or inode64 (default)
When ``inode32`` is specified, it indicates that XFS limits
inode creation to locations which will not result in inode
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index f7e474161..4dfa91faa 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -798,10 +798,11 @@ xfs_file_dio_write_atomic(
iomap_iter_next_fn next;

/*
- * HW offload should be faster, so try that first if it is already
- * known that the write length is not too large.
+ * Prefer HW offload unless software CoW is forced or the write length
+ * exceeds the hardware limit.
*/
- if (ocount > xfs_inode_buftarg(ip)->bt_awu_max)
+ if (xfs_has_force_atomic_cow(ip->i_mount) ||
+ ocount > xfs_inode_buftarg(ip)->bt_awu_max)
next = xfs_atomic_write_cow_iomap_next;
else
next = xfs_direct_write_iomap_next;
diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
index e04b7d9d2..f785996a8 100644
--- a/fs/xfs/xfs_iops.c
+++ b/fs/xfs/xfs_iops.c
@@ -664,6 +664,10 @@ xfs_get_atomic_write_max_opt(
const unsigned int hw_awu_max = xfs_inode_buftarg(ip)->bt_awu_max;
const xfs_fsize_t hw_align_max = xfs_get_atomic_hw_write_align(ip);

+ /* Forced software writes have no separate hardware-optimized limit. */
+ if (xfs_has_force_atomic_cow(mp))
+ return 0;
+
/* if the max is 1x block, then just keep behaviour that opt is 0 */
if (sw_awu_max <= mp->m_sb.sb_blocksize)
return 0;
diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
index cbcfb89c6..2a07481b3 100644
--- a/fs/xfs/xfs_mount.h
+++ b/fs/xfs/xfs_mount.h
@@ -406,6 +406,7 @@ typedef struct xfs_mount {

/* Mount features */
#define XFS_FEAT_NOLIFETIME (1ULL << 47) /* disable lifetime hints */
+#define XFS_FEAT_FORCE_ATOMIC_COW (1ULL << 48) /* force software atomic writes */
#define XFS_FEAT_NOALIGN (1ULL << 49) /* ignore alignment */
#define XFS_FEAT_ALLOCSIZE (1ULL << 50) /* user specified allocation size */
#define XFS_FEAT_LARGE_IOSIZE (1ULL << 51) /* report large preferred
@@ -550,6 +551,7 @@ __XFS_HAS_FEAT(grpid, GRPID)
__XFS_HAS_FEAT(small_inums, SMALL_INUMS)
__XFS_HAS_FEAT(swalloc, SWALLOC)
__XFS_HAS_FEAT(filestreams, FILESTREAMS)
+__XFS_HAS_FEAT(force_atomic_cow, FORCE_ATOMIC_COW)
__XFS_HAS_FEAT(dax_always, DAX_ALWAYS)
__XFS_HAS_FEAT(dax_never, DAX_NEVER)
__XFS_HAS_FEAT(norecovery, NORECOVERY)
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index 2f6999b69..9c90787f2 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -116,6 +116,7 @@ enum {
Opt_uqnoenforce, Opt_gqnoenforce, Opt_pqnoenforce, Opt_qnoenforce,
Opt_discard, Opt_nodiscard, Opt_dax, Opt_dax_enum, Opt_max_open_zones,
Opt_lifetime, Opt_nolifetime, Opt_max_atomic_write, Opt_errortag,
+ Opt_force_atomic_cow,
};

#define fsparam_dead(NAME) \
@@ -175,6 +176,7 @@ static const struct fs_parameter_spec xfs_fs_parameters[] = {
fsparam_flag("nolifetime", Opt_nolifetime),
fsparam_string("max_atomic_write", Opt_max_atomic_write),
fsparam_string("errortag", Opt_errortag),
+ fsparam_flag("force_atomic_cow", Opt_force_atomic_cow),
{}
};

@@ -196,6 +198,7 @@ xfs_fs_show_options(
{ XFS_FEAT_NOUUID, ",nouuid" },
{ XFS_FEAT_NORECOVERY, ",norecovery" },
{ XFS_FEAT_FILESTREAMS, ",filestreams" },
+ { XFS_FEAT_FORCE_ATOMIC_COW, ",force_atomic_cow" },
{ XFS_FEAT_GRPID, ",grpid" },
{ XFS_FEAT_DISCARD, ",discard" },
{ XFS_FEAT_LARGE_IOSIZE, ",largeio" },
@@ -1141,6 +1144,11 @@ xfs_finish_flags(
return -EINVAL;
}

+ if (xfs_has_force_atomic_cow(mp) && !xfs_can_sw_atomic_write(mp)) {
+ xfs_warn(mp, "force_atomic_cow requires reflink support");
+ return -EINVAL;
+ }
+
if (!xfs_has_zoned(mp)) {
if (mp->m_max_open_zones) {
xfs_warn(mp,
@@ -1609,6 +1617,9 @@ xfs_fs_parse_param(
return 0;
case Opt_errortag:
return xfs_errortag_add_name(parsing_mp, param->string);
+ case Opt_force_atomic_cow:
+ parsing_mp->m_features |= XFS_FEAT_FORCE_ATOMIC_COW;
+ return 0;
default:
xfs_warn(parsing_mp, "unknown mount option [%s].", param->key);
return -EINVAL;
@@ -2031,7 +2042,27 @@ static int
xfs_fs_get_tree(
struct fs_context *fc)
{
- return get_tree_bdev(fc, xfs_fs_fill_super);
+ struct xfs_mount *mp = fc->s_fs_info;
+ struct super_block *sb;
+ bool force_atomic_cow = xfs_has_force_atomic_cow(mp);
+ int error;
+
+ error = get_tree_bdev(fc, xfs_fs_fill_super);
+ if (error)
+ return error;
+
+ sb = fc->root->d_sb;
+ mp = XFS_M(sb);
+ if (force_atomic_cow && !xfs_has_force_atomic_cow(mp)) {
+ xfs_warn(mp,
+ "force_atomic_cow requires a new filesystem instance");
+ dput(fc->root);
+ fc->root = NULL;
+ deactivate_locked_super(sb);
+ return -EBUSY;
+ }
+
+ return 0;
}

static int
@@ -2189,6 +2220,11 @@ xfs_fs_reconfigure(
int flags = fc->sb_flags;
int error;

+ if (xfs_has_force_atomic_cow(new_mp) && !xfs_has_force_atomic_cow(mp)) {
+ xfs_warn(mp, "force_atomic_cow cannot be enabled by remount");
+ return -EINVAL;
+ }
+
new_mp->m_qflags &= ~XFS_QFLAGS_MNTOPTS;

/* version 5 superblocks always support version counters. */

base-commit: 1ebd141a13ae59c34f08e55922c9308e180409a8
--
2.54.0.windows.1


Wayne Gao
Principle Storage Solution Architect
wechat: 13636331364
solidigm.com



CONFIDENTIALITY NOTICE: This email and any files attached may contain confidential information and may be restricted from disclosure by corporate confidentiality guidelines, or applicable state and federal law. It is intended solely for the use of the person or entity to whom the email was addressed. If you are not the intended recipient of this message, be advised that any dissemination, distribution, or use of the contents of this message is strictly prohibited. Please delete this email from your system if you are not the intended recipient.