All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Foster <bfoster@redhat.com>
To: linux-xfs@vger.kernel.org
Subject: [PATCH RFC 1/2] xfs: lift truncate iomap zeroing into a new helper
Date: Fri, 28 Oct 2022 09:04:10 -0400	[thread overview]
Message-ID: <20221028130411.977076-2-bfoster@redhat.com> (raw)
In-Reply-To: <20221028130411.977076-1-bfoster@redhat.com>

Create a new helper to improve readability of subsequent changes in
this area of code. No functional change is intended, but while here,
also change the end offset of the flush to use newsize - 1. This off
by one should have no impact on cases where the flush is relevant
because zeroing only occurs when the size is non-block aligned.

Signed-off-by: Brian Foster <bfoster@redhat.com>
---
 fs/xfs/xfs_iops.c | 52 +++++++++++++++++++++++++++++++----------------
 1 file changed, 34 insertions(+), 18 deletions(-)

diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
index 2e10e1c66ad6..d31e64db243f 100644
--- a/fs/xfs/xfs_iops.c
+++ b/fs/xfs/xfs_iops.c
@@ -770,6 +770,39 @@ xfs_setattr_nonsize(
 	return error;
 }
 
+/*
+ * Do the appropriate zeroing for a particular truncate operation. This zeroes
+ * the range of blocks between oldsize and newsize on a truncate up or otherwise
+ * partially zeroes the post-EOF portion of the EOF block at newsize.
+ */
+static int
+xfs_truncate_zeroing(
+	struct xfs_inode	*ip,
+	xfs_off_t		oldsize,
+	xfs_off_t		newsize,
+	bool			*did_zeroing)
+{
+	int			error;
+
+	if (newsize > oldsize) {
+		trace_xfs_zero_eof(ip, oldsize, newsize - oldsize);
+		return xfs_zero_range(ip, oldsize, newsize - oldsize,
+				did_zeroing);
+	}
+
+	/*
+	 * iomap won't detect a dirty page over an unwritten block (or a cow
+	 * block over a hole) and subsequently skips zeroing the newly post-EOF
+	 * portion of the page. Flush the new EOF to convert the block before
+	 * the pagecache truncate.
+	 */
+	error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping, newsize - 1,
+					     newsize - 1);
+	if (error)
+		return error;
+	return xfs_truncate_page(ip, newsize, did_zeroing);
+}
+
 /*
  * Truncate file.  Must have write permission and not be a directory.
  *
@@ -835,24 +868,7 @@ xfs_setattr_size(
 	 * extension, or zeroing out the rest of the block on a downward
 	 * truncate.
 	 */
-	if (newsize > oldsize) {
-		trace_xfs_zero_eof(ip, oldsize, newsize - oldsize);
-		error = xfs_zero_range(ip, oldsize, newsize - oldsize,
-				&did_zeroing);
-	} else {
-		/*
-		 * iomap won't detect a dirty page over an unwritten block (or a
-		 * cow block over a hole) and subsequently skips zeroing the
-		 * newly post-EOF portion of the page. Flush the new EOF to
-		 * convert the block before the pagecache truncate.
-		 */
-		error = filemap_write_and_wait_range(inode->i_mapping, newsize,
-						     newsize);
-		if (error)
-			return error;
-		error = xfs_truncate_page(ip, newsize, &did_zeroing);
-	}
-
+	error = xfs_truncate_zeroing(ip, oldsize, newsize, &did_zeroing);
 	if (error)
 		return error;
 
-- 
2.37.3


  reply	other threads:[~2022-10-28 13:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-28 13:04 [PATCH RFC 0/2] xfs: optimize truncate cache flushing Brian Foster
2022-10-28 13:04 ` Brian Foster [this message]
2022-10-28 13:04 ` [PATCH RFC 2/2] xfs: optimize eof page flush for iomap zeroing on truncate Brian Foster
2022-10-28 13:11 ` [PATCH] xfs: redirty eof folio on truncate to avoid filemap flush Brian Foster
2022-10-28 18:26   ` Brian Foster
2022-10-28 21:30     ` Dave Chinner
2022-10-28 23:49       ` Darrick J. Wong
2022-10-29 22:01         ` Dave Chinner
2022-11-02  8:15           ` Christoph Hellwig
2022-11-03 14:53       ` Brian Foster
2022-11-03 22:25         ` Dave Chinner
2022-11-04 18:22           ` Brian Foster
2022-11-02  8:25     ` Christoph Hellwig
2022-10-28 21:35   ` kernel test robot

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=20221028130411.977076-2-bfoster@redhat.com \
    --to=bfoster@redhat.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.