Skip to contentSkip to conversation

NFSD: Return full WCC data for NFSv3 metadata operations

PATCH In review Chuck Lever 2 participants 4 messages Jul 8, 2010 1 message not in the archive

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

PATCH 1/1 NFSD: Return full WCC data for NFSv3 metadata operations

NFSv3 WCC data, or "weak cache consistency" data, is an attempt to reduce the number of on-the-wire transactions needed by NFS clients to keep their caches up to date. WCC data consists of two parts:

o pre-op data, which is a subset of file metadata as it was before a procedure starts, and

o post-op data, which is a full set of NFSv3 file attribute data as it is after a procedure finishes.

For an NFSv3 procedure that returns wcc_data, an NFSv3 server is free to return either, both, or neither of these. Define "full WCC data" as a reply that contains both pre-op and post-op data.

To make this data useful, a server must ensure that file metadata is captured atomically around the requested operation. If the pre-op data in a reply matches the file metadata that the client already has cached, the client can assume that no other operation on that file occurred while the server was fulfilling the current request, and that therefore the post-op metadata is the latest version, and can be cached.

Conversely, NFSv3 clients invalidate their metadata caches when they receive replies to metadata altering operations that do not contain full WCC data. When a server presents a reply that does not have both pre-op and post-op WCC data, clients must employ extra LOOKUP and GETATTR requests to ensure their metadata caches are up to date, causing performance to suffer needlessly. For example, untarring a large tar file can take almost an order of magnitude longer in this case, depending on the client implementation.

In the Linux NFS server implementation, to ensure that WCC data reflects only changes made during the current file system operation, the file's inode mutex is held in order to serialize metadata altering operations on that inode. Our server saves pre-op data for a file handle just after the target inode's mutex is taken, and saves post-op data just before the inode's mutex is dropped (see fh_lock() and fh_unlock()).

In order to return full WCC data to clients, our server must have both the saved pre-op and the saved post-op attribute data for a file handle filled in before it starts XDR encoding the reply. Unfortunately, for the NFSv3 MKDIR, MKNOD, REMOVE, RMDIR procedures, our server does not unlock the parent directory inode until well after the reply has been XDR encoded.

In these cases, encode_wcc_data() does have saved pre-op WCC data available, since the fh is locked, but does not have saved post-op WCC data for the parent directory, since it hasn't yet been unlocked. In this situation, encode_wcc_data() simply grabs the parent's current metadata, uses that as the post-op WCC data, and returns no pre-op WCC data to the client.

By instead unlocking the parent directory file handle immediately after the internal operations for each of these NFS procedures is complete, saved post-op WCC data for the file handle is filled in before XDR encoding starts, so full WCC data for that procedure can be returned to clients.

Note that the NFSv4 CREATE and REMOVE procedures already invoke fh_unlock() explicitly on the parent directory in order to fill in the NFSv4 post change attribute.

Note also that NFSv3 CREATE, RENAME, SETATTR, and SYMLINK already perform explicit file handle unlocking.

---

Bruce-

This patch is mechanically the same as the previous one, but the patch description has a more accurate and clearly stated rationale for the change.

Please use this one instead of the previous one.

 fs/nfsd/nfs3proc.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
fs/nfsd/nfs3proc.c +4 -2
index 3d68f45..9ae9331 100644
@@ -271,7 +271,7 @@ nfsd3_proc_mkdir(struct svc_rqst *rqstp, struct nfsd3_createargs *argp,
 	fh_init(&resp->fh, NFS3_FHSIZE);
 	nfserr = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
 				    &argp->attrs, S_IFDIR, 0, &resp->fh);
-
+	fh_unlock(&resp->dirfh);
 	RETURN_STATUS(nfserr);
 }
 
@@ -327,7 +327,7 @@ nfsd3_proc_mknod(struct svc_rqst *rqstp, struct nfsd3_mknodargs *argp,
 	type = nfs3_ftypes[argp->ftype];
 	nfserr = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
 				    &argp->attrs, type, rdev, &resp->fh);
-
+	fh_unlock(&resp->dirfh);
 	RETURN_STATUS(nfserr);
 }
 
@@ -348,6 +348,7 @@ nfsd3_proc_remove(struct svc_rqst *rqstp, struct nfsd3_diropargs *argp,
 	/* Unlink. -S_IFDIR means file must not be a directory */
 	fh_copy(&resp->fh, &argp->fh);
 	nfserr = nfsd_unlink(rqstp, &resp->fh, -S_IFDIR, argp->name, argp->len);
+	fh_unlock(&resp->fh);
 	RETURN_STATUS(nfserr);
 }
 
@@ -367,6 +368,7 @@ nfsd3_proc_rmdir(struct svc_rqst *rqstp, struct nfsd3_diropargs *argp,
 
 	fh_copy(&resp->fh, &argp->fh);
 	nfserr = nfsd_unlink(rqstp, &resp->fh, S_IFDIR, argp->name, argp->len);
+	fh_unlock(&resp->fh);
 	RETURN_STATUS(nfserr);
 }
 

A message that is not in the archive (sent off-list or not yet received): 20100708154037.2820.51702.stgit-ewv44WTpT0t9HhUboXbp9zCvJB+x5qRC@public.gmane.org

#2 lore raw
Quoted 69 lines · Chuck Lever

NFSv3 WCC data, or "weak cache consistency" data, is an attempt to reduce the number of on-the-wire transactions needed by NFS clients to keep their caches up to date. WCC data consists of two parts:

o pre-op data, which is a subset of file metadata as it was before a procedure starts, and

o post-op data, which is a full set of NFSv3 file attribute data as it is after a procedure finishes.

For an NFSv3 procedure that returns wcc_data, an NFSv3 server is free to return either, both, or neither of these. Define "full WCC data" as a reply that contains both pre-op and post-op data.

To make this data useful, a server must ensure that file metadata is captured atomically around the requested operation. If the pre-op data in a reply matches the file metadata that the client already has cached, the client can assume that no other operation on that file occurred while the server was fulfilling the current request, and that therefore the post-op metadata is the latest version, and can be cached.

Conversely, NFSv3 clients invalidate their metadata caches when they receive replies to metadata altering operations that do not contain full WCC data. When a server presents a reply that does not have both pre-op and post-op WCC data, clients must employ extra LOOKUP and GETATTR requests to ensure their metadata caches are up to date, causing performance to suffer needlessly. For example, untarring a large tar file can take almost an order of magnitude longer in this case, depending on the client implementation.

In the Linux NFS server implementation, to ensure that WCC data reflects only changes made during the current file system operation, the file's inode mutex is held in order to serialize metadata altering operations on that inode. Our server saves pre-op data for a file handle just after the target inode's mutex is taken, and saves post-op data just before the inode's mutex is dropped (see fh_lock() and fh_unlock()).

In order to return full WCC data to clients, our server must have both the saved pre-op and the saved post-op attribute data for a file handle filled in before it starts XDR encoding the reply. Unfortunately, for the NFSv3 MKDIR, MKNOD, REMOVE, RMDIR procedures, our server does not unlock the parent directory inode until well after the reply has been XDR encoded.

In these cases, encode_wcc_data() does have saved pre-op WCC data available, since the fh is locked, but does not have saved post-op WCC data for the parent directory, since it hasn't yet been unlocked. In this situation, encode_wcc_data() simply grabs the parent's current metadata, uses that as the post-op WCC data, and returns no pre-op WCC data to the client.

By instead unlocking the parent directory file handle immediately after the internal operations for each of these NFS procedures is complete, saved post-op WCC data for the file handle is filled in before XDR encoding starts, so full WCC data for that procedure can be returned to clients.

Note that the NFSv4 CREATE and REMOVE procedures already invoke fh_unlock() explicitly on the parent directory in order to fill in the NFSv4 post change attribute.

Note also that NFSv3 CREATE, RENAME, SETATTR, and SYMLINK already perform explicit file handle unlocking.

---

Quoted 7 lines

Bruce-

This patch is mechanically the same as the previous one, but the patch description has a more accurate and clearly stated rationale for the change.

Please use this one instead of the previous one.

Thanks. The first is already committed, though. I'm not sure if there's a good place for the longer explanation in the docs, so it may just have to live on in the list archives. (It's the testcase (untarring a linux kernel from an OS X client) that I was mainly curious about.)

--b.

#3 lore raw
Quoted 72 lines · J. Bruce Fields
Quoted 71 lines · Chuck Lever

NFSv3 WCC data, or "weak cache consistency" data, is an attempt to reduce the number of on-the-wire transactions needed by NFS clients to keep their caches up to date. WCC data consists of two parts:

o pre-op data, which is a subset of file metadata as it was before a procedure starts, and

o post-op data, which is a full set of NFSv3 file attribute data as it is after a procedure finishes.

For an NFSv3 procedure that returns wcc_data, an NFSv3 server is free to return either, both, or neither of these. Define "full WCC data" as a reply that contains both pre-op and post-op data.

To make this data useful, a server must ensure that file metadata is captured atomically around the requested operation. If the pre-op data in a reply matches the file metadata that the client already has cached, the client can assume that no other operation on that file occurred while the server was fulfilling the current request, and that therefore the post-op metadata is the latest version, and can be cached.

Conversely, NFSv3 clients invalidate their metadata caches when they receive replies to metadata altering operations that do not contain full WCC data. When a server presents a reply that does not have both pre-op and post-op WCC data, clients must employ extra LOOKUP and GETATTR requests to ensure their metadata caches are up to date, causing performance to suffer needlessly. For example, untarring a large tar file can take almost an order of magnitude longer in this case, depending on the client implementation.

In the Linux NFS server implementation, to ensure that WCC data reflects only changes made during the current file system operation, the file's inode mutex is held in order to serialize metadata altering operations on that inode. Our server saves pre-op data for a file handle just after the target inode's mutex is taken, and saves post-op data just before the inode's mutex is dropped (see fh_lock() and fh_unlock()).

In order to return full WCC data to clients, our server must have both the saved pre-op and the saved post-op attribute data for a file handle filled in before it starts XDR encoding the reply. Unfortunately, for the NFSv3 MKDIR, MKNOD, REMOVE, RMDIR procedures, our server does not unlock the parent directory inode until well after the reply has been XDR encoded.

In these cases, encode_wcc_data() does have saved pre-op WCC data available, since the fh is locked, but does not have saved post-op WCC data for the parent directory, since it hasn't yet been unlocked. In this situation, encode_wcc_data() simply grabs the parent's current metadata, uses that as the post-op WCC data, and returns no pre-op WCC data to the client.

By instead unlocking the parent directory file handle immediately after the internal operations for each of these NFS procedures is complete, saved post-op WCC data for the file handle is filled in before XDR encoding starts, so full WCC data for that procedure can be returned to clients.

Note that the NFSv4 CREATE and REMOVE procedures already invoke fh_unlock() explicitly on the parent directory in order to fill in the NFSv4 post change attribute.

Note also that NFSv3 CREATE, RENAME, SETATTR, and SYMLINK already perform explicit file handle unlocking.

---

Bruce-

Quoted 7 lines
Quoted 5 lines

This patch is mechanically the same as the previous one, but the patch description has a more accurate and clearly stated rationale for the change.

Please use this one instead of the previous one.

Thanks. The first is already committed, though.

And you can't use "git reset --soft ..." to fix the commit message because....?

#4 lore raw
Quoted 7 lines · Chuck Lever
Quoted 6 lines · J. Bruce Fields
Quoted 5 lines · Chuck Lever

This patch is mechanically the same as the previous one, but the patch description has a more accurate and clearly stated rationale for the change.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Please use this one instead of the previous one.

Thanks. The first is already committed, though.

And you can't use "git reset --soft ..." to fix the commit message because....?

The public for-2.6.x branches only fast-forward. I'd prefer to keep it that way.

--b.