Skip to contentSkip to conversation

More short subjects for 2.6.34

PATCH New Chuck Lever 1 participant 6 messages Feb 1, 2010 1 message not in the archive

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

cover More short subjects for 2.6.34

Here are some performance metric accounting fixes to consider for 2.6.34. Also, a close(2) optimization for O_DIRECT files.

---

Chuck Lever (5):
NFS: Make close(2) asynchronous when closing NFS O_DIRECT files
NFS: Improve NFS iostat byte count accuracy for writes
NFS: Account for NFS bytes read via the splice API
NFS: Fix byte accounting for generic NFS reads
NFS: Proper accounting for NFS VFS calls

 fs/nfs/file.c  |   30 ++++++++++++++++++++++--------
 fs/nfs/inode.c |    7 +------
 2 files changed, 23 insertions(+), 14 deletions(-)
Signature · 1 line
Chuck Lever

A message that is not in the archive (sent off-list or not yet received): 20100201191415.20189.39710.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]

#2 lore raw

PATCH 1/5 NFS: Proper accounting for NFS VFS calls

Nit: The VFSOPEN and VFSFLUSH counters are function call counters. Count every call to these routines.

---

 fs/nfs/file.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
fs/nfs/file.c +2 -2
index 6b89132..f028e7d 100644
@@ -123,11 +123,11 @@ nfs_file_open(struct inode *inode, struct file *filp)
 			filp->f_path.dentry->d_parent->d_name.name,
 			filp->f_path.dentry->d_name.name);
 
+	nfs_inc_stats(inode, NFSIOS_VFSOPEN);
 	res = nfs_check_flags(filp->f_flags);
 	if (res)
 		return res;
 
-	nfs_inc_stats(inode, NFSIOS_VFSOPEN);
 	res = nfs_open(inode, filp);
 	return res;
 }
@@ -237,9 +237,9 @@ nfs_file_flush(struct file *file, fl_owner_t id)
 			dentry->d_parent->d_name.name,
 			dentry->d_name.name);
 
+	nfs_inc_stats(inode, NFSIOS_VFSFLUSH);
 	if ((file->f_mode & FMODE_WRITE) == 0)
 		return 0;
-	nfs_inc_stats(inode, NFSIOS_VFSFLUSH);
 
 	/* Flush writes to the server and return any errors */
 	return nfs_do_fsync(ctx, inode);
#3 lore raw

PATCH 2/5 NFS: Fix byte accounting for generic NFS reads

In reply to a message not in the archive

Currently, the NFS I/O counters count the number of bytes requested by applications, rather than the number of bytes actually read by the system calls.

The number of bytes requested for reads is actually not that useful, because the value is usually a buffer size for reads. That is, that requested number is usually a maximum, and frequently doesn't reflect the actual number of bytes read.

---

 fs/nfs/file.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
fs/nfs/file.c +4 -2
index f028e7d..3c65a6b 100644
@@ -262,9 +262,11 @@ nfs_file_read(struct kiocb *iocb, const struct iovec *iov,
 		(unsigned long) count, (unsigned long) pos);
 
 	result = nfs_revalidate_mapping(inode, iocb->ki_filp->f_mapping);
-	nfs_add_stats(inode, NFSIOS_NORMALREADBYTES, count);
-	if (!result)
+	if (!result) {
 		result = generic_file_aio_read(iocb, iov, nr_segs, pos);
+		if (result > 0)
+			nfs_add_stats(inode, NFSIOS_NORMALREADBYTES, result);
+	}
 	return result;
 }
 
#4 lore raw

PATCH 3/5 NFS: Account for NFS bytes read via the splice API

In reply to a message not in the archive

Bytes read via the splice API should be accounted for in the NFS performance statistics.

---

 fs/nfs/file.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
fs/nfs/file.c +4 -1
index 3c65a6b..64278c8 100644
@@ -284,8 +284,11 @@ nfs_file_splice_read(struct file *filp, loff_t *ppos,
 		(unsigned long) count, (unsigned long long) *ppos);
 
 	res = nfs_revalidate_mapping(inode, filp->f_mapping);
-	if (!res)
+	if (!res) {
 		res = generic_file_splice_read(filp, ppos, pipe, count, flags);
+		if (res > 0)
+			nfs_add_stats(inode, NFSIOS_NORMALREADBYTES, res);
+	}
 	return res;
 }
 
#5 lore raw

PATCH 4/5 NFS: Improve NFS iostat byte count accuracy for writes

In reply to a message not in the archive

The bytes counted by the performance counters for NFS writes should reflect write and sync errors. If the write(2) system call reports an error, the bytes should not be counted. And, if the write is short, the actual number of bytes that was written should be counted, not the number of bytes that was requested.

---

 fs/nfs/file.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
fs/nfs/file.c +12 -3
index 64278c8..1fc8175 100644
@@ -599,6 +599,7 @@ static ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov,
 {
 	struct dentry * dentry = iocb->ki_filp->f_path.dentry;
 	struct inode * inode = dentry->d_inode;
+	unsigned long written = 0;
 	ssize_t result;
 	size_t count = iov_length(iov, nr_segs);
 
@@ -625,14 +626,18 @@ static ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov,
 	if (!count)
 		goto out;
 
-	nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, count);
 	result = generic_file_aio_write(iocb, iov, nr_segs, pos);
+	if (result > 0)
+		written = result;
+
 	/* Return error values for O_DSYNC and IS_SYNC() */
 	if (result >= 0 && nfs_need_sync_write(iocb->ki_filp, inode)) {
 		int err = nfs_do_fsync(nfs_file_open_context(iocb->ki_filp), inode);
 		if (err < 0)
 			result = err;
 	}
+	if (result > 0)
+		nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written);
 out:
 	return result;
 
@@ -647,6 +652,7 @@ static ssize_t nfs_file_splice_write(struct pipe_inode_info *pipe,
 {
 	struct dentry *dentry = filp->f_path.dentry;
 	struct inode *inode = dentry->d_inode;
+	unsigned long written = 0;
 	ssize_t ret;
 
 	dprintk("NFS splice_write(%s/%s, %lu@%llu)\n",
@@ -657,14 +663,17 @@ static ssize_t nfs_file_splice_write(struct pipe_inode_info *pipe,
 	 * The combination of splice and an O_APPEND destination is disallowed.
 	 */
 
-	nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, count);
-
 	ret = generic_file_splice_write(pipe, filp, ppos, count, flags);
+	if (ret > 0)
+		written = ret;
+
 	if (ret >= 0 && nfs_need_sync_write(filp, inode)) {
 		int err = nfs_do_fsync(nfs_file_open_context(filp), inode);
 		if (err < 0)
 			ret = err;
 	}
+	if (ret > 0)
+		nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written);
 	return ret;
 }
 
#6 lore raw

PATCH 5/5 NFS: Make close(2) asynchronous when closing NFS O_DIRECT files

In reply to a message not in the archive

For NFSv2 and v3:

O_DIRECT writes are always synchronous, and aren't cached, so nothing should be flushed when closing an NFS O_DIRECT file descriptor. Thus there are no write errors to report on close(2).

In addition, there's no cached data to verify on the next open(2), so we don't need clean GETATTR results at close time to compare with.

Thus, there's no need for the nfs_revalidate_inode() call when closing an NFS O_DIRECT file. This reduces the number of synchronous on-the-wire requests for a simple open-write-close of an NFS O_DIRECT file by roughly 20%.

For NFSv4:

Call nfs4_do_close() with wait set to zero when closing an NFS O_DIRECT file. The CLOSE will go on the wire, but the application won't wait for it to complete.

---

 fs/nfs/inode.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)
fs/nfs/inode.c +1 -6
index faa0918..873717f 100644
@@ -620,11 +620,6 @@ void put_nfs_open_context(struct nfs_open_context *ctx)
 	__put_nfs_open_context(ctx, 0);
 }
 
-static void put_nfs_open_context_sync(struct nfs_open_context *ctx)
-{
-	__put_nfs_open_context(ctx, 1);
-}
-
 /*
  * Ensure that mmap has a recent RPC credential for use when writing out
  * shared pages
@@ -671,7 +666,7 @@ static void nfs_file_clear_open_context(struct file *filp)
 		spin_lock(&inode->i_lock);
 		list_move_tail(&ctx->list, &NFS_I(inode)->open_files);
 		spin_unlock(&inode->i_lock);
-		put_nfs_open_context_sync(ctx);
+		__put_nfs_open_context(ctx, filp->f_flags & O_DIRECT ? 0 : 1);
 	}
 }