From: John Garry <john.g.garry@oracle.com>
To: brauner@kernel.org, djwong@kernel.org, hch@lst.de,
viro@zeniv.linux.org.uk, jack@suse.cz, cem@kernel.org
Cc: linux-fsdevel@vger.kernel.org, dchinner@redhat.com,
linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org,
ojaswin@linux.ibm.com, ritesh.list@gmail.com,
martin.petersen@oracle.com, linux-ext4@vger.kernel.org,
linux-block@vger.kernel.org, catherine.hoang@oracle.com,
John Garry <john.g.garry@oracle.com>
Subject: [PATCH v6 12/12] xfs: update atomic write limits
Date: Tue, 8 Apr 2025 10:42:09 +0000 [thread overview]
Message-ID: <20250408104209.1852036-13-john.g.garry@oracle.com> (raw)
In-Reply-To: <20250408104209.1852036-1-john.g.garry@oracle.com>
Update the limits returned from xfs_get_atomic_write_{min, max, max_opt)().
No reflink support always means no CoW-based atomic writes.
For updating xfs_get_atomic_write_min(), we support blocksize only and that
depends on HW or reflink support.
For updating xfs_get_atomic_write_max(), for rtvol or no reflink, we are
limited to blocksize but only if HW support. Otherwise we are limited to
combined limit in mp->m_atomic_write_unit_max.
For updating xfs_get_atomic_write_max_opt(), ultimately we are limited by
the bdev atomic write limit. If xfs_get_atomic_write_max() does not report
> 1x blocksize, then just continue to report 0 as before.
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
fs/xfs/xfs_file.c | 2 +-
fs/xfs/xfs_iops.c | 37 +++++++++++++++++++++++++++++++------
2 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 81a377f65aa3..d1ddbc4a98c3 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -1557,7 +1557,7 @@ xfs_file_open(
if (xfs_is_shutdown(XFS_M(inode->i_sb)))
return -EIO;
file->f_mode |= FMODE_NOWAIT | FMODE_CAN_ODIRECT;
- if (xfs_inode_can_hw_atomicwrite(XFS_I(inode)))
+ if (xfs_get_atomic_write_min(XFS_I(inode)))
file->f_mode |= FMODE_CAN_ATOMIC_WRITE;
return generic_file_open(inode, file);
}
diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
index 3b5aa39dbfe9..894f56f1a830 100644
--- a/fs/xfs/xfs_iops.c
+++ b/fs/xfs/xfs_iops.c
@@ -605,27 +605,52 @@ unsigned int
xfs_get_atomic_write_min(
struct xfs_inode *ip)
{
- if (!xfs_inode_can_hw_atomicwrite(ip))
- return 0;
+ if (xfs_inode_can_hw_atomicwrite(ip) || xfs_has_reflink(ip->i_mount))
+ return ip->i_mount->m_sb.sb_blocksize;
- return ip->i_mount->m_sb.sb_blocksize;
+ return 0;
}
unsigned int
xfs_get_atomic_write_max(
struct xfs_inode *ip)
{
- if (!xfs_inode_can_hw_atomicwrite(ip))
+ struct xfs_mount *mp = ip->i_mount;
+
+ /*
+ * If no reflink, then best we can do is 1x block as no CoW fallback
+ * for when HW offload not possible.
+ *
+ * rtvol is not commonly used and supporting large atomic writes
+ * would also be complicated to support there, so limit to a single
+ * block for now.
+ */
+ if (!xfs_has_reflink(mp) || XFS_IS_REALTIME_INODE(ip)) {
+ if (xfs_inode_can_hw_atomicwrite(ip))
+ return ip->i_mount->m_sb.sb_blocksize;
return 0;
+ }
- return ip->i_mount->m_sb.sb_blocksize;
+ /*
+ * Even though HW support could be larger (than CoW), we rely on
+ * CoW-based method as a fallback for when HW-based is not possible,
+ * so always limit at m_atomic_write_unit_max (which is evaluated
+ * according to CoW-based limit.
+ */
+ return XFS_FSB_TO_B(mp, mp->m_atomic_write_unit_max);
}
unsigned int
xfs_get_atomic_write_max_opt(
struct xfs_inode *ip)
{
- return 0;
+ struct xfs_buftarg *target = xfs_inode_buftarg(ip);
+
+ /* if the max is 1x block, then just keep behaviour that opt is 0 */
+ if (xfs_get_atomic_write_max(ip) <= ip->i_mount->m_sb.sb_blocksize)
+ return 0;
+
+ return min(xfs_get_atomic_write_max(ip), target->bt_bdev_awu_max);
}
static void
--
2.31.1
prev parent reply other threads:[~2025-04-08 10:43 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-08 10:41 [PATCH v6 00/12] large atomic writes for xfs John Garry
2025-04-08 10:41 ` [PATCH v6 01/12] fs: add atomic write unit max opt to statx John Garry
2025-04-09 2:23 ` Darrick J. Wong
2025-04-09 10:45 ` Christoph Hellwig
2025-04-08 10:41 ` [PATCH v6 02/12] xfs: add helpers to compute log item overhead John Garry
2025-04-08 22:50 ` Dave Chinner
2025-04-08 23:21 ` Darrick J. Wong
2025-04-09 2:25 ` [PATCH v6.1 " Darrick J. Wong
2025-04-09 2:25 ` [PATCH v6.1 RFC 02.1/12] xfs: add helpers to compute transaction reservation for finishing intent items Darrick J. Wong
2025-04-08 10:42 ` [PATCH v6 03/12] xfs: rename xfs_inode_can_atomicwrite() -> xfs_inode_can_hw_atomicwrite() John Garry
2025-04-09 2:02 ` Darrick J. Wong
2025-04-09 10:46 ` Christoph Hellwig
2025-04-08 10:42 ` [PATCH v6 04/12] xfs: allow block allocator to take an alignment hint John Garry
2025-04-08 10:42 ` [PATCH v6 05/12] xfs: refactor xfs_reflink_end_cow_extent() John Garry
2025-04-08 10:42 ` [PATCH v6 06/12] xfs: refine atomic write size check in xfs_file_write_iter() John Garry
2025-04-08 10:42 ` [PATCH v6 07/12] xfs: add xfs_atomic_write_cow_iomap_begin() John Garry
2025-04-08 10:42 ` [PATCH v6 08/12] xfs: add large atomic writes checks in xfs_direct_write_iomap_begin() John Garry
2025-04-08 10:42 ` [PATCH v6 09/12] xfs: commit CoW-based atomic writes atomically John Garry
2025-04-08 10:42 ` [PATCH v6 10/12] xfs: add xfs_file_dio_write_atomic() John Garry
2025-04-08 10:42 ` [PATCH v6 11/12] xfs: add xfs_compute_atomic_write_unit_max() John Garry
2025-04-08 21:28 ` Darrick J. Wong
2025-04-08 22:47 ` Dave Chinner
2025-04-09 0:41 ` Darrick J. Wong
2025-04-09 5:30 ` Dave Chinner
2025-04-09 8:15 ` John Garry
2025-04-09 22:49 ` Dave Chinner
2025-04-10 8:58 ` John Garry
2025-04-09 23:46 ` Darrick J. Wong
2025-04-08 10:42 ` John Garry [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250408104209.1852036-13-john.g.garry@oracle.com \
--to=john.g.garry@oracle.com \
--cc=brauner@kernel.org \
--cc=catherine.hoang@oracle.com \
--cc=cem@kernel.org \
--cc=dchinner@redhat.com \
--cc=djwong@kernel.org \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=linux-block@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=ojaswin@linux.ibm.com \
--cc=ritesh.list@gmail.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox