From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wolfram Gloger To: shanem@netcom.com, libc-hacker@sourceware.cygnus.com Subject: Re: how is malloc/free done in SMP linux Date: Wed, 11 Aug 1999 14:58:00 -0000 Message-id: <19990811215539.31577.qmail@md.dent.med.uni-muenchen.de> References: <19990811175647.A6AE957BB@ocean.lucon.org> X-SW-Source: 1999-08/msg00032.html > > as to the linux's memory management, suppose a program has > > 30 threads. each thread is allocating and deallocating memory. > > > > does linux block the other 29 threads when thread wants > > to malloc/free? Usually, no. Only when two (or more) threads want to simultaneously free() chunks from _one_ particular arena, all those threads except for one will be blocked. In practice, this is very rare. malloc() will actually _never_ block unless more memory is needed from the kernel and the sbrk() or mmap() system call blocks. > how about other threads/processes in the process > > table? Not quite sure, but generally I would expect them to be unaffected by a malloc() or free() in a particular process, unless there is (heavy) swapping activity going on. > > in a regular, single-processor system, my original C++ program > > spent 50% of its time in malloc/free. i reduced this time very > > significantly by implementing memory pools. the basic algorithm is fairly > > easy to split up across threads. hence linux SMP for more performance. > > but i am wondering if i might be walking into a "technical snare" > > with respect to linux and memory management. Linux's malloc may perform well enough so you don't need to implement pools yourself for SMP. Regards, Wolfram. -- `Surf the sea, not double-u three...' wmglo@dent.med.uni-muenchen.de