linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chris Mason <chris.mason@fusionio.com>
To: Miao Xie <miaox@cn.fujitsu.com>
Cc: Josef Bacik <JBacik@fusionio.com>,
	"linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH] Btrfs: fix dio write vs buffered read race V2
Date: Fri, 29 Jun 2012 09:05:10 -0400	[thread overview]
Message-ID: <20120629130510.GY17638@shiny> (raw)
In-Reply-To: <4FED107B.9020308@cn.fujitsu.com>

On Thu, Jun 28, 2012 at 08:18:35PM -0600, Miao Xie wrote:
> On Thu, 28 Jun 2012 08:34:23 -0400, Josef Bacik wrote:
> > On Wed, Jun 27, 2012 at 09:35:08PM -0600, Miao Xie wrote:
> >> On Tue, 26 Jun 2012 09:42:56 -0400, Josef Bacik wrote:
> >>> From: Josef Bacik <josef@redhat.com>
> >>>
> >>> Miao pointed out there's a problem with mixing dio writes and buffered
> >>> reads.  If the read happens between us invalidating the page range and
> >>> actually locking the extent we can bring in pages into page cache.  Then
> >>> once the write finishes if somebody tries to read again it will just find
> >>> uptodate pages and we'll read stale data.  So we need to lock the extent and
> >>> check for uptodate bits in the range.  If there are uptodate bits we need to
> >>> unlock and invalidate again.  This will keep this race from happening since
> >>> we will hold the extent locked until we create the ordered extent, and then
> >>> teh read side always waits for ordered extents.  Thanks,
> >>
> >> This patch still can not work well. It is because we don't update i_size in time.
> >> 	Writer		Worker		Reader
> >> 	lock_extent
> >> 	do direct io
> >> 	end io
> >> 			finish io
> >> 			unlock_extent
> >> 					lock_extent
> >> 					check the pos is beyond EOF or not
> >> 					  beyond EOF, zero the page and set it uptodate
> >> 					unlock_extent
> >> 	update i_size
> >>
> >> So I think we must update the i_size in time, and I wrote a small patch to do it:
> >>
> > 
> > We should probably be updating i_size when we create an extent past EOF in the
> > write stuff, not during endio, I will work this out and fold it into my patch.
> > Good catch.
> 
> It is better that update i_size in endio, I think. because during endio, we are sure that
> the data is flushed into the disk successfully, and can update i_size at ease. and if the
> error happens when flushing the data into the disk, we also needn't reset i_size.

I think the i_size update should happen sooner.  The rest of the
filesystems work that way, and it will have fewer interaction problems
with the VM.

-chris

  reply	other threads:[~2012-06-29 13:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-26 13:42 [PATCH] Btrfs: fix dio write vs buffered read race V2 Josef Bacik
2012-06-28  3:35 ` Miao Xie
2012-06-28 12:34   ` Josef Bacik
2012-06-29  2:18     ` Miao Xie
2012-06-29 13:05       ` Chris Mason [this message]
2012-07-01 10:24         ` Miao Xie
2012-07-02  6:19         ` 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=20120629130510.GY17638@shiny \
    --to=chris.mason@fusionio.com \
    --cc=JBacik@fusionio.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=miaox@cn.fujitsu.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).