Date: Tue, 31 Oct 2000 10:21:10 -0800 From: Alfred Perlstein <bright@wintelcom.net> To: Cedric Berger <cedric@wireless-networks.com> Cc: Robert Watson <rwatson@FreeBSD.ORG>, freebsd-smp@FreeBSD.ORG Subject: Re: Reference count invariants in a fine-grained threaded environment Message-ID: <20001031102110.V22110@fw.wintelcom.net> In-Reply-To: <39FF0AC0.86A3A950@wireless-networks.com>; from cedric@wireless-networks.com on Tue, Oct 31, 2000 at 10:09:04AM -0800 References: <Pine.NEB.3.96L.1001031123647.58688x-100000@fledge.watson.org> <39FF0AC0.86A3A950@wireless-networks.com>
next in thread | previous in thread | raw e-mail | index | archive | help
* Cedric Berger <cedric@wireless-networks.com> [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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20001031102110.V22110>