From: Christoph Hellwig <hch@lst.de>
To: Carlos Maiolino <cem@kernel.org>
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 4/6] xfs: avoid extra cache flushes for multi-device file systems in xfs_fsync
Date: Wed, 2 Sep 2026 08:49:18 +0300 [thread overview]
Message-ID: <20260902054942.111988-5-hch@lst.de> (raw)
In-Reply-To: <20260902054942.111988-1-hch@lst.de>
When xlog_force_lsn sets log_flushed, it has just called xlog_force_iclog
through xlog_force_and_check_iclog, which sets XLOG_ICL_NEED_FLUSH before
writing out the head iclog. This means that we already flushed the log,
data, and (with the recent fix) RT devices before writing out the iclog
start record and no extra cache flushed is required.
The explicit flush of the data that the device resides on when no iclog
was written out is still required.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/xfs/xfs_file.c | 36 +++++++++---------------------------
1 file changed, 9 insertions(+), 27 deletions(-)
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index cce324321b4c..795e72e1b599 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -128,7 +128,6 @@ xfs_file_fsync(
int datasync)
{
struct xfs_inode *ip = XFS_I(file->f_mapping->host);
- struct xfs_mount *mp = ip->i_mount;
int log_flushed = 0;
int error;
@@ -138,27 +137,17 @@ xfs_file_fsync(
if (error)
return error;
- if (xfs_is_shutdown(mp))
+ if (xfs_is_shutdown(ip->i_mount))
return -EIO;
xfs_iflags_clear(ip, XFS_ITRUNCATED);
/*
- * If we have an RT and/or log subvolume we need to make sure to flush
- * the write cache the device used for file data first. This is to
- * ensure newly written file data make it to disk before logging the new
- * inode size in case of an extending write.
- */
- if (XFS_IS_REALTIME_INODE(ip) && mp->m_rtdev_targp != mp->m_ddev_targp)
- error = blkdev_issue_flush(mp->m_rtdev_targp->bt_bdev);
- else if (mp->m_logdev_targp != mp->m_ddev_targp)
- error = blkdev_issue_flush(mp->m_ddev_targp->bt_bdev);
- if (error)
- return error;
-
- /*
- * If the inode has a inode log item attached, it may need the journal
- * flushed to persist any changes the log item might be tracking.
+ * If the inode has a log item attached, we must force the log up to the
+ * last LSN in which the inode was modified to ensure all metadata is
+ * persisted. The log force will flush the caches for all devices
+ * before writing the log records unless it is a no-op because there are
+ * no modifications to this inode that need to be pushed out.
*/
if (ip->i_itemp) {
error = xfs_fsync_flush_log(ip, datasync, &log_flushed);
@@ -172,17 +161,10 @@ xfs_file_fsync(
* when no metadata needed to be committed.
*
* Use the inode's actual file data target rather than assuming the
- * main data device. Realtime inodes with a separate realtime device
- * are flushed before the log force, so this fallback only applies
- * when the file data target is the same as the log target.
+ * main data device.
*/
- if (!log_flushed) {
- struct xfs_buftarg *file_targp = xfs_inode_buftarg(ip);
-
- if (mp->m_logdev_targp == file_targp)
- return blkdev_issue_flush(file_targp->bt_bdev);
- }
-
+ if (!log_flushed)
+ return blkdev_issue_flush(xfs_inode_buftarg(ip)->bt_bdev);
return 0;
}
--
2.53.0
next prev parent reply other threads:[~2026-09-02 5:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 5:49 fix and then optimize cache flushes for the RT device Christoph Hellwig
2026-09-02 5:49 ` [PATCH 1/6] xfs: also flush the RT device cache in xlog_write_iclog Christoph Hellwig
2026-09-02 16:01 ` Darrick J. Wong
2026-09-02 5:49 ` [PATCH 2/6] xfs: don't continue on error in xfs_fsync Christoph Hellwig
2026-09-02 16:07 ` Darrick J. Wong
2026-09-02 5:49 ` [PATCH 3/6] xfs: clean up xfs_fsync_flush_log a bit Christoph Hellwig
2026-09-02 16:07 ` Darrick J. Wong
2026-09-02 5:49 ` Christoph Hellwig [this message]
2026-09-02 16:12 ` [PATCH 4/6] xfs: avoid extra cache flushes for multi-device file systems in xfs_fsync Darrick J. Wong
2026-09-02 5:49 ` [PATCH 5/6] xfs: optimize cache flushing for CIL commits on multi-device file systems Christoph Hellwig
2026-09-02 16:15 ` Darrick J. Wong
2026-09-02 5:49 ` [PATCH 6/6] xfs: flush multiple device caches in parallel in xlog_write_iclog Christoph Hellwig
2026-09-02 16:18 ` Darrick J. Wong
2026-09-03 5:44 ` Christoph Hellwig
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=20260902054942.111988-5-hch@lst.de \
--to=hch@lst.de \
--cc=cem@kernel.org \
--cc=linux-xfs@vger.kernel.org \
/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