From owner-svn-src-all@FreeBSD.ORG Tue Dec 30 22:46:31 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 36307B13; Tue, 30 Dec 2014 22:46:31 +0000 (UTC) Received: from mx1.sbone.de (bird.sbone.de [46.4.1.90]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client CN "mx1.sbone.de", Issuer "SBone.DE" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 618811572; Tue, 30 Dec 2014 22:46:30 +0000 (UTC) Received: from mail.sbone.de (mail.sbone.de [IPv6:fde9:577b:c1a9:31::2013:587]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.sbone.de (Postfix) with ESMTPS id AA6F625D388C; Tue, 30 Dec 2014 22:46:20 +0000 (UTC) Received: from content-filter.sbone.de (content-filter.sbone.de [IPv6:fde9:577b:c1a9:31::2013:2742]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.sbone.de (Postfix) with ESMTPS id B08B5C7709C; Tue, 30 Dec 2014 22:46:19 +0000 (UTC) X-Virus-Scanned: amavisd-new at sbone.de Received: from mail.sbone.de ([IPv6:fde9:577b:c1a9:31::2013:587]) by content-filter.sbone.de (content-filter.sbone.de [fde9:577b:c1a9:31::2013:2742]) (amavisd-new, port 10024) with ESMTP id 2y25BAHTOcgu; Tue, 30 Dec 2014 22:46:17 +0000 (UTC) Received: from [IPv6:fde9:577b:c1a9:4410:dbd:a00d:7703:7346] (unknown [IPv6:fde9:577b:c1a9:4410:dbd:a00d:7703:7346]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.sbone.de (Postfix) with ESMTPSA id F17AEC7706F; Tue, 30 Dec 2014 22:46:16 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\)) Subject: Re: svn commit: r276424 - head/sys/kern From: "Bjoern A. Zeeb" In-Reply-To: <201412302140.sBULek5f076019@svn.freebsd.org> Date: Tue, 30 Dec 2014 22:45:43 +0000 Content-Transfer-Encoding: quoted-printable Message-Id: References: <201412302140.sBULek5f076019@svn.freebsd.org> To: Mateusz Guzik X-Mailer: Apple Mail (2.1993) Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org 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 22:46:31 -0000 > On 30 Dec 2014, at 21:40 , Mateusz Guzik wrote: >=20 > Author: mjg > Date: Tue Dec 30 21:40:45 2014 > New Revision: 276424 > URL: https://svnweb.freebsd.org/changeset/base/276424 >=20 > Log: > Convert vfs hash lock from a mutex to an rwlock. This is very obvious from the change. What is not and should be described as well is some of this: - Why? - What are the benefits? - What are the locking implications? - Does it make a performance difference? If yes, was it measured? - =E2=80=A6 (you got the idea) >=20 > Modified: > head/sys/kern/vfs_hash.c >=20 > Modified: head/sys/kern/vfs_hash.c > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > --- 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 >=20 > 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; >=20 > static void > vfs_hashinit(void *dummy __unused) > { >=20 > vfs_hash_tbl =3D 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); > } >=20 > @@ -75,7 +76,7 @@ vfs_hash_get(const struct mount *mp, u_i > int error; >=20 > 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 !=3D hash) > continue; > @@ -84,7 +85,7 @@ vfs_hash_get(const struct mount *mp, u_i > if (fn !=3D NULL && fn(vp, arg)) > continue; > VI_LOCK(vp); > - mtx_unlock(&vfs_hash_mtx); > + rw_runlock(&vfs_hash_lock); > error =3D vget(vp, flags | LK_INTERLOCK, td); > if (error =3D=3D ENOENT && (flags & LK_NOWAIT) = =3D=3D 0) > break; > @@ -94,7 +95,7 @@ vfs_hash_get(const struct mount *mp, u_i > return (0); > } > if (vp =3D=3D NULL) { > - mtx_unlock(&vfs_hash_mtx); > + rw_runlock(&vfs_hash_lock); > *vpp =3D NULL; > return (0); > } > @@ -105,9 +106,9 @@ void > vfs_hash_remove(struct vnode *vp) > { >=20 > - 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); > } >=20 > int > @@ -118,7 +119,7 @@ vfs_hash_insert(struct vnode *vp, u_int=20 >=20 > *vpp =3D 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 !=3D hash) > @@ -128,13 +129,13 @@ vfs_hash_insert(struct vnode *vp, u_int=20 > if (fn !=3D NULL && fn(vp2, arg)) > continue; > VI_LOCK(vp2); > - mtx_unlock(&vfs_hash_mtx); > + rw_wunlock(&vfs_hash_lock); > error =3D vget(vp2, flags | LK_INTERLOCK, td); > if (error =3D=3D ENOENT && (flags & LK_NOWAIT) = =3D=3D 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 =3D vp2; > @@ -146,7 +147,7 @@ vfs_hash_insert(struct vnode *vp, u_int=20 > } > vp->v_hash =3D 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); > } >=20 > @@ -154,9 +155,9 @@ void > vfs_hash_rehash(struct vnode *vp, u_int hash) > { >=20 > - 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 =3D hash; > - mtx_unlock(&vfs_hash_mtx); > + rw_wunlock(&vfs_hash_lock); > } >=20 =E2=80=94=20 Bjoern A. Zeeb Charles Haddon Spurgeon: "Friendship is one of the sweetest joys of life. Many might have failed beneath the bitterness of their trial had they not found a friend."