From owner-cvs-all Sat Jul 7 18:35: 1 2001 Delivered-To: cvs-all@freebsd.org Received: from wantadilla.lemis.com (wantadilla.lemis.com [192.109.197.80]) by hub.freebsd.org (Postfix) with ESMTP id 22EBA37B401; Sat, 7 Jul 2001 18:34:52 -0700 (PDT) (envelope-from grog@lemis.com) Received: by wantadilla.lemis.com (Postfix, from userid 1004) id E77AC6ACBC; Sun, 8 Jul 2001 11:04:49 +0930 (CST) Date: Sun, 8 Jul 2001 11:04:49 +0930 From: Greg Lehey To: Matt Dillon Cc: Alfred Perlstein , "Justin T. Gibbs" , John Baldwin , Jake Burkholder , cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org, Matthew Jacob , Doug Rabson Subject: Re: cvs commit: src/sys/sys systm.h condvar.h src/sys/kern kern_ Message-ID: <20010708110449.E75626@wantadilla.lemis.com> References: <200107052228.f65MSeU64741@aslan.scsiguy.com> <20010705174135.A79818@sneakerz.org> <200107060214.f662ElT61708@earth.backplane.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <200107060214.f662ElT61708@earth.backplane.com>; from dillon@earth.backplane.com on Thu, Jul 05, 2001 at 07:14:47PM -0700 Organization: The FreeBSD Project Phone: +61-8-8388-8286 Fax: +61-8-8388-8725 Mobile: +61-418-838-708 WWW-Home-Page: http://www.FreeBSD.org/ X-PGP-Fingerprint: 6B 7B C3 8C 61 CD 54 AF 13 24 52 F8 6D A4 95 EF Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Thursday, 5 July 2001 at 19:14:47 -0700, Matt Dillon wrote: > >> * Justin T. Gibbs [010705 17:28] wrote: >>>> It happens with SMP, too, not just preemption. The calls are an optimization >>>> to avoid problems with releasing the lock after the wakeup. The contention >>>> can be avoided if we release the lock before calling wakeup(), but doing that >>>> leaves a window open for another CPU to alter the data that the lock protects >>>> possibly invalidating the wakeup that then gets sent. >>> >>> This window exists anyway. The locked mutex it not passed to the woken >>> up thread, so there will always be a race between the woken up thread >>> acquiring the mutex and some other thread on some other CPU acquiring it >>> first and making the wakeup invalid. >> >> >> Y'know this sorta got me thinking about something else, shouldn't the >> wakeup() calls for most exclusive locks use wakeup_one? I know >> wakeup_one() hoses priority, but for the locks in things like vnodes >> and the pager locks, shouldn't we do a wakeup_one() since it is an >> exclusive lock? >> >> -- >> -Alfred Perlstein [alfred@freebsd.org] > > I would not recommend using wakeup_one until 5.2ish. A mistake could > result in hard-to-find system lockups. I would not recommend using wakeup_one. It has the potential to hang the system. One of the tradeoffs in the sleep/wakeup paradigm is that you wait on an arbitrary address. This works fine as long as you wake up *every* process. But consider two independent subsystems which wait on the same address. wakeup_one wakes the first waiter on the list, which happens to belong to the other subsystem. It checks its environment and goes back to sleep. Bingo! The first subsystem has lost a wakeup. This isn't a theoretical situation: it happened in Vinum. The solution is to guarantee that two subsystems don't wait on the same address. I don't see that this is addressed by the current condition variable implementation, but I'm prepared to be taught otherwise. In this connection, more on the Vinum implementation: the code is in lockrange() in vinumlock.c. It implements locking for a potentially very large number of bands in a RAID-5 volume, and it sleeps on the band address. The only alternative I can see at the moment is to create a large number of mutex locks, one per band, which could be very expensive. If anybody has a better idea after looking at the code, I'd be interested. Greg -- See complete headers for address and phone numbers To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message