Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 May 2015 11:40:26 -0500
From:      Bryan Drewery <bdrewery@FreeBSD.org>
To:        Konstantin Belousov <kib@FreeBSD.org>, src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r282948 - head/lib/libthr/thread
Message-ID:  <555772FA.2080408@FreeBSD.org>
In-Reply-To: <201505150840.t4F8eHhM000804@svn.freebsd.org>
References:  <201505150840.t4F8eHhM000804@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--V2VQqCUxc38WfvmkBeTmRbEMAdALPOMfx
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

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
>=20
> 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.
>  =20
>   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 fo=
r
>   specialized allocator().
>  =20
>   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.
>  =20
>   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.
>  =20
>   Found by:	yuri@rawbw.com
>   PR:	200138
>   Sponsored by:	The FreeBSD Foundation
>   MFC after:	2 weeks
>=20
> Modified:
>   head/lib/libthr/thread/thr_spec.c
>=20

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.

--=20
Regards,
Bryan Drewery


--V2VQqCUxc38WfvmkBeTmRbEMAdALPOMfx
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBAgAGBQJVV3L6AAoJEDXXcbtuRpfPV5IIAOET2XsUZhEavP/dvKuBQK46
L0HGVyexgUcx/2Zmb9HhI21xaPl6uTsgc7wycJgJXGjXNpqRipSursGogvqEcrTW
c50aTnPgzGj2jC9hOWcjK34MdVU0Q/Amkj/mkeToYDAaxRVYszdOuc1Xvg3nlnDn
ZFioXGT6FzpjYcyZAOaKi9xeKJm+4Y2f65fEOF4kXjwhXbFtDdQ9QDPUQ/avzL5x
Ddladk6VAbKssJKWmuJkR7zVRWHHlAGcmPOZ5v2NPP/aXyaYE/429rGsmDMwqMdR
uHhN0j4QdJ+wjWT29lyneDUS9FQVJIAEnpaHbJJqyGEzoeU7dkIkMQbAcxMADIQ=
=roz7
-----END PGP SIGNATURE-----

--V2VQqCUxc38WfvmkBeTmRbEMAdALPOMfx--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?555772FA.2080408>