Skip to contentSkip to conversation

nfs: open-associated setattr shouldn't invalidate own cache

PATCH Myklebust, Trond 3 participants 13 messages Jul 19, 2011 – Nov 3, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

We should already optimize away the unnecessary setting of the size. The problem is that truncate() still requires you to set the ctime, whereas ftruncate() does not iirc.

"J. Bruce Fields" <[email protected]> wrote:

From: "J. Bruce Fields" <[email protected]>

We recently noticed that NFSv4 iozone read tests that should have been performing at local-cache speeds were running at wire speeds, and found that currently,

	open(O_RDWR|O_TRUNC)
	write()
	close()
	open(O_RDONLY)
	read()

results in an over-the-wire read (due to a setattr triggered by O_TRUNC). Even non-O_TRUNC opens send setattrs (of timestamps) in some cases, causing the same problem.

In discussion with Trond, he blames a VFS bug for breaking what should be a single open into an open followed by a setattr.

However, it may make sense even in a case like

	open(O_RDWR)
	write()
	setattr()
	close()
	open(O_RDONLY)
	read()

to treat the setattr similarly to the write, and not invalidate the client's own cache as long as the setattr is performed under a write open.

(That said, I don't know if this is the correct place in the code to implement that behavior.)

---
 fs/nfs/inode.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
fs/nfs/inode.c +6 -1
index 6f4850d..d4eed06 100644
@@ -438,8 +438,13 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
 	if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0)
 		nfs_inode_return_delegation(inode);
 	error = NFS_PROTO(inode)->setattr(dentry, fattr, attr);
-	if (error == 0)
+	if (error)
+		goto out_free;
+	if (attr->ia_valid & ATTR_FILE)
+		nfs_post_op_update_inode_force_wcc(inode, fattr);
+	else
 		nfs_refresh_inode(inode, fattr);
+out_free:
 	nfs_free_fattr(fattr);
 out:
 	return error;
Signature · 1 line
1.7.6
#1 lore raw
Quoted 1 line · Trond

We should already optimize away the unnecessary setting of the size.

Do you remember what commit fixed that? (Was it an nfs change or a vfs change?)

Quoted 1 line

The problem is that truncate() still requires you to set the ctime, whereas ftruncate() does not iirc.

Staring at the code.... I think you mean the opposite? I notice do_sys_ftruncate() calling

	do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);

and do_sys_truncate() calling

	do_truncate(path.dentry, length, 0, NULL);

where the third argument is getting OR'd with ATTR_FILE to pass into notify_change().

Also even when a setattr does get through, I don't understand why it should be invalidating our data cache. Is there some reason it needs to, or is this just a case that hasn't seemed worth fixing?

--b.

Quoted 69 lines

"J. Bruce Fields" <[email protected]> wrote:

From: "J. Bruce Fields" <[email protected]>

We recently noticed that NFSv4 iozone read tests that should have been performing at local-cache speeds were running at wire speeds, and found that currently,

	open(O_RDWR|O_TRUNC)
	write()
	close()
	open(O_RDONLY)
	read()

results in an over-the-wire read (due to a setattr triggered by O_TRUNC). Even non-O_TRUNC opens send setattrs (of timestamps) in some cases, causing the same problem.

In discussion with Trond, he blames a VFS bug for breaking what should be a single open into an open followed by a setattr.

However, it may make sense even in a case like

	open(O_RDWR)
	write()
	setattr()
	close()
	open(O_RDONLY)
	read()

to treat the setattr similarly to the write, and not invalidate the client's own cache as long as the setattr is performed under a write open.

(That said, I don't know if this is the correct place in the code to implement that behavior.)

---
 fs/nfs/inode.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
fs/nfs/inode.c +6 -1
index 6f4850d..d4eed06 100644
@@ -438,8 +438,13 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
 	if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0)
 		nfs_inode_return_delegation(inode);
 	error = NFS_PROTO(inode)->setattr(dentry, fattr, attr);
-	if (error == 0)
+	if (error)
+		goto out_free;
+	if (attr->ia_valid & ATTR_FILE)
+		nfs_post_op_update_inode_force_wcc(inode, fattr);
+	else
 		nfs_refresh_inode(inode, fattr);
+out_free:
 	nfs_free_fattr(fattr);
 out:
 	return error;
Signature · 6 lines
1.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
Quoted 6 lines

-----Original Message-----
From: J. Bruce Fields [mailto:[email protected]]
Sent: Tuesday, November 01, 2011 4:27 PM
To: Myklebust, Trond
Cc: J. Bruce Fields; Myklebust, Trond; [email protected]
Subject: Re: [PATCH] nfs: open-associated setattr shouldn't invalidate

own

Quoted 6 lines

cache

Quoted 1 line · Trond

We should already optimize away the unnecessary setting of the size.

Do you remember what commit fixed that? (Was it an nfs change or a

vfs

Quoted 1 line

change?)

It predates the git repository. See the comment about "Optimization:" in nfs_setattr().

Quoted 1 line
Quoted 1 line

The problem is that truncate() still requires you to set the ctime,

whereas

Quoted 5 lines

ftruncate() does not iirc.

Staring at the code.... I think you mean the opposite? I notice do_sys_ftruncate() calling

Quoted 8 lines
	do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);

and do_sys_truncate() calling

	do_truncate(path.dentry, length, 0, NULL);

where the third argument is getting OR'd with ATTR_FILE to pass into notify_change().

Sorry, yes. ftruncate() is the one that unconditionally sets the mtime/ctime on success according to the POSIX spec.

Quoted 1 line

Also even when a setattr does get through, I don't understand why it

should

Quoted 1 line

be invalidating our data cache. Is there some reason it needs to, or

is this just

Quoted 1 line

a case that hasn't seemed worth fixing?

Is the problem perhaps that we should be clearing the NFS_INO_INVALID_DATA flag in nfs_vmtruncate() when the size gets set to zero?

The other micro-optimisation that we might want to consider is to not set NFS_INO_INVALID_DATA in nfs_update_inode() if inode->i_data.nrpages == 0.

Cheers
Trond

Quoted 5 lines
Quoted 5 lines

"J. Bruce Fields" <[email protected]> wrote:

From: "J. Bruce Fields" <[email protected]>

We recently noticed that NFSv4 iozone read tests that should have

been

Quoted 9 lines
Quoted 9 lines

performing at local-cache speeds were running at wire speeds, and found that currently,

	open(O_RDWR|O_TRUNC)
	write()
	close()
	open(O_RDONLY)
	read()
Quoted 5 lines
Quoted 5 lines

results in an over-the-wire read (due to a setattr triggered by O_TRUNC). Even non-O_TRUNC opens send setattrs (of timestamps) in some cases, causing the same problem.

In discussion with Trond, he blames a VFS bug for breaking what

should

Quoted 51 lines

fs/nfs/inode.c nfs_setattr(struct dentry *dentry, struct iattr

Quoted 28 lines

be a single open into an open followed by a setattr.

However, it may make sense even in a case like

	open(O_RDWR)
	write()
	setattr()
	close()
	open(O_RDONLY)
	read()

to treat the setattr similarly to the write, and not invalidate the client's own cache as long as the setattr is performed under a write open.

(That said, I don't know if this is the correct place in the code to implement that behavior.)

---
 fs/nfs/inode.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
fs/nfs/inode.c index 6f4850d..d4eed06 renamed from fs/nfs/inode.c +0 -0

100644

fs/nfs/inode.c +0 -0
@@ -438,8 +438,13 @@ nfs_setattr(struct dentry *dentry, struct iattr

*attr)

Quoted 17 lines
fs/nfs/inode.c +6 -2
 	if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0)
 		nfs_inode_return_delegation(inode);
 	error = NFS_PROTO(inode)->setattr(dentry, fattr, attr);
-	if (error == 0)
+	if (error)
+		goto out_free;
+	if (attr->ia_valid & ATTR_FILE)
+		nfs_post_op_update_inode_force_wcc(inode, fattr);
+	else
 		nfs_refresh_inode(inode, fattr);
+out_free:
 	nfs_free_fattr(fattr);
 out:
 	return error;
--

1.7.6

Quoted 3 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More

majordomo

Quoted 1 line

info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 30 lines · Trond
Quoted 6 lines

-----Original Message-----
From: J. Bruce Fields [mailto:[email protected]]
Sent: Tuesday, November 01, 2011 4:27 PM
To: Myklebust, Trond
Cc: J. Bruce Fields; Myklebust, Trond; [email protected]
Subject: Re: [PATCH] nfs: open-associated setattr shouldn't invalidate

own

Quoted 6 lines

cache

Quoted 1 line · Trond

We should already optimize away the unnecessary setting of the size.

Do you remember what commit fixed that? (Was it an nfs change or a

vfs

Quoted 1 line

change?)

It predates the git repository. See the comment about "Optimization:" in nfs_setattr().

Quoted 1 line
Quoted 1 line

The problem is that truncate() still requires you to set the ctime,

whereas

Quoted 9 lines

ftruncate() does not iirc.

Staring at the code.... I think you mean the opposite? I notice do_sys_ftruncate() calling

	do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);

and do_sys_truncate() calling

Quoted 8 lines
Quoted 4 lines
	do_truncate(path.dentry, length, 0, NULL);

where the third argument is getting OR'd with ATTR_FILE to pass into notify_change().

Sorry, yes. ftruncate() is the one that unconditionally sets the mtime/ctime on success according to the POSIX spec.

Even when it's a noop? Blech.

Quoted 10 lines
Quoted 1 line

Also even when a setattr does get through, I don't understand why it

should

Quoted 1 line

be invalidating our data cache. Is there some reason it needs to, or

is this just

Quoted 1 line

a case that hasn't seemed worth fixing?

Is the problem perhaps that we should be clearing the NFS_INO_INVALID_DATA flag in nfs_vmtruncate() when the size gets set to zero?

That was my thinking too. Whenever we truncate the i_size to 0, we can safely assume that the pagecache is now valid, and should be able to clear NFS_INO_INVALID_DATA no matter when it was set, right?

Quoted 4 lines

The other micro-optimisation that we might want to consider is to not set NFS_INO_INVALID_DATA in nfs_update_inode() if inode->i_data.nrpages == 0.

This I'm a little less clear on...

If we find that another host has truncated the i_size to 0, don't we still need to call invalidate_inode_pages2() somehow?

Signature · 1 line
Jeff Layton <[email protected]>
#4 lore raw
Quoted 50 lines · Jeff Layton
Quoted 30 lines · Trond
Quoted 6 lines

-----Original Message-----
From: J. Bruce Fields [mailto:[email protected]]
Sent: Tuesday, November 01, 2011 4:27 PM
To: Myklebust, Trond
Cc: J. Bruce Fields; Myklebust, Trond; [email protected]
Subject: Re: [PATCH] nfs: open-associated setattr shouldn't invalidate

own

Quoted 6 lines

cache

Quoted 1 line · Trond

We should already optimize away the unnecessary setting of the size.

Do you remember what commit fixed that? (Was it an nfs change or a

vfs

Quoted 1 line

change?)

It predates the git repository. See the comment about "Optimization:" in nfs_setattr().

Quoted 1 line
Quoted 1 line

The problem is that truncate() still requires you to set the ctime,

whereas

Quoted 9 lines

ftruncate() does not iirc.

Staring at the code.... I think you mean the opposite? I notice do_sys_ftruncate() calling

	do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);

and do_sys_truncate() calling

Quoted 8 lines
Quoted 4 lines
	do_truncate(path.dentry, length, 0, NULL);

where the third argument is getting OR'd with ATTR_FILE to pass into notify_change().

Sorry, yes. ftruncate() is the one that unconditionally sets the mtime/ctime on success according to the POSIX spec.

Even when it's a noop? Blech.

Quoted 6 lines
Quoted 1 line

Also even when a setattr does get through, I don't understand why it

should

Quoted 1 line

be invalidating our data cache. Is there some reason it needs to, or

is this just

Quoted 1 line

a case that hasn't seemed worth fixing?

Quoted 8 lines
Quoted 4 lines

Is the problem perhaps that we should be clearing the NFS_INO_INVALID_DATA flag in nfs_vmtruncate() when the size gets set to zero?

That was my thinking too. Whenever we truncate the i_size to 0, we can safely assume that the pagecache is now valid, and should be able to clear NFS_INO_INVALID_DATA no matter when it was set, right?

I don't understand why 0 is a special case: why should my setting the size ever mean that I have to go reread data from the server?

--b.

#5 lore raw
Quoted 6 lines

-----Original Message-----
From: J. Bruce Fields [mailto:[email protected]]
Sent: Tuesday, November 01, 2011 9:23 PM
To: Jeff Layton
Cc: Myklebust, Trond; J. Bruce Fields; [email protected]
Subject: Re: [PATCH] nfs: open-associated setattr shouldn't invalidate

own

Quoted 17 lines

cache

Quoted 14 lines · Jeff Layton
Quoted 11 lines · Trond
Quoted 7 lines

-----Original Message-----
From: J. Bruce Fields [mailto:[email protected]]
Sent: Tuesday, November 01, 2011 4:27 PM
To: Myklebust, Trond
Cc: J. Bruce Fields; Myklebust, Trond; [email protected]
Subject: Re: [PATCH] nfs: open-associated setattr shouldn't invalidate

own

Quoted 3 lines

cache

On Mon, Jul 18, 2011 at 08:09:15PM -0400, Myklebust, Trond

Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

We should already optimize away the unnecessary setting of the

size.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Do you remember what commit fixed that? (Was it an nfs change

or

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line

a

vfs

Quoted 1 line

change?)

It predates the git repository. See the comment about "Optimization:" in nfs_setattr().

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

The problem is that truncate() still requires you to set the ctime,

whereas

Quoted 3 lines

ftruncate() does not iirc.

Staring at the code.... I think you mean the opposite? I

notice

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

do_sys_ftruncate() calling

do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME,

file);

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

and do_sys_truncate() calling

	do_truncate(path.dentry, length, 0, NULL);

where the third argument is getting OR'd with ATTR_FILE to pass into notify_change().

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

Sorry, yes. ftruncate() is the one that unconditionally sets the mtime/ctime on success according to the POSIX spec.

Even when it's a noop? Blech.

Quoted 1 line
Quoted 1 line

Also even when a setattr does get through, I don't understand

why

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

it

should

Quoted 1 line

be invalidating our data cache. Is there some reason it needs

to,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line

or

is this just

Quoted 1 line

a case that hasn't seemed worth fixing?

Is the problem perhaps that we should be clearing the NFS_INO_INVALID_DATA flag in nfs_vmtruncate() when the size gets

set

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

to zero?

That was my thinking too. Whenever we truncate the i_size to 0, we

can

Quoted 4 lines
Quoted 2 lines

safely assume that the pagecache is now valid, and should be able to clear NFS_INO_INVALID_DATA no matter when it was set, right?

I don't understand why 0 is a special case: why should my setting the

size

Quoted 1 line

ever mean that I have to go reread data from the server?

Your test case was:

open(O_RDWR|O_TRUNCATE)
write()
close()
open(O_RDONLY)
read()
...

That truncates _all_ data, so there is nothing left in the data cache when we get to the write().

The question therefore is not "Why does setattr clear my cache?".

The question is "Why isn't that write() cached?".

That's why I'm exploring reasons why the cache might get cleared after that write(). The other obvious one would be if the server is failing to return post-op attributes in the WRITE reply.

Trond

#6 lore raw
In reply to J. Bruce Fields
Quoted 56 lines · On Tue, 1 Nov 2011 21:23:15 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 55 lines · Jeff Layton
Quoted 30 lines · Trond
Quoted 6 lines

-----Original Message-----
From: J. Bruce Fields [mailto:[email protected]]
Sent: Tuesday, November 01, 2011 4:27 PM
To: Myklebust, Trond
Cc: J. Bruce Fields; Myklebust, Trond; [email protected]
Subject: Re: [PATCH] nfs: open-associated setattr shouldn't invalidate

own

Quoted 6 lines

cache

Quoted 1 line · Trond

We should already optimize away the unnecessary setting of the size.

Do you remember what commit fixed that? (Was it an nfs change or a

vfs

Quoted 1 line

change?)

It predates the git repository. See the comment about "Optimization:" in nfs_setattr().

Quoted 1 line
Quoted 1 line

The problem is that truncate() still requires you to set the ctime,

whereas

Quoted 9 lines

ftruncate() does not iirc.

Staring at the code.... I think you mean the opposite? I notice do_sys_ftruncate() calling

	do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);

and do_sys_truncate() calling

Quoted 8 lines
Quoted 4 lines
	do_truncate(path.dentry, length, 0, NULL);

where the third argument is getting OR'd with ATTR_FILE to pass into notify_change().

Sorry, yes. ftruncate() is the one that unconditionally sets the mtime/ctime on success according to the POSIX spec.

Even when it's a noop? Blech.

Quoted 10 lines
Quoted 1 line

Also even when a setattr does get through, I don't understand why it

should

Quoted 1 line

be invalidating our data cache. Is there some reason it needs to, or

is this just

Quoted 1 line

a case that hasn't seemed worth fixing?

Is the problem perhaps that we should be clearing the NFS_INO_INVALID_DATA flag in nfs_vmtruncate() when the size gets set to zero?

Quoted 7 lines
Quoted 3 lines

That was my thinking too. Whenever we truncate the i_size to 0, we can safely assume that the pagecache is now valid, and should be able to clear NFS_INO_INVALID_DATA no matter when it was set, right?

I don't understand why 0 is a special case: why should my setting the size ever mean that I have to go reread data from the server?

If the server doesn't send pre-op attrs (and linux servers don't) then you have no way to know whether someone raced in and did writes to the remaining pages just prior to your truncate.

Size 0 is a special case because there are no remaining pages.

Signature · 1 line
Jeff Layton <[email protected]>
#7 lore raw
Quoted 19 lines · Jeff Layton
Quoted 8 lines · On Tue, 1 Nov 2011 21:23:15 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 7 lines · Jeff Layton
Quoted 4 lines · Trond

Is the problem perhaps that we should be clearing the NFS_INO_INVALID_DATA flag in nfs_vmtruncate() when the size gets set to zero?

Quoted 7 lines
Quoted 3 lines

That was my thinking too. Whenever we truncate the i_size to 0, we can safely assume that the pagecache is now valid, and should be able to clear NFS_INO_INVALID_DATA no matter when it was set, right?

I don't understand why 0 is a special case: why should my setting the size ever mean that I have to go reread data from the server?

Quoted 5 lines

If the server doesn't send pre-op attrs (and linux servers don't) then you have no way to know whether someone raced in and did writes to the remaining pages just prior to your truncate.

Size 0 is a special case because there are no remaining pages.

Those 3rd-party writes could also arrive between the truncate and the read of the post-op attrs. Is this setattr/write conflict really any different than write/write conflicts? In both cases you've got a file open for write on two different clients.

And we live with the same sort of race in the write/write case. (Hence the nfs_post_op_update_inode_force_wcc in nfs4_write_done_cb.)

--b.

#8 lore raw
Quoted 26 lines · On Wed, 2 Nov 2011 10:46:57 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 19 lines · Jeff Layton
Quoted 8 lines · On Tue, 1 Nov 2011 21:23:15 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 7 lines · Jeff Layton
Quoted 4 lines · Trond

Is the problem perhaps that we should be clearing the NFS_INO_INVALID_DATA flag in nfs_vmtruncate() when the size gets set to zero?

Quoted 7 lines
Quoted 3 lines

That was my thinking too. Whenever we truncate the i_size to 0, we can safely assume that the pagecache is now valid, and should be able to clear NFS_INO_INVALID_DATA no matter when it was set, right?

I don't understand why 0 is a special case: why should my setting the size ever mean that I have to go reread data from the server?

Quoted 5 lines

If the server doesn't send pre-op attrs (and linux servers don't) then you have no way to know whether someone raced in and did writes to the remaining pages just prior to your truncate.

Size 0 is a special case because there are no remaining pages.

Quoted 8 lines

Those 3rd-party writes could also arrive between the truncate and the read of the post-op attrs. Is this setattr/write conflict really any different than write/write conflicts? In both cases you've got a file open for write on two different clients.

And we live with the same sort of race in the write/write case. (Hence the nfs_post_op_update_inode_force_wcc in nfs4_write_done_cb.)

Yes, I think it is different. When we truncate the file to 0 then we don't care if another write races in. 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 that indicate that something else happened prior to the truncate, or if the server doesn't send pre-op attrs at all.

Signature · 1 line
Jeff Layton <[email protected]>
#9 lore raw

I'm feeling dense.

Quoted 2 lines · Jeff Layton

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.

Quoted 11 lines

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.

Quoted 3 lines

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.

Quoted 3 lines

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

#10 lore raw
Quoted 9 lines · J. Bruce Fields

I'm feeling dense.

Quoted 2 lines · Jeff Layton

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
-------- --------

Quoted 6 lines

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.

?????????

How can we "decide not to invalidate the cache here"? the call to nfs_vmtruncate() will _always_ call truncate_pagecache(). The only case where we don't call nfs_vmtruncate() is if the client has already determined that the file size was zero, and optimised away the setattr call altogether.

Quoted 11 lines

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.

When did we move to the topic of multiple clients, and why do you think it is relevant?

Signature · 6 lines
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com
#11 lore raw
Quoted 17 lines · Trond Myklebust
Quoted 9 lines · J. Bruce Fields

I'm feeling dense.

Quoted 2 lines · Jeff Layton

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
-------- --------

Quoted 6 lines

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.

Quoted 6 lines

?????????
How can we "decide not to invalidate the cache here"? the call to nfs_vmtruncate() will _always_ call truncate_pagecache(). The only case where we don't call nfs_vmtruncate() is if the client has already determined that the file size was zero, and optimised away the setattr call altogether.

Sorry, I'm probably using the wrong language.

I'm using the word "cache" to refer not to the page cache, but more generally to the client's idea of the file state. Thus if the client, after the above operation, is left believing the file has size 0, I wouldn't say it has invalidated its cache, I'd say it's cached the fact that the file has size zero....

Does what I said make sense, given that?

Quoted 7 lines
Quoted 7 lines

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.

Quoted 7 lines
Quoted 4 lines

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.

When did we move to the topic of multiple clients, and why do you think it is relevant?

We're seeing the client decide that it can no longer trust its idea of the file, presumably because it no longer believes it safe to assume that nobody else has modified it.

--b.

#12 lore raw
Quoted 27 lines · J. Bruce Fields
Quoted 17 lines · Trond Myklebust
Quoted 9 lines · J. Bruce Fields

I'm feeling dense.

Quoted 2 lines · Jeff Layton

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
-------- --------

Quoted 6 lines

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.

Quoted 6 lines

?????????
How can we "decide not to invalidate the cache here"? the call to nfs_vmtruncate() will _always_ call truncate_pagecache(). The only case where we don't call nfs_vmtruncate() is if the client has already determined that the file size was zero, and optimised away the setattr call altogether.

Sorry, I'm probably using the wrong language.

Quoted 7 lines

I'm using the word "cache" to refer not to the page cache, but more generally to the client's idea of the file state. Thus if the client, after the above operation, is left believing the file has size 0, I wouldn't say it has invalidated its cache, I'd say it's cached the fact that the file has size zero....

Does what I said make sense, given that?

Nope; I'm still lost.

So if the client is caching a file size of 0, why would it "miss a write"? It will soon see that the file size on the server is non-zero. In fact, your 'get change attribute' will always be accompanied by a 'get file size' that will detect the changed size right there...

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

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.

Quoted 6 lines
Quoted 2 lines

When did we move to the topic of multiple clients, and why do you think it is relevant?

We're seeing the client decide that it can no longer trust its idea of the file, presumably because it no longer believes it safe to assume that nobody else has modified it.

Did you look into the race I described yesterday? That doesn't require a client 2.

Signature · 6 lines
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com