Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 Jan 2002 11:58:04 -0800 (PST)
From:      John Baldwin <jhb@FreeBSD.org>
To:        Matthew Dillon <dillon@apollo.backplane.com>
Cc:        smp@FreeBSD.ORG, Alfred Perlstein <bright@mu.org>
Subject:   Re: making malloc(9) smp safe?
Message-ID:  <XFMail.020115115804.jhb@FreeBSD.org>
In-Reply-To: <200201151940.g0FJeNI63717@apollo.backplane.com>

next in thread | previous in thread | raw e-mail | index | archive | help

On 15-Jan-02 Matthew Dillon wrote:
>:Malloc has its own mutex, however when it needs to do page allocations
>:via kmem_malloc() it drops the mutex and calls it.
>:
>:kmem_malloc() needs giant.
>:
>:what do I do?
>:
>:Do I grab giant before calling malloc(9)?
>:Do I make malloc(9) aquire or recurse on giant automatically?
>:  (basically grab giant around kmem_malloc() call in malloc(9))
>:
>:?
>:
>:-- 
>:-Alfred Perlstein [alfred@freebsd.org]
> 
>     If you are trying to make malloc() SMP safe, then Giant cannot be
>     required to be held by the caller of malloc().

There is only thing to watch out for:  if anyone wants to hold a lockmgr or sx
lock while calling malloc, they need to acquire Giant before they acquire the
lockmgr or sx lock to avoid lock order problems.  Witness will whine about the
reversals if this happens, but I think we would be safe for the time being. 
People should really avoid holding locks while calling malloc() though.

-- 

John Baldwin <jhb@FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve!"  -  http://www.FreeBSD.org/

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?XFMail.020115115804.jhb>