From owner-freebsd-smp Tue Jan 15 11:58:50 2002 Delivered-To: freebsd-smp@freebsd.org Received: from mail5.speakeasy.net (mail5.speakeasy.net [216.254.0.205]) by hub.freebsd.org (Postfix) with ESMTP id E03A937B41D for ; Tue, 15 Jan 2002 11:58:44 -0800 (PST) Received: (qmail 14414 invoked from network); 15 Jan 2002 19:58:43 -0000 Received: from unknown (HELO laptop.baldwin.cx) ([64.81.54.73]) (envelope-sender ) by mail5.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 15 Jan 2002 19:58:43 -0000 Message-ID: X-Mailer: XFMail 1.4.0 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: <200201151940.g0FJeNI63717@apollo.backplane.com> Date: Tue, 15 Jan 2002 11:58:04 -0800 (PST) From: John Baldwin To: Matthew Dillon Subject: Re: making malloc(9) smp safe? Cc: smp@FreeBSD.ORG, Alfred Perlstein Sender: owner-freebsd-smp@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org 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 <>< 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