From: Dave Chinner <david@fromorbit.com>
To: linux-xfs@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org,
hch@lst.de, rdorr@microsoft.com
Subject: [PATCH 2/3] iomap: iomap_dio_rw() handles all sync writes
Date: Wed, 2 May 2018 15:38:06 +1000 [thread overview]
Message-ID: <20180502053807.13846-3-david@fromorbit.com> (raw)
In-Reply-To: <20180502053807.13846-1-david@fromorbit.com>
From: Dave Chinner <dchinner@redhat.com>
Currently iomap_dio_rw() only handles (data)sync write completions
for AIO. This means we can't optimised non-AIO IO to minimise device
flushes as we can't tell the caller whether a flush is required or
not.
To solve this problem and enable further optimisations, make
iomap_dio_rw responsible for data sync behaviour for all IO, not
just AIO.
In doing so, the sync operation is now accounted as part of the DIO
IO by inode_dio_end(), hence post-IO data stability updates will no
long race against operations that serialise via inode_dio_wait()
such as truncate or hole punch.
Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
fs/iomap.c | 21 +++++++++++++++------
fs/xfs/xfs_file.c | 5 -----
2 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/fs/iomap.c b/fs/iomap.c
index afd163586aa0..b044d8ee2efd 100644
--- a/fs/iomap.c
+++ b/fs/iomap.c
@@ -685,6 +685,7 @@ EXPORT_SYMBOL_GPL(iomap_seek_data);
* Private flags for iomap_dio, must not overlap with the public ones in
* iomap.h:
*/
+#define IOMAP_DIO_NEED_SYNC (1 << 29)
#define IOMAP_DIO_WRITE (1 << 30)
#define IOMAP_DIO_DIRTY (1 << 31)
@@ -759,6 +760,13 @@ static ssize_t iomap_dio_complete(struct iomap_dio *dio)
dio_warn_stale_pagecache(iocb->ki_filp);
}
+ /*
+ * If this is a DSYNC write, make sure we push it to stable storage now
+ * that we've written data.
+ */
+ if (ret > 0 && (dio->flags & IOMAP_DIO_NEED_SYNC))
+ ret = generic_write_sync(iocb, ret);
+
inode_dio_end(file_inode(iocb->ki_filp));
kfree(dio);
@@ -769,13 +777,8 @@ static void iomap_dio_complete_work(struct work_struct *work)
{
struct iomap_dio *dio = container_of(work, struct iomap_dio, aio.work);
struct kiocb *iocb = dio->iocb;
- bool is_write = (dio->flags & IOMAP_DIO_WRITE);
- ssize_t ret;
- ret = iomap_dio_complete(dio);
- if (is_write && ret > 0)
- ret = generic_write_sync(iocb, ret);
- iocb->ki_complete(iocb, ret, 0);
+ iocb->ki_complete(iocb, iomap_dio_complete(dio), 0);
}
/*
@@ -961,6 +964,10 @@ iomap_dio_actor(struct inode *inode, loff_t pos, loff_t length,
return copied;
}
+/*
+ * iomap_dio_rw() always completes O_[D]SYNC writes regardless of whether the IO
+ * is being issued as AIO or not.
+ */
ssize_t
iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
const struct iomap_ops *ops, iomap_dio_end_io_t end_io)
@@ -1006,6 +1013,8 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
dio->flags |= IOMAP_DIO_DIRTY;
} else {
dio->flags |= IOMAP_DIO_WRITE;
+ if (iocb->ki_flags & IOCB_DSYNC)
+ dio->flags |= IOMAP_DIO_NEED_SYNC;
flags |= IOMAP_WRITE;
}
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 4cbd15d84bb8..64112a57b004 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -570,11 +570,6 @@ xfs_file_dio_aio_write(
* complete fully or fail.
*/
ASSERT(ret < 0 || ret == count);
-
- if (ret > 0) {
- /* Handle various SYNC-type writes */
- ret = generic_write_sync(iocb, ret);
- }
return ret;
}
--
2.17.0
next prev parent reply other threads:[~2018-05-02 6:02 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-02 5:38 [PATCH 0/3 v3] iomap: Use FUA for O_DSYNC DIO writes Dave Chinner
2018-05-02 5:38 ` [PATCH 1/3] xfs: move generic_write_sync calls inwards Dave Chinner
2018-05-02 5:38 ` Dave Chinner [this message]
2018-05-02 5:38 ` [PATCH 3/3] iomap: Use FUA for pure data O_DSYNC DIO writes Dave Chinner
2018-05-02 20:09 ` [PATCH 0/3 v3] iomap: Use FUA for " Darrick J. Wong
-- strict thread matches above, loose matches on Subject: below --
2018-03-27 7:07 [PATCH 0/3 V2] " Dave Chinner
2018-03-27 7:07 ` [PATCH 2/3] iomap: iomap_dio_rw() handles all sync writes Dave Chinner
2018-03-28 7:38 ` Christoph Hellwig
2018-03-28 7: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=20180502053807.13846-3-david@fromorbit.com \
--to=david@fromorbit.com \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=rdorr@microsoft.com \
/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;
as well as URLs for NNTP newsgroup(s).