From: Dave Chinner <david@fromorbit.com>
To: Christoph Hellwig <hch@lst.de>
Cc: linux-xfs@vger.kernel.org, Avi Kivity <avi@scylladb.com>,
Brian Foster <bfoster@redhat.com>
Subject: Re: [PATCH 3/3] xfs: try to avoid the iolock exclusive for non-aligned direct writes
Date: Tue, 12 Jan 2021 07:52:48 +1100 [thread overview]
Message-ID: <20210111205248.GO331610@dread.disaster.area> (raw)
In-Reply-To: <20210111161212.1414034-4-hch@lst.de>
On Mon, Jan 11, 2021 at 05:12:12PM +0100, Christoph Hellwig wrote:
> We only need the exclusive iolock for direct writes to protect sub-block
> zeroing after an allocation or conversion of unwritten extents, and the
> synchronous execution of these writes is also only needed because the
> iolock is dropped early for the dodgy i_dio_count synchronisation.
>
> Always start out with the shared iolock in xfs_file_dio_aio_write for
> non-appending writes and only upgrade it to exclusive if the start and
> end of the write range are not already allocated and in written
> state. This means one or two extra lookups in the in-core extent tree,
> but with our btree data structure those lookups are very cheap and do
> not show up in profiles on NVMe hardware for me. On the other hand
> avoiding the lock allows for a high concurrency using aio or io_uring.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Reported-by: Avi Kivity <avi@scylladb.com>
> Suggested-by: Brian Foster <bfoster@redhat.com>
> ---
> fs/xfs/xfs_file.c | 127 +++++++++++++++++++++++++++++++++++-----------
> 1 file changed, 96 insertions(+), 31 deletions(-)
>
> diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
> index 1470fc4f2e0255..59d4c6e90f06c1 100644
> --- a/fs/xfs/xfs_file.c
> +++ b/fs/xfs/xfs_file.c
> @@ -521,6 +521,57 @@ static const struct iomap_dio_ops xfs_dio_write_ops = {
> .end_io = xfs_dio_write_end_io,
> };
>
> +static int
> +xfs_dio_write_exclusive(
> + struct kiocb *iocb,
> + size_t count,
> + bool *exclusive_io)
> +{
> + struct xfs_inode *ip = XFS_I(file_inode(iocb->ki_filp));
> + struct xfs_mount *mp = ip->i_mount;
> + struct xfs_ifork *ifp = &ip->i_df;
> + loff_t offset = iocb->ki_pos;
> + loff_t end = offset + count;
> + xfs_fileoff_t offset_fsb = XFS_B_TO_FSBT(mp, offset);
> + xfs_fileoff_t end_fsb = XFS_B_TO_FSB(mp, end);
> + struct xfs_bmbt_irec got = { };
> + struct xfs_iext_cursor icur;
> + int ret;
> +
> + *exclusive_io = true;
> +
> + /*
> + * Bmap information not read in yet or no blocks allocated at all?
> + */
> + if (!(ifp->if_flags & XFS_IFEXTENTS) || !ip->i_d.di_nblocks)
> + return 0;
> +
> + ret = xfs_ilock_iocb(iocb, XFS_ILOCK_SHARED);
> + if (ret)
> + return ret;
> +
> + if (offset & mp->m_blockmask) {
> + if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &icur, &got) ||
> + got.br_startoff > offset_fsb ||
> + got.br_state == XFS_EXT_UNWRITTEN)
> + goto out_unlock;
> + }
> +
> + if ((end & mp->m_blockmask) &&
> + got.br_startoff + got.br_blockcount <= end_fsb) {
> + if (!xfs_iext_lookup_extent(ip, ifp, end_fsb, &icur, &got) ||
> + got.br_startoff > end_fsb ||
> + got.br_state == XFS_EXT_UNWRITTEN)
> + goto out_unlock;
> + }
> +
> + *exclusive_io = false;
> +
> +out_unlock:
> + xfs_iunlock(ip, XFS_ILOCK_SHARED);
> + return ret;
> +}
OK, this has a bug in it. We have to do exclusive sub-block IO when
the end of the IO is >= i_size_read(inode) because in this situation
iomap_dio_rw_actor() will issue an extra bio to zero the portion of
the filesystem block that lies beyond EOF. generic/418 hammers this
case, and randomly ends up with zeroes where there should be data.
Otherwise, it largely makes a similar mess of
xfs_file_dio_aio_write() as my initial patchset does. We should just
move the unaligned IO out of the main path, regardless of whether it
is exclusive or not.
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
next prev parent reply other threads:[~2021-01-11 20:53 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-11 16:12 improve sub-block size direct I/O concurrency Christoph Hellwig
2021-01-11 16:12 ` [PATCH 1/3] xfs: factor out a xfs_ilock_iocb helper Christoph Hellwig
2021-01-11 18:55 ` Brian Foster
2021-01-11 16:12 ` [PATCH 2/3] xfs: make xfs_file_aio_write_checks IOCB_NOWAIT-aware Christoph Hellwig
2021-01-11 18:55 ` Brian Foster
2021-01-11 16:12 ` [PATCH 3/3] xfs: try to avoid the iolock exclusive for non-aligned direct writes Christoph Hellwig
2021-01-11 18:59 ` Brian Foster
2021-01-11 19:14 ` Christoph Hellwig
2021-01-11 19:49 ` Brian Foster
2021-01-11 20:52 ` Dave Chinner [this message]
2021-01-11 20:45 ` improve sub-block size direct I/O concurrency Dave Chinner
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=20210111205248.GO331610@dread.disaster.area \
--to=david@fromorbit.com \
--cc=avi@scylladb.com \
--cc=bfoster@redhat.com \
--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