svn commit: r282948 - head/lib/libthr/thread
Bryan Drewery
bdrewery at FreeBSD.org
Sat May 16 16:40:23 UTC 2015
On 5/15/2015 3:40 AM, Konstantin Belousov wrote:
> Author: kib
> Date: Fri May 15 08:40:17 2015
> New Revision: 282948
> URL: https://svnweb.freebsd.org/changeset/base/282948
>
> Log:
> Some third-party malloc(3) implementations use pthread_setspecific(3)
> to handle per-thread information. Since our pthread_setspecific()
> implementation calls calloc(3) to allocate per-thread specific data
> storage, things get complicated.
>
> Switch the allocator to use bare mmap(2). There is some loss of the
> allocated page, since e.g. on amd64, PTHREAD_KEYS_MAX * sizeof(struct
> pthread_specific_elem) is 3K (it actually spans whole page due to
> padding), but I believe it is more acceptable than additional code for
> specialized allocator().
>
> The alternatives would either to make the specific data array be part of
> the struct thread, or use internal bindings to call the libc malloc,
> avoiding interposing.
>
> Also do the style pass over the thr_spec.c, esp. simplify the
> conditionals nesting by returning early when an error detected.
> Remove trivial comments.
>
> Found by: yuri at rawbw.com
> PR: 200138
> Sponsored by: The FreeBSD Foundation
> MFC after: 2 weeks
>
> Modified:
> head/lib/libthr/thread/thr_spec.c
>
Thank you for this!
I have a lot of patches at Isilon for adding a libc cleanup function to
free all caching, for use in memory leak detectors such as valgrind. I
even fixed valgrind to utilize it. This particular code was problematic.
I wrote up an arch mail about my patch a few months ago and it ended up
being several pages about libthr. I never sent it because it became too
long. I need to revisit that work and get an arch@ discussion going on
my proposal and the various issues I ran into with libthr.
While developing this cleanup feature, and working on a malloc wrapper
(dmalloc), I had a lot of problems with pthread_mutext_t (and similar
primitives) using calloc(3). I found that David Xu actually did do most
of the work to change this but abandoned it (it's all in SVN still).
Using pthreads from a malloc wrapper is really painful to get right.
--
Regards,
Bryan Drewery
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freebsd.org/pipermail/svn-src-all/attachments/20150516/a2ee0039/attachment.sig>
More information about the svn-src-all
mailing list