From owner-svn-src-user@FreeBSD.ORG Sat Jan 3 02:31:57 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 7D183106564A; Sat, 3 Jan 2009 02:31:57 +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 6D7B48FC12; Sat, 3 Jan 2009 02:31:57 +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 n032VvRk013882; Sat, 3 Jan 2009 02:31:57 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n032Vvfb013881; Sat, 3 Jan 2009 02:31:57 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200901030231.n032Vvfb013881@svn.freebsd.org> From: Kip Macy Date: Sat, 3 Jan 2009 02:31:57 +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: r186711 - 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:31:57 -0000 Author: kmacy Date: Sat Jan 3 02:31:57 2009 New Revision: 186711 URL: http://svn.freebsd.org/changeset/base/186711 Log: convert vfs hash lock to an rwlock Modified: user/kmacy/HEAD_fast_net/sys/kern/vfs_hash.c Modified: user/kmacy/HEAD_fast_net/sys/kern/vfs_hash.c ============================================================================== --- user/kmacy/HEAD_fast_net/sys/kern/vfs_hash.c Sat Jan 3 02:00:10 2009 (r186710) +++ user/kmacy/HEAD_fast_net/sys/kern/vfs_hash.c Sat Jan 3 02:31:57 2009 (r186711) @@ -31,8 +31,10 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include +#include #include static MALLOC_DEFINE(M_VFS_HASH, "vfs_hash", "VFS hash table"); @@ -40,14 +42,20 @@ static MALLOC_DEFINE(M_VFS_HASH, "vfs_ha static LIST_HEAD(vfs_hash_head, vnode) *vfs_hash_tbl; static LIST_HEAD(,vnode) vfs_hash_side; static u_long vfs_hash_mask; -static struct mtx vfs_hash_mtx; +static struct rwlock vfs_hash_lock; + +#define HASH_WLOCK() rw_wlock(&vfs_hash_lock) +#define HASH_WUNLOCK() rw_wunlock(&vfs_hash_lock) +#define HASH_RLOCK() rw_rlock(&vfs_hash_lock) +#define HASH_RUNLOCK() rw_runlock(&vfs_hash_lock) + static void vfs_hashinit(void *dummy __unused) { vfs_hash_tbl = hashinit(desiredvnodes, M_VFS_HASH, &vfs_hash_mask); - mtx_init(&vfs_hash_mtx, "vfs hash", NULL, MTX_DEF); + rw_init(&vfs_hash_lock, "vfs hash"); LIST_INIT(&vfs_hash_side); } @@ -68,7 +76,7 @@ vfs_hash_get(const struct mount *mp, u_i int error; while (1) { - mtx_lock(&vfs_hash_mtx); + HASH_RLOCK(); LIST_FOREACH(vp, vfs_hash_index(mp, hash), v_hashlist) { if (vp->v_hash != hash) continue; @@ -77,7 +85,7 @@ vfs_hash_get(const struct mount *mp, u_i if (fn != NULL && fn(vp, arg)) continue; VI_LOCK(vp); - mtx_unlock(&vfs_hash_mtx); + HASH_RUNLOCK(); error = vget(vp, flags | LK_INTERLOCK, td); if (error == ENOENT && (flags & LK_NOWAIT) == 0) break; @@ -87,7 +95,7 @@ vfs_hash_get(const struct mount *mp, u_i return (0); } if (vp == NULL) { - mtx_unlock(&vfs_hash_mtx); + HASH_RUNLOCK(); *vpp = NULL; return (0); } @@ -98,9 +106,9 @@ void vfs_hash_remove(struct vnode *vp) { - mtx_lock(&vfs_hash_mtx); + HASH_WLOCK(); LIST_REMOVE(vp, v_hashlist); - mtx_unlock(&vfs_hash_mtx); + HASH_WUNLOCK(); } int @@ -111,7 +119,7 @@ vfs_hash_insert(struct vnode *vp, u_int *vpp = NULL; while (1) { - mtx_lock(&vfs_hash_mtx); + HASH_WLOCK(); LIST_FOREACH(vp2, vfs_hash_index(vp->v_mount, hash), v_hashlist) { if (vp2->v_hash != hash) @@ -121,13 +129,13 @@ vfs_hash_insert(struct vnode *vp, u_int if (fn != NULL && fn(vp2, arg)) continue; VI_LOCK(vp2); - mtx_unlock(&vfs_hash_mtx); + HASH_WUNLOCK(); error = vget(vp2, flags | LK_INTERLOCK, td); if (error == ENOENT && (flags & LK_NOWAIT) == 0) break; - mtx_lock(&vfs_hash_mtx); + HASH_WLOCK(); LIST_INSERT_HEAD(&vfs_hash_side, vp, v_hashlist); - mtx_unlock(&vfs_hash_mtx); + HASH_WUNLOCK(); vput(vp); if (!error) *vpp = vp2; @@ -139,7 +147,7 @@ vfs_hash_insert(struct vnode *vp, u_int } vp->v_hash = hash; LIST_INSERT_HEAD(vfs_hash_index(vp->v_mount, hash), vp, v_hashlist); - mtx_unlock(&vfs_hash_mtx); + HASH_WUNLOCK(); return (0); } @@ -147,9 +155,9 @@ void vfs_hash_rehash(struct vnode *vp, u_int hash) { - mtx_lock(&vfs_hash_mtx); + HASH_WLOCK(); LIST_REMOVE(vp, v_hashlist); LIST_INSERT_HEAD(vfs_hash_index(vp->v_mount, hash), vp, v_hashlist); vp->v_hash = hash; - mtx_unlock(&vfs_hash_mtx); + HASH_WUNLOCK(); }