From owner-svn-src-user@FreeBSD.ORG Sat Jan 3 02:00:11 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A53FB106566B; Sat, 3 Jan 2009 02:00:11 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 972898FC12; Sat, 3 Jan 2009 02:00:11 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n0320Bc2013246; Sat, 3 Jan 2009 02:00:11 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n0320Arr013245; Sat, 3 Jan 2009 02:00:10 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200901030200.n0320Arr013245@svn.freebsd.org> From: Kip Macy Date: Sat, 3 Jan 2009 02:00:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r186710 - user/kmacy/HEAD_fast_net/sys/kern X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Jan 2009 02:00:12 -0000 Author: kmacy Date: Sat Jan 3 02:00:10 2009 New Revision: 186710 URL: http://svn.freebsd.org/changeset/base/186710 Log: convert name cache lock to rwlock for lookups Modified: user/kmacy/HEAD_fast_net/sys/kern/vfs_cache.c Modified: user/kmacy/HEAD_fast_net/sys/kern/vfs_cache.c ============================================================================== --- user/kmacy/HEAD_fast_net/sys/kern/vfs_cache.c Sat Jan 3 01:11:26 2009 (r186709) +++ user/kmacy/HEAD_fast_net/sys/kern/vfs_cache.c Sat Jan 3 02:00:10 2009 (r186710) @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -109,11 +110,17 @@ SYSCTL_ULONG(_debug, OID_AUTO, numcachep #endif struct nchstats nchstats; /* cache effectiveness statistics */ -static struct mtx cache_lock; -MTX_SYSINIT(vfscache, &cache_lock, "Name Cache", MTX_DEF); +static struct rwlock cache_lock; +RW_SYSINIT(vfscache, &cache_lock, "Name Cache"); -#define CACHE_LOCK() mtx_lock(&cache_lock) -#define CACHE_UNLOCK() mtx_unlock(&cache_lock) +#define CACHE_RLOCK() rw_rlock(&cache_lock) +#define CACHE_RUNLOCK() rw_runlock(&cache_lock) +#define CACHE_WLOCK() rw_wlock(&cache_lock) +#define CACHE_WUNLOCK() rw_wunlock(&cache_lock) +#define CACHE_TRY_UPGRADE() rw_try_upgrade(&cache_lock) + +#define CACHE_LOCK() CACHE_WLOCK() +#define CACHE_UNLOCK() CACHE_WUNLOCK() /* * UMA zones for the VFS cache. @@ -275,7 +282,7 @@ cache_zap(ncp) { struct vnode *vp; - mtx_assert(&cache_lock, MA_OWNED); + rw_assert(&cache_lock, RA_LOCKED); CTR2(KTR_VFS, "cache_zap(%p) vp %p", ncp, ncp->nc_vp); vp = NULL; LIST_REMOVE(ncp, nc_hash); @@ -329,7 +336,7 @@ cache_lookup(dvp, vpp, cnp) return (0); } retry: - CACHE_LOCK(); + CACHE_RLOCK(); numcalls++; if (cnp->cn_nameptr[0] == '.') { @@ -344,7 +351,7 @@ retry: dotdothits++; if (dvp->v_dd == NULL || (cnp->cn_flags & MAKEENTRY) == 0) { - CACHE_UNLOCK(); + CACHE_RUNLOCK(); return (0); } *vpp = dvp->v_dd; @@ -371,12 +378,16 @@ retry: nummiss++; } nchstats.ncs_miss++; - CACHE_UNLOCK(); + CACHE_RUNLOCK(); return (0); } /* We don't want to have an entry, so dump it */ if ((cnp->cn_flags & MAKEENTRY) == 0) { + if (CACHE_TRY_UPGRADE() == 0) { + CACHE_RUNLOCK(); + CACHE_WLOCK(); + } numposzaps++; nchstats.ncs_badhits++; cache_zap(ncp); @@ -394,6 +405,10 @@ retry: goto success; } + if (CACHE_TRY_UPGRADE() == 0) { + CACHE_RUNLOCK(); + CACHE_WLOCK(); + } /* We found a negative match, and want to create it, so purge */ if (cnp->cn_nameiop == CREATE) { numnegzaps++; @@ -425,7 +440,7 @@ success: */ if (dvp == *vpp) { /* lookup on "." */ VREF(*vpp); - CACHE_UNLOCK(); + CACHE_RUNLOCK(); /* * When we lookup "." we still can be asked to lock it * differently... @@ -451,7 +466,7 @@ success: VOP_UNLOCK(dvp, 0); } VI_LOCK(*vpp); - CACHE_UNLOCK(); + CACHE_RUNLOCK(); error = vget(*vpp, cnp->cn_lkflags | LK_INTERLOCK, cnp->cn_thread); if (cnp->cn_flags & ISDOTDOT) vn_lock(dvp, ltype | LK_RETRY);