svn commit: r239355 - stable/7/sys/nfsclient

John Baldwin jhb at FreeBSD.org
Fri Aug 17 14:22:57 UTC 2012


Author: jhb
Date: Fri Aug 17 14:22:56 2012
New Revision: 239355
URL: http://svn.freebsd.org/changeset/base/239355

Log:
  MFC 230547:
  Add a timeout on positive name cache entries in the NFS client.  That is,
  we will only trust a positive name cache entry for a specified amount of
  time before falling back to a LOOKUP RPC, even if the ctime for the file
  handle matches the cached copy in the name cache entry.  The timeout is
  configured via a global 'vfs.nfs.name_timeout' sysctl and defaults to 60
  seconds.  It may be set to zero to disable positive name caching entirely.
  
  Note that this can result in increased NFS traffic under certain workloads.
  Increasing the threshold can mitigate this somewhat.  Also, to match the
  existing 'vfs.nfs.negative_name_timeout' sysctl in 7, this version uses a
  sysctl rather than a mount option as in 8.x and later.
  
  Tested by:	Mark Saad

Modified:
  stable/7/sys/nfsclient/nfs_vnops.c
  stable/7/sys/nfsclient/nfsmount.h
Directory Properties:
  stable/7/sys/   (props changed)
  stable/7/sys/cddl/contrib/opensolaris/   (props changed)
  stable/7/sys/contrib/dev/acpica/   (props changed)
  stable/7/sys/contrib/pf/   (props changed)

Modified: stable/7/sys/nfsclient/nfs_vnops.c
==============================================================================
--- stable/7/sys/nfsclient/nfs_vnops.c	Fri Aug 17 14:14:25 2012	(r239354)
+++ stable/7/sys/nfsclient/nfs_vnops.c	Fri Aug 17 14:22:56 2012	(r239355)
@@ -225,6 +225,10 @@ int nfs_directio_enable = 0;
 SYSCTL_INT(_vfs_nfs, OID_AUTO, nfs_directio_enable, CTLFLAG_RW,
 	   &nfs_directio_enable, 0, "Enable NFS directio");
 
+static u_int	nametimeo = NFS_DEFAULT_NAMETIMEO;
+SYSCTL_UINT(_vfs_nfs, OID_AUTO, name_timeout, CTLFLAG_RW,
+	   &nametimeo, 0, "Positive name cache entry timeout");
+
 static u_int	negnametimeo = NFS_DEFAULT_NEGNAMETIMEO;
 SYSCTL_UINT(_vfs_nfs, OID_AUTO, negative_name_timeout, CTLFLAG_RW,
 	   &negnametimeo, 0, "Negative name cache entry timeout");
@@ -908,7 +912,8 @@ nfs_lookup(struct vop_lookup_args *ap)
 		 * We only accept a positive hit in the cache if the
 		 * change time of the file matches our cached copy.
 		 * Otherwise, we discard the cache entry and fallback
-		 * to doing a lookup RPC.
+		 * to doing a lookup RPC.  We also only trust cache
+		 * entries for less than nametimeo seconds.
 		 *
 		 * To better handle stale file handles and attributes,
 		 * clear the attribute cache of this node if it is a
@@ -927,7 +932,8 @@ nfs_lookup(struct vop_lookup_args *ap)
 			newnp->n_attrstamp = 0;
 			mtx_unlock(&newnp->n_mtx);
 		}
-		if (VOP_GETATTR(newvp, &vattr, cnp->cn_cred, td) == 0 &&
+		if ((u_int)(ticks - ncticks) < (nametimeo * hz) &&
+		    VOP_GETATTR(newvp, &vattr, cnp->cn_cred, td) == 0 &&
 		    timespeccmp(&vattr.va_ctime, &nctime, ==)) {
 			nfsstats.lookupcache_hits++;
 			if (cnp->cn_nameiop != LOOKUP &&

Modified: stable/7/sys/nfsclient/nfsmount.h
==============================================================================
--- stable/7/sys/nfsclient/nfsmount.h	Fri Aug 17 14:14:25 2012	(r239354)
+++ stable/7/sys/nfsclient/nfsmount.h	Fri Aug 17 14:22:56 2012	(r239355)
@@ -114,6 +114,10 @@ struct	nfsmount {
 #define NFS_TPRINTF_DELAY               30
 #endif
 
+#ifndef NFS_DEFAULT_NAMETIMEO
+#define NFS_DEFAULT_NAMETIMEO		60
+#endif
+
 #ifndef NFS_DEFAULT_NEGNAMETIMEO
 #define NFS_DEFAULT_NEGNAMETIMEO	60
 #endif


More information about the svn-src-stable mailing list