From owner-freebsd-hackers@FreeBSD.ORG Mon Aug 6 11:39:57 2007 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 324B416A47F for ; Mon, 6 Aug 2007 11:39:57 +0000 (UTC) (envelope-from pjd@garage.freebsd.pl) Received: from mail.garage.freebsd.pl (arm132.internetdsl.tpnet.pl [83.17.198.132]) by mx1.freebsd.org (Postfix) with ESMTP id C8A5913C481 for ; Mon, 6 Aug 2007 11:39:56 +0000 (UTC) (envelope-from pjd@garage.freebsd.pl) Received: by mail.garage.freebsd.pl (Postfix, from userid 65534) id 1575045B26; Mon, 6 Aug 2007 13:11:05 +0200 (CEST) Received: from localhost (pjd.wheel.pl [10.0.1.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.garage.freebsd.pl (Postfix) with ESMTP id E76E145684; Mon, 6 Aug 2007 13:10:59 +0200 (CEST) Date: Mon, 6 Aug 2007 13:10:18 +0200 From: Pawel Jakub Dawidek To: Ulf Lilleengen Message-ID: <20070806111017.GA4170@garage.freebsd.pl> References: <20070803192910.GA23699@carrot.studby.ntnu.no> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="YZ5djTAD1cGYuMQK" Content-Disposition: inline In-Reply-To: <20070803192910.GA23699@carrot.studby.ntnu.no> User-Agent: Mutt/1.4.2.3i X-PGP-Key-URL: http://people.freebsd.org/~pjd/pjd.asc X-OS: FreeBSD 7.0-CURRENT i386 X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on mail.garage.freebsd.pl X-Spam-Level: X-Spam-Status: No, score=-5.9 required=3.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.0.4 Cc: freebsd-hackers@freebsd.org Subject: Re: VFS locking questions X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Aug 2007 11:39:57 -0000 --YZ5djTAD1cGYuMQK Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Aug 03, 2007 at 09:29:33PM +0200, Ulf Lilleengen wrote: > Hi, >=20 > I have a couple of questions regarding VFS, since I'm trying to SMPify the > fdescfs code in an effort to get some experience with VFS and freebsd loc= king... >=20 > What is really LK_INTERLOCK? When should it be used? When should one acqu= ire it > (with VI_LOCK i assume), and what are the "semantics"? =20 Vnode internal lock (v_interlock, VI_LOCK()) is used to protect various field in the vnode structure (those marked with 'i' letter in vnode.h). You pass the LK_INTERLOCK flag to functions like lockmgr(), vn_lock(), VOP_UNLOCK() when you already hold vnode's interlock. This way if one of those functions needs vnode's interlock internally, it knows if you already hold it or not (thus the function needs to acquire it on its own). We could probably just use mtx_owned() inside those functions. > Let's say I have a function that should return a locked vnode. I lock the > hash-table with a regular mutex. Then, when I traverse the list, I check = if the > entry is what I look for. If it is, I call VI_LOCK() on the vnode, use vg= et to > increment refcount, and then use vn_lock(vp, LK_EXCLUSIVE...) to lock the= vnode > before the function returns. Is this correct behaviour?=20 Instead of doing what you suggest: VI_LOCK(vp); vget(vp, LK_INTERLOCK, td); vn_lock(vp, LK_EXCLUSIVE, td); You can simply call: vget(vp, LK_EXCLUSIVE, td); This is why: - You haven't passed LK_INTERLOCK, so vget() will lock it by itself if needed (it does need it). - You passed LK_EXCLUSIVE, so vget() will return locked vnode. > The LK_INTERLOCK bothers me a bit, because I'm not 100% sure on how it wo= rks. It probably mostly an optimization and probably protection before some races, so you can call various functions with vnode's interlock already held. --=20 Pawel Jakub Dawidek http://www.wheel.pl pjd@FreeBSD.org http://www.FreeBSD.org FreeBSD committer Am I Evil? Yes, I Am! --YZ5djTAD1cGYuMQK Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4 (FreeBSD) iD8DBQFGtwGZForvXbEpPzQRAow8AKDpRDNYR4VyJy7CuvoAwiURGskzpwCg8xMm +dovr/Zof/jkPEyvsU7z5J4= =PMZ1 -----END PGP SIGNATURE----- --YZ5djTAD1cGYuMQK--