From owner-freebsd-arch@FreeBSD.ORG Mon Oct 19 20:34:39 2009 Return-Path: Delivered-To: arch@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 25AE1106566C for ; Mon, 19 Oct 2009 20:34:39 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id EE2048FC19 for ; Mon, 19 Oct 2009 20:34:38 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id A12AE46B2C for ; Mon, 19 Oct 2009 16:34:38 -0400 (EDT) Received: from jhbbsd.hudson-trading.com (unknown [209.249.190.8]) by bigwig.baldwin.cx (Postfix) with ESMTPA id A39CB8A020 for ; Mon, 19 Oct 2009 16:34:37 -0400 (EDT) From: John Baldwin To: arch@FreeBSD.org Date: Mon, 19 Oct 2009 16:34:29 -0400 User-Agent: KMail/1.9.7 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200910191634.30040.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Mon, 19 Oct 2009 16:34:37 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 required=4.2 tests=AWL,BAYES_00,RDNS_NONE autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: Subject: Put a timeout on -ve name cache entries in NFS X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Oct 2009 20:34:39 -0000 This patch allows one to put an upper time limit on how long the NFS client should keep negative cache entries around for a given directory. This is basically a safety belt as there are certain races with -ve entries that are not easily fixed (e.g. dealing with the low resolution of the directory modification timestamps). However, timing out the entries would put a limit on how stale the client's cache entries could be. My main question is do folks think this value should be tunable as a global sysctl or a per-mount option. A sysctl is far easier to implement (and the acccess cache timeout is a sysctl). However, the other namecache-related settings are all mount options, so a mount option might be more consistent. Current rough patch is below: --- //depot/projects/smpng/sys/nfsclient/nfs_vnops.c 2009/10/19 14:27:26 +++ //depot/user/jhb/lock/nfsclient/nfs_vnops.c 2009/10/19 19:53:51 @@ -981,9 +981,11 @@ * We only accept a negative hit in the cache if the * modification time of the parent directory matches * our cached copy. Otherwise, we discard all of the - * negative cache entries for this directory. + * negative cache entries for this directory. We also + * only trust -ve cache entries for up to 5 seconds. */ - if (VOP_GETATTR(dvp, &vattr, cnp->cn_cred) == 0 && + if ((u_int)(ticks - np->n_dmtime_ticks) <= 5 && + VOP_GETATTR(dvp, &vattr, cnp->cn_cred) == 0 && vattr.va_mtime.tv_sec == np->n_dmtime) { nfsstats.lookupcache_hits++; return (ENOENT); @@ -1157,8 +1159,10 @@ */ mtx_lock(&np->n_mtx); if (np->n_dmtime <= dmtime) { - if (np->n_dmtime == 0) + if (np->n_dmtime == 0) { np->n_dmtime = dmtime; + np->n_dmtime_ticks = ticks; + } mtx_unlock(&np->n_mtx); cache_enter(dvp, NULL, cnp); } else --- //depot/projects/smpng/sys/nfsclient/nfsnode.h 2009/05/29 14:35:29 +++ //depot/user/jhb/lock/nfsclient/nfsnode.h 2009/10/19 19:53:51 @@ -119,6 +119,7 @@ struct vnode *n_vnode; /* associated vnode */ struct vnode *n_dvp; /* parent vnode */ int n_error; /* Save write error value */ + int n_dmtime_ticks; /* When n_dmtime was last set */ union { struct timespec nf_atim; /* Special file times */ nfsuint64 nd_cookieverf; /* Cookie verifier (dir only) */ -- John Baldwin