From owner-freebsd-smp Sun Jan 13 12:43:28 2002 Delivered-To: freebsd-smp@freebsd.org Received: from hawk.prod.itd.earthlink.net (hawk.mail.pas.earthlink.net [207.217.120.22]) by hub.freebsd.org (Postfix) with ESMTP id 1110937B417; Sun, 13 Jan 2002 12:43:20 -0800 (PST) Received: from pool0417.cvx40-bradley.dialup.earthlink.net ([216.244.43.162] helo=mindspring.com) by hawk.prod.itd.earthlink.net with esmtp (Exim 3.33 #1) id 16PrT7-0003aC-00; Sun, 13 Jan 2002 12:43:05 -0800 Message-ID: <3C41F153.DCA0A4F3@mindspring.com> Date: Sun, 13 Jan 2002 12:42:59 -0800 From: Terry Lambert X-Mailer: Mozilla 4.7 [en]C-CCK-MCD {Sony} (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Alfred Perlstein Cc: smp@freebsd.org, jhb@freebsd.org, dillon@freebsd.org Subject: Re: making malloc(9) smp safe? References: <20020113050836.Q7984@elvis.mu.org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 Alfred Perlstein 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)) > > ? The way Dynix does this (see UNIX Internals: The New Frontiers, Uresh Vahalia, Chapter 12 Kernel Memory Allocation, 12.9 A Hierarchical Allocator for Multiprocessors) is to seperate the memory into a global pool, and per CPU pools, with a seperate Coelesce-to-Page layer. Here are some nice papers: http://www.research.ibm.com/K42/full-hotos-01.ps http://citeseer.nj.nec.com/mckenney96selecting.html http://citeseer.nj.nec.com/54799.html http://citeseer.nj.nec.com/bonwick94slab.html http://citeseer.nj.nec.com/wilson95dynamic.html http://citeseer.nj.nec.com/gamsa99tornado.html Yyou can get a copy of the original paper: "Efficient Kernel Memory Allocation on Shared-Memory Multiprocessors" P.E. McKenney, J. Slingwine Processdings of Usenix, Winter, 1993 (p295-305). Paul's current email address is: pmckenne@us.ibm.com (he works in the Linux Technology Center at IBM Watson Research). You can get the mother of all papers on SMP kernel memory allocation from his home page at: http://www.rdrop.com/users/paulmck He has quite a nice set of papers on SMP, locking, and memory allocation. Here is another paper he's been involved with recently; it's also quite applicable to the problem at hand: http://lwn.net/2001/features/OLS/pdf/pdf/read-copy.pdf -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-smp" in the body of the message