From owner-freebsd-smp Tue Oct 31 10:21:14 2000 Delivered-To: freebsd-smp@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by hub.freebsd.org (Postfix) with ESMTP id EB06937B4CF; Tue, 31 Oct 2000 10:21:11 -0800 (PST) Received: (from bright@localhost) by fw.wintelcom.net (8.10.0/8.10.0) id e9VILB001432; Tue, 31 Oct 2000 10:21:11 -0800 (PST) Date: Tue, 31 Oct 2000 10:21:10 -0800 From: Alfred Perlstein To: Cedric Berger Cc: Robert Watson , freebsd-smp@FreeBSD.ORG Subject: Re: Reference count invariants in a fine-grained threaded environment Message-ID: <20001031102110.V22110@fw.wintelcom.net> References: <39FF0AC0.86A3A950@wireless-networks.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.4i In-Reply-To: <39FF0AC0.86A3A950@wireless-networks.com>; from cedric@wireless-networks.com on Tue, Oct 31, 2000 at 10:09:04AM -0800 Sender: owner-freebsd-smp@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org * Cedric Berger [001031 10:11] wrote: > > > Robert Watson wrote: > > > [...] > > > > Rules for interactions between mutexes and reference-counted kernel > > objects: > > > > Assumptions: > > > > - Objects with reference counts have a mutex that can protect their > > reference count, and possibly other variables (or other instances). For > > example, struct cred might have a mutex per instance, but all struct > > prison's might use the same mutex. > > > > Is there not a cheaper way to manage reference count then using mutexes? > I would guess that all architectures must have hardware support (i.e. special > assembly instruction) to atomically increment/decrement+read a 32-bit value > in a multiprocessor environment Yes, but FreeBSD is has too many knights that say NIH! This is where atomic refcounts would simplify the code however for some reason everyone I've talked to prefers to have this sort of code: void crhold(struct ucred* ucp) { mtx_lock(ucp->uc_mtx); ucp->ref++; mtx_unlock(ucp->uc_mtx); } rather than a simple and cheaper: void crhold(struct ucred* ucp) { atomic_ref_inc(&ucp->ref); } *shrug* -- -Alfred Perlstein - [bright@wintelcom.net|alfred@freebsd.org] "I have the heart of a child; I keep it in a jar on my desk." To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-smp" in the body of the message