linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Grünbacher" <andreas.gruenbacher@gmail.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Andreas Gruenbacher <agruenba@redhat.com>,
	cluster-devel <cluster-devel@redhat.com>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	Dave Chinner <dchinner@redhat.com>
Subject: Re: [PATCH v4 11/11] iomap: Complete partial direct I/O writes synchronously
Date: Fri, 18 May 2018 20:35:12 +0200	[thread overview]
Message-ID: <CAHpGcMLLCEwC_R_a-ud9-CJkdcdUVFdXfoVc5y+hnj6ezgyFfg@mail.gmail.com> (raw)
In-Reply-To: <20180518155611.GA3018@lst.de>

2018-05-18 17:56 GMT+02:00 Christoph Hellwig <hch@lst.de>:
> On Wed, May 16, 2018 at 10:27:18PM +0200, Andreas Gruenbacher wrote:
>> I/O completion triggers when dio->ref reaches zero, so
>> iomap_dio_bio_end_io will never evaluate submit.waiter before the
>> atomic_dec_and_test in iomap_dio_rw. We probably need an
>> smp_mb__before_atomic() before that atomic_dec_and_test to make sure
>> that iomap_dio_bio_end_io sees the right value of submit.waiter
>> though. Any concerns beyond that?
>
> I suspect in the end union usage might still be fine, but it still
> looks rather dangerous to scramble over the union that late.  It will
> also do things like overriding the last_queue pointer which we need
> initialized early for block polling.
>
> I suspect something like the variant below will work much better.
> This moves the wait_for_completion flag into struct iomap_dio
> (in an existing packing hole) and uses that in the completion
> handler.  It also always initializes the submit fields to prepare
> for this early, and makes all fallbacks synchronous (if we ever
> get a read fallback that would be the right thing to do).

Yes, that should work.

> diff --git a/fs/iomap.c b/fs/iomap.c
> index e4617ae1f8d6..54b28a58b7e3 100644
> --- a/fs/iomap.c
> +++ b/fs/iomap.c
> @@ -1327,6 +1327,7 @@ struct iomap_dio {
>         atomic_t                ref;
>         unsigned                flags;
>         int                     error;
> +       bool                    wait_for_completion;
>
>         union {
>                 /* used during submission and for synchronous completion: */
> @@ -1430,7 +1431,7 @@ static void iomap_dio_bio_end_io(struct bio *bio)
>                 iomap_dio_set_error(dio, blk_status_to_errno(bio->bi_status));
>
>         if (atomic_dec_and_test(&dio->ref)) {
> -               if (is_sync_kiocb(dio->iocb)) {
> +               if (dio->wait_for_completion) {
>                         struct task_struct *waiter = dio->submit.waiter;
>
>                         WRITE_ONCE(dio->submit.waiter, NULL);
> @@ -1646,13 +1647,12 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
>         dio->end_io = end_io;
>         dio->error = 0;
>         dio->flags = 0;
> +       dio->wait_for_completion = is_sync_kiocb(iocb);
>
>         dio->submit.iter = iter;
> -       if (is_sync_kiocb(iocb)) {
> -               dio->submit.waiter = current;
> -               dio->submit.cookie = BLK_QC_T_NONE;
> -               dio->submit.last_queue = NULL;
> -       }
> +       dio->submit.waiter = current;
> +       dio->submit.cookie = BLK_QC_T_NONE;
> +       dio->submit.last_queue = NULL;
>
>         if (iov_iter_rw(iter) == READ) {
>                 if (pos >= dio->i_size)
> @@ -1702,7 +1702,7 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
>                 dio_warn_stale_pagecache(iocb->ki_filp);
>         ret = 0;
>
> -       if (iov_iter_rw(iter) == WRITE && !is_sync_kiocb(iocb) &&
> +       if (iov_iter_rw(iter) == WRITE && !dio->wait_for_completion &&
>             !inode->i_sb->s_dio_done_wq) {
>                 ret = sb_init_dio_done_wq(inode->i_sb);
>                 if (ret < 0)
> @@ -1717,8 +1717,10 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
>                                 iomap_dio_actor);
>                 if (ret <= 0) {
>                         /* magic error code to fall back to buffered I/O */
> -                       if (ret == -ENOTBLK)
> +                       if (ret == -ENOTBLK) {
> +                               dio->wait_for_completion = true;
>                                 ret = 0;
> +                       }
>                         break;
>                 }
>                 pos += ret;
> @@ -1739,7 +1741,7 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
>                 dio->flags &= ~IOMAP_DIO_NEED_SYNC;

We still want to make sure the right value of dio->wait_for_completion
is seen by iomap_dio_bio_end_io:

        smp_mb__before_atomic();

>         if (!atomic_dec_and_test(&dio->ref)) {
> -               if (!is_sync_kiocb(iocb))
> +               if (!dio->wait_for_completion)
>                         return -EIOCBQUEUED;
>
>                 for (;;) {

Thanks,
Andreas

      reply	other threads:[~2018-05-18 18:35 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-14 15:36 [PATCH v4 00/11] gfs2 iomap write support Andreas Gruenbacher
2018-05-14 15:36 ` [PATCH v4 01/11] gfs2: Update find_metapath comment Andreas Gruenbacher
2018-05-14 15:36 ` [PATCH v4 02/11] gfs2: hole_size improvement Andreas Gruenbacher
2018-05-14 15:36 ` [PATCH v4 03/11] gfs2: gfs2_stuffed_write_end cleanup Andreas Gruenbacher
2018-05-14 15:36 ` [PATCH v4 04/11] gfs2: Remove ordered write mode handling from gfs2_trans_add_data Andreas Gruenbacher
2018-05-14 15:36 ` [PATCH v4 05/11] gfs2: Iomap cleanups and improvements Andreas Gruenbacher
2018-05-14 15:36 ` [PATCH v4 06/11] iomap: Add write_{begin,end} iomap operations Andreas Gruenbacher
2018-05-15  1:11   ` Dave Chinner
2018-05-15  7:22     ` Christoph Hellwig
2018-05-15  8:16       ` Andreas Gruenbacher
2018-05-18 16:04         ` Christoph Hellwig
2018-05-25 17:58           ` Andreas Grünbacher
2018-05-28 13:02             ` Christoph Hellwig
2018-05-14 15:36 ` [PATCH v4 07/11] gfs2: iomap buffered write support Andreas Gruenbacher
2018-05-14 15:36 ` [PATCH v4 08/11] gfs2: gfs2_extent_length cleanup Andreas Gruenbacher
2018-05-14 15:36 ` [PATCH v4 09/11] gfs2: iomap direct I/O support Andreas Gruenbacher
2018-05-15  7:31   ` Christoph Hellwig
2018-05-16 20:36     ` Andreas Gruenbacher
2018-05-14 15:36 ` [PATCH v4 10/11] gfs2: Remove gfs2_write_{begin,end} Andreas Gruenbacher
2018-05-14 15:36 ` [PATCH v4 11/11] iomap: Complete partial direct I/O writes synchronously Andreas Gruenbacher
2018-05-15  7:24   ` Christoph Hellwig
2018-05-16 20:27     ` Andreas Gruenbacher
2018-05-18 15:56       ` Christoph Hellwig
2018-05-18 18:35         ` Andreas Grünbacher [this message]

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=CAHpGcMLLCEwC_R_a-ud9-CJkdcdUVFdXfoVc5y+hnj6ezgyFfg@mail.gmail.com \
    --to=andreas.gruenbacher@gmail.com \
    --cc=agruenba@redhat.com \
    --cc=cluster-devel@redhat.com \
    --cc=dchinner@redhat.com \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@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;
as well as URLs for NNTP newsgroup(s).