From owner-svn-src-all@FreeBSD.ORG Tue Dec 30 21:40:46 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4856B61E; Tue, 30 Dec 2014 21:40:46 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 33C0D2B34; Tue, 30 Dec 2014 21:40:46 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sBULekn3076020; Tue, 30 Dec 2014 21:40:46 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sBULek5f076019; Tue, 30 Dec 2014 21:40:46 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201412302140.sBULek5f076019@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Tue, 30 Dec 2014 21:40:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r276424 - head/sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Dec 2014 21:40:46 -0000 Author: mjg Date: Tue Dec 30 21:40:45 2014 New Revision: 276424 URL: https://svnweb.freebsd.org/changeset/base/276424 Log: Convert vfs hash lock from a mutex to an rwlock. Modified: head/sys/kern/vfs_hash.c Modified: head/sys/kern/vfs_hash.c ============================================================================== --- head/sys/kern/vfs_hash.c Tue Dec 30 20:46:01 2014 (r276423) +++ head/sys/kern/vfs_hash.c Tue Dec 30 21:40:45 2014 (r276424) @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include static MALLOC_DEFINE(M_VFS_HASH, "vfs_hash", "VFS hash table"); @@ -40,14 +41,14 @@ 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; 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); } @@ -75,7 +76,7 @@ vfs_hash_get(const struct mount *mp, u_i int error; while (1) { - mtx_lock(&vfs_hash_mtx); + rw_rlock(&vfs_hash_lock); LIST_FOREACH(vp, vfs_hash_bucket(mp, hash), v_hashlist) { if (vp->v_hash != hash) continue; @@ -84,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); + rw_runlock(&vfs_hash_lock); error = vget(vp, flags | LK_INTERLOCK, td); if (error == ENOENT && (flags & LK_NOWAIT) == 0) break; @@ -94,7 +95,7 @@ vfs_hash_get(const struct mount *mp, u_i return (0); } if (vp == NULL) { - mtx_unlock(&vfs_hash_mtx); + rw_runlock(&vfs_hash_lock); *vpp = NULL; return (0); } @@ -105,9 +106,9 @@ void vfs_hash_remove(struct vnode *vp) { - mtx_lock(&vfs_hash_mtx); + rw_wlock(&vfs_hash_lock); LIST_REMOVE(vp, v_hashlist); - mtx_unlock(&vfs_hash_mtx); + rw_wunlock(&vfs_hash_lock); } int @@ -118,7 +119,7 @@ vfs_hash_insert(struct vnode *vp, u_int *vpp = NULL; while (1) { - mtx_lock(&vfs_hash_mtx); + rw_wlock(&vfs_hash_lock); LIST_FOREACH(vp2, vfs_hash_bucket(vp->v_mount, hash), v_hashlist) { if (vp2->v_hash != hash) @@ -128,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); + rw_wunlock(&vfs_hash_lock); error = vget(vp2, flags | LK_INTERLOCK, td); if (error == ENOENT && (flags & LK_NOWAIT) == 0) break; - mtx_lock(&vfs_hash_mtx); + rw_wlock(&vfs_hash_lock); LIST_INSERT_HEAD(&vfs_hash_side, vp, v_hashlist); - mtx_unlock(&vfs_hash_mtx); + rw_wunlock(&vfs_hash_lock); vput(vp); if (!error) *vpp = vp2; @@ -146,7 +147,7 @@ vfs_hash_insert(struct vnode *vp, u_int } vp->v_hash = hash; LIST_INSERT_HEAD(vfs_hash_bucket(vp->v_mount, hash), vp, v_hashlist); - mtx_unlock(&vfs_hash_mtx); + rw_wunlock(&vfs_hash_lock); return (0); } @@ -154,9 +155,9 @@ void vfs_hash_rehash(struct vnode *vp, u_int hash) { - mtx_lock(&vfs_hash_mtx); + rw_wlock(&vfs_hash_lock); LIST_REMOVE(vp, v_hashlist); LIST_INSERT_HEAD(vfs_hash_bucket(vp->v_mount, hash), vp, v_hashlist); vp->v_hash = hash; - mtx_unlock(&vfs_hash_mtx); + rw_wunlock(&vfs_hash_lock); }