From owner-freebsd-current Fri May 2 04:26:06 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id EAA25805 for current-outgoing; Fri, 2 May 1997 04:26:06 -0700 (PDT) Received: from hda.hda.com (hda-bicnet.bicnet.net [207.198.1.121]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id EAA25792 for ; Fri, 2 May 1997 04:26:03 -0700 (PDT) Received: (from dufault@localhost) by hda.hda.com (8.8.5/8.8.5) id HAA27754; Fri, 2 May 1997 07:24:55 -0400 (EDT) From: Peter Dufault Message-Id: <199705021124.HAA27754@hda.hda.com> Subject: Re: vnode->v_usage In-Reply-To: <5321.862569821@critter> from Poul-Henning Kamp at "May 2, 97 12:43:41 pm" To: phk@dk.tfs.com (Poul-Henning Kamp) Date: Fri, 2 May 1997 07:24:54 -0400 (EDT) Cc: current@freebsd.org X-Mailer: ELM [version 2.4ME+ PL25 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-current@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > Ok, now I'm in doubt here... Which of these two places are the > correct place to release the interlock, I've marked the candidates > with XXX, I pressume the later, right ? > > void > vtouch(vp) > struct vnode *vp; > { > simple_lock(&vp->v_interlock); > if (vp->v_usecount) { > simple_unlock(&vp->v_interlock); > return; > } > simple_unlock(&vp->v_interlock); /* XXX */ > simple_lock(&vnode_free_list_slock); > TAILQ_REMOVE(&vnode_free_list, vp, v_freelist); > TAILQ_INSERT_TAIL(&vnode_free_list, vp, v_freelist); > simple_unlock(&vnode_free_list_slock); > simple_unlock(&vp->v_interlock); /* XXX */ > } > The first unlock won't work since a second thread can come in and decide to do the same move. Obviously you have a lock ordering issue with the nested lock and you have to define the ordering. Moving items between two lists should be atomic - it is common and lends itself to clean implementation. Aside: how about making the queues truly opaque while you're doing this? Then you have a single place to enable locking hierarchy violation detection, *CAS types of implementations, etc. Peter -- Peter Dufault (dufault@hda.com) Realtime Machine Control and Simulation HD Associates, Inc. Voice: 508 433 6936