Thoughts about malloc(3) and threading.
Poul-Henning Kamp
phk at phk.freebsd.dk
Mon Sep 6 03:45:32 PDT 2004
A number of times the issue of memory allocation in threaded programs
have come up in various fora.
In order to not become a road block for this important area, I want
to state my opinion on this matter for the record:
For single-threaded programs and non-malloc intensive multi-threaded
programs I am still of the opinion that phkmalloc is our best choice.
The combination of strong error checking and focus on minimal working
set size seems to me a good compromise between functionality and
raw performance for a general purpose malloc in a general purpose
operating system.
For multi-threaded programs with a lot of malloc activity, phkmalloc
does not work well since it requires one big lock around the entire
thing and does not do anything to preserve processor affinity.
I think we need a malloc which can service this hi-end segment
effectively, but even though various suggestions for replacements
of phkmalloc to address this have been made, I do not see any clear
winner or even the full list of candidates yet.
Since a malloc which is aware of multiple CPUs or which relies on
per-cpu locks can not implement a strong level of error checking,
my guess is that we will end up retaining phkmalloc as the default
and have a "SMP malloc" for the heavy duty case.
It can (and without doubt will) be argued that the "SMP malloc"
should be a port, but lets not even go there until we have a
candidate.
So, short version of my position is:
I am not and will not be researching this topic and that
people with a serious interest in it should get started.
Given the list of programs which have been found buggy by
phkmalloc, I do not think we should default to a malloc which
does not have strong error checking.
If a malloc better than phkmalloc in performance and error
checking is found/written, I'll be all for a replacement
if that means we will only have one malloc.
Anyone wanting to work on this is welcome to contact me for
some hard-earned insight into what and how to benchmark etc.
Poul-Henning
--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
More information about the freebsd-arch
mailing list