linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH V2] xfs: properly serialise fallocate against AIO+DIO
Date: Wed, 30 Oct 2019 10:54:39 +1100	[thread overview]
Message-ID: <20191029235439.GP4614@dread.disaster.area> (raw)
In-Reply-To: <20191029233337.GH15222@magnolia>

On Tue, Oct 29, 2019 at 04:33:37PM -0700, Darrick J. Wong wrote:
> On Wed, Oct 30, 2019 at 09:37:52AM +1100, Dave Chinner wrote:
> > From: Dave Chinner <dchinner@redhat.com>
> > 
> > AIO+DIO can extend the file size on IO completion, and it holds
> > no inode locks while the IO is in flight. Therefore, a race
> > condition exists in file size updates if we do something like this:
> > 
> > aio-thread			fallocate-thread
> > 
> > lock inode
> > submit IO beyond inode->i_size
> > unlock inode
> > .....
> > 				lock inode
> > 				break layouts
> > 				if (off + len > inode->i_size)
> > 					new_size = off + len
> > 				.....
> > 				inode_dio_wait()
> > 				<blocks>
> > .....
> > completes
> > inode->i_size updated
> > inode_dio_done()
> > ....
> > 				<wakes>
> > 				<does stuff no long beyond EOF>
> > 				if (new_size)
> > 					xfs_vn_setattr(inode, new_size)
> > 
> > 
> > Yup, that attempt to extend the file size in the fallocate code
> > turns into a truncate - it removes the whatever the aio write
> > allocated and put to disk, and reduced the inode size back down to
> > where the fallocate operation ends.
> > 
> > Fundamentally, xfs_file_fallocate()  not compatible with racing
> > AIO+DIO completions, so we need to move the inode_dio_wait() call
> > up to where the lock the inode and break the layouts.
> > 
> > Secondly, storing the inode size and then using it unchecked without
> > holding the ILOCK is not safe; we can only do such a thing if we've
> > locked out and drained all IO and other modification operations,
> > which we don't do initially in xfs_file_fallocate.
> > 
> > It should be noted that some of the fallocate operations are
> > compound operations - they are made up of multiple manipulations
> > that may zero data, and so we may need to flush and invalidate the
> > file multiple times during an operation. However, we only need to
> > lock out IO and other space manipulation operations once, as that
> > lockout is maintained until the entire fallocate operation has been
> > completed.
> > 
> > Signed-off-by: Dave Chinner <dchinner@redhat.com>
> 
> Looks reasonable to me; what do you think of my regression test?

Looks reasonable at a first glance. Not much different what I was
using to test this patch. I haven't looked in more detail than that
yet...

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

  reply	other threads:[~2019-10-29 23:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-29 22:37 [PATCH V2] xfs: properly serialise fallocate against AIO+DIO Dave Chinner
2019-10-29 23:33 ` Darrick J. Wong
2019-10-29 23:54   ` Dave Chinner [this message]
2019-10-30 12:46 ` Brian Foster
2019-10-30 14:26 ` Christoph Hellwig
2019-10-31 21:06   ` Dave Chinner
2019-11-20  2:38 ` Darrick J. Wong
2019-11-21  6:50   ` 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=20191029235439.GP4614@dread.disaster.area \
    --to=david@fromorbit.com \
    --cc=darrick.wong@oracle.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 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).