linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: Jeff Layton <jlayton@redhat.com>
Cc: "Myklebust, Trond" <Trond.Myklebust@netapp.com>,
	"J. Bruce Fields" <bfields@redhat.com>,
	linux-nfs@vger.kernel.org
Subject: Re: [PATCH] nfs: open-associated setattr shouldn't invalidate own cache
Date: Thu, 3 Nov 2011 16:44:49 -0400	[thread overview]
Message-ID: <20111103204449.GA27393@fieldses.org> (raw)
In-Reply-To: <20111102115453.7e81168f@corrin.poochiereds.net>

I'm feeling dense.

On Wed, Nov 02, 2011 at 11:54:53AM -0400, Jeff Layton wrote:
> Yes, I think it is different. When we truncate the file to 0 then we
> don't care if another write races in.

	Client 1		Client 2
	--------		--------

	setattr size to 0
				write to file
	get change attribute

If we decide not to invalidate the cache here, then we miss Client 2's
write.  The same is true if we set the size to something other than 0.

There's a second possible race when Client 2's write comes before the
setattr, and it's true that that race doesn't matter in the size-0 case
and does in the other.

But if we were doing a write instead of a setattr, we'd ignore that
second race.

And I don't understand why something like ftruncate should be treated
differently from write.  In either case we're modifying a file while
holding a write open, and I'd expect us to assume in both cases that
nobody else is doing the same.

> We're invalidating all of the
> pages we have cached for the file at that point anyway. If we try to
> reread the file afterward we're going to have to fetch the data from
> the server regardless.
> 
> I guess my main point is that we won't have any cached data after a
> truncate to 0, so there's no need to worry about ensuring that the
> cache is eventually invalidated after that. The VFS-level truncate on
> the client is going to take care of that for us anyway. That allows us
> to optimize for this special (but common) case.
> 
> A truncate to a non-zero size is different however because we may still
> have lingering cached pages. We will need to invalidate those if the
> server sends pre-op attrs

There are no pre-op attrs: the Linux v4 client's write compound is
putfh, write, getattr, with no getattr before the write, and the
nfs_post_op_update_inode_force_wcc() call in nfs4_write_done_cb() makes
the client pretends there were pre-op attributes the same as whatever it
currently has cached in the inode--if I understand it right.

--b.

> that indicate that something else happened
> prior to the truncate, or if the server doesn't send pre-op attrs at
> all.

  reply	other threads:[~2011-11-03 20:44 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-19  0:09 [PATCH] nfs: open-associated setattr shouldn't invalidate own cache Myklebust, Trond
2011-11-01 20:27 ` J. Bruce Fields
2011-11-01 23:07   ` Myklebust, Trond
2011-11-02  0:43     ` Jeff Layton
2011-11-02  1:23       ` J. Bruce Fields
2011-11-02  1:36         ` Myklebust, Trond
2011-11-02 11:07         ` Jeff Layton
2011-11-02 14:46           ` J. Bruce Fields
2011-11-02 15:54             ` Jeff Layton
2011-11-03 20:44               ` J. Bruce Fields [this message]
2011-11-03 21:03                 ` Trond Myklebust
2011-11-03 21:20                   ` J. Bruce Fields
2011-11-03 21:39                     ` Trond Myklebust
  -- strict thread matches above, loose matches on Subject: below --
2011-07-18 22:23 J. Bruce Fields

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=20111103204449.GA27393@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=Trond.Myklebust@netapp.com \
    --cc=bfields@redhat.com \
    --cc=jlayton@redhat.com \
    --cc=linux-nfs@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).