On Tue, Aug 10, 1999 at 08:13:52AM -0700, Shane Miller wrote:
> Sir;
>
> i am beginning development of a CAD like program. it will be
> threaded and multi-processor capable (well thanks to SMP O/S
> like linux).
>
> 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 <X> wants
> to malloc/free? how about other threads/processes in the process
> table?
Linux doesn't. Or, at least the kernel is not involved with every
malloc()/free() you do, because the C library takes care of allocation and
deallocation of these smaller blocks, so what the kernel does actually
shouldn't be that important.
The C library (which handles the memory for the threads) will serialize the
malloc()/free() new/delete calls using a mutex semaphore but unless you do a
very very large number of allocations and deallocations this will not hurt you.
> in a regular, single-processor system, my original C++ program spent 50% of
> its time in malloc/free. i reduced this time very
If you link your program with ElectricFence, the kernel will spend a lot of
time doing memory protection stuff at every malloc() and free(). If that's not
the problem, then you should probably rewrite the algorithm to handle memory
better (use fewer allocations)
> significantly by implementing memory pools. the basic algorithm is fairly
> easy to split up across threads. hence linux SMP for more performance.
Good :)
> but i am wondering if i might be walking into a "technical snare" with
> respect to linux and memory management.
I don't think so. If you're just careful that your algorithms are efficient
when they run serially, and you're careful that they don't use pthread_lock and
_unlock excessively when they're parallel, you should do just fine.
If the algorithms parallelize well, or if they run independently of eachother,
SMP should give you around 100% speedup in the latter case at least. You can
see below 100% speedup if the algorithms depend on memory bus bandwidth, and
you can see superlinear speedup if the algorithms fit in the L1/L2 caches of
the individual CPUs (if you use CPUs that have their own L2 caches of course,
like PPro/PII/PIII).
................................................................
: [EMAIL PROTECTED] : And I see the elder races, :
:.........................: putrid forms of man :
: Jakob �stergaard : See him rise and claim the earth, :
: OZ9ABN : his downfall is at hand. :
:.........................:............{Konkhra}...............:
-
Linux SMP list: FIRST see FAQ at http://www.irisa.fr/prive/mentre/smp-faq/
To Unsubscribe: send "unsubscribe linux-smp" to [EMAIL PROTECTED]