From: Dave Chinner <david@fromorbit.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Chandan Babu R <chandan.babu@oracle.com>,
"Darrick J. Wong" <djwong@kernel.org>,
Dave Chinner <dchinner@redhat.com>,
linux-xfs@vger.kernel.org
Subject: Re: [PATCH 6/9] xfs: only free posteof blocks on first close
Date: Fri, 9 Aug 2024 08:36:33 +1000 [thread overview]
Message-ID: <ZrVIcay+jnfM7mM5@dread.disaster.area> (raw)
In-Reply-To: <20240808152826.3028421-7-hch@lst.de>
On Thu, Aug 08, 2024 at 08:27:32AM -0700, Christoph Hellwig wrote:
> From: "Darrick J. Wong" <djwong@kernel.org>
>
> Certain workloads fragment files on XFS very badly, such as a software
> package that creates a number of threads, each of which repeatedly run
> the sequence: open a file, perform a synchronous write, and close the
> file, which defeats the speculative preallocation mechanism. We work
> around this problem by only deleting posteof blocks the /first/ time a
> file is closed to preserve the behavior that unpacking a tarball lays
> out files one after the other with no gaps.
>
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> [hch: rebased, updated comment, renamed the flag]
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Reviewed-by: Darrick J. Wong <djwong@kernel.org>
> ---
> fs/xfs/xfs_file.c | 32 +++++++++++---------------------
> fs/xfs/xfs_inode.h | 4 ++--
> 2 files changed, 13 insertions(+), 23 deletions(-)
>
> diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
> index 60424e64230743..30b553ac8f56bb 100644
> --- a/fs/xfs/xfs_file.c
> +++ b/fs/xfs/xfs_file.c
> @@ -1204,15 +1204,21 @@ xfs_file_release(
> * exposed to that problem.
> */
> if (xfs_iflags_test_and_clear(ip, XFS_ITRUNCATED)) {
> - xfs_iflags_clear(ip, XFS_IDIRTY_RELEASE);
> + xfs_iflags_clear(ip, XFS_EOFBLOCKS_RELEASED);
> if (ip->i_delayed_blks > 0)
> filemap_flush(inode->i_mapping);
> }
This should probably be open coded to minimise lock cycles and lock
contention on the flags lock when concurrent open/sync write/close
cycles are run on the file (as recently reported by Mateusz). i.e:
if (ip->i_flags & XFS_ITRUNCATED) {
spin_lock(&ip->i_flags_lock);
if (ip->i_flags & XFS_ITRUNCATED)
ip->i_flags &= ~(XFS_ITRUNCATED | XFS_EOFBLOCKS_RELEASED);
spin_unlock(&ip->i_flags_lock);
if (ip->i_delayed_blks > 0)
filemap_flush(inode->i_mapping);
}
....
> @@ -1230,25 +1236,9 @@ xfs_file_release(
> (file->f_mode & FMODE_WRITE) &&
> xfs_ilock_nowait(ip, XFS_IOLOCK_EXCL)) {
> if (xfs_can_free_eofblocks(ip) &&
> - !xfs_iflags_test(ip, XFS_IDIRTY_RELEASE)) {
> - /*
> - * Check if the inode is being opened, written and
> - * closed frequently and we have delayed allocation
> - * blocks outstanding (e.g. streaming writes from the
> - * NFS server), truncating the blocks past EOF will
> - * cause fragmentation to occur.
> - *
> - * In this case don't do the truncation, but we have to
> - * be careful how we detect this case. Blocks beyond EOF
> - * show up as i_delayed_blks even when the inode is
> - * clean, so we need to truncate them away first before
> - * checking for a dirty release. Hence on the first
> - * dirty close we will still remove the speculative
> - * allocation, but after that we will leave it in place.
> - */
> + !xfs_iflags_test(ip, XFS_EOFBLOCKS_RELEASED)) {
> xfs_free_eofblocks(ip);
> - if (ip->i_delayed_blks)
> - xfs_iflags_set(ip, XFS_IDIRTY_RELEASE);
> + xfs_iflags_set(ip, XFS_EOFBLOCKS_RELEASED);
!xfs_iflags_test_and_set(ip, XFS_EOFBLOCKS_RELEASED)
xfs_free_eofblocks(ip);
This also avoids an extra lock cycle to set the flag....
-Dave.
--
Dave Chinner
david@fromorbit.com
next prev parent reply other threads:[~2024-08-08 22:36 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-08 15:27 post-EOF block handling revamp v2 Christoph Hellwig
2024-08-08 15:27 ` [PATCH 1/9] xfs: remove the i_mode check in xfs_release Christoph Hellwig
2024-08-08 15:27 ` [PATCH 2/9] xfs: refactor f_op->release handling Christoph Hellwig
2024-08-08 15:27 ` [PATCH 3/9] xfs: don't bother returning errors from xfs_file_release Christoph Hellwig
2024-08-08 15:27 ` [PATCH 4/9] xfs: skip all of xfs_file_release when shut down Christoph Hellwig
2024-08-08 22:25 ` Dave Chinner
2024-08-08 15:27 ` [PATCH 5/9] xfs: don't free post-EOF blocks on read close Christoph Hellwig
2024-08-08 15:27 ` [PATCH 6/9] xfs: only free posteof blocks on first close Christoph Hellwig
2024-08-08 22:36 ` Dave Chinner [this message]
2024-08-11 8:44 ` Christoph Hellwig
2024-08-08 15:27 ` [PATCH 7/9] xfs: check XFS_EOFBLOCKS_RELEASED earlier in xfs_release_eofblocks Christoph Hellwig
2024-08-08 23:03 ` Dave Chinner
2024-08-11 8:59 ` Christoph Hellwig
2024-08-11 23:48 ` Dave Chinner
2024-08-08 15:27 ` [PATCH 8/9] xfs: simplify extent lookup in xfs_can_free_eofblocks Christoph Hellwig
2024-08-08 15:27 ` [PATCH 9/9] xfs: reclaim speculative preallocations for append only files Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2024-08-13 7:39 post-EOF block handling revamp v3 Christoph Hellwig
2024-08-13 7:39 ` [PATCH 6/9] xfs: only free posteof blocks on first close 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=ZrVIcay+jnfM7mM5@dread.disaster.area \
--to=david@fromorbit.com \
--cc=chandan.babu@oracle.com \
--cc=dchinner@redhat.com \
--cc=djwong@kernel.org \
--cc=hch@lst.de \
--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