pthread programming eats up resources (My or FreeBSD's fault?)
Andre Albsmeier
mail at ma17.ata.myota.org
Thu Feb 20 12:16:30 UTC 2014
On Thu, 20-Feb-2014 at 16:06:30 +0800, David Xu wrote:
> On 2014/02/20 14:06, Erich Dollansky wrote:
> > Hi,
> >
> > On Thu, 20 Feb 2014 13:41:08 +0800
> > David Xu <davidxu at freebsd.org> wrote:
> >
> >> On 2014/02/19 02:06, Andre Albsmeier wrote:
> >>
> >> please compile it as static binary and run it, check if the
> >> problem still exists, I am hunting the bug, it is not necessary in
> >> the libthr because I have not changed its code for a long time.
> >
> > I just compiled is a static program. The behaviour is now different.
> > The size still grows but much slower while 'res' stays below some 10MB.
> >
> > Size also got stagnant after some 2 min CPU time hanging around 126MB.
> >
> > I am running it on:
> >
> > FreeBSD X220.alogt.com 10.0-STABLE FreeBSD 10.0-STABLE #15 r261342: Sat
> > Feb 1 14:52:39 WITA 2014
> > erich at X220.alogt.com:/usr/obj/usr/src/sys/X220 amd64
> >
> > Erich
> >
>
> I have found the bug, it is in rtld, where malloc_aligned() is
> misfunctioning, memory can be corrupted by the function.
>
> libthr calls _rtld_allocate_tls to allocate tls control block,
> the function is in rtld, its uses malloc_aligned() which is not
> working correctly.
>
> Patch is attached.
Your patch seems to have fixed it here on 9.2-STABLE as well.
Memory consumption stays at around 9MB RES and 130 MB SIZE
for pth2. Thanks!
-Andre
>
> Regards,
> David Xu
>
> Index: libexec/rtld-elf/xmalloc.c
> ===================================================================
> --- libexec/rtld-elf/xmalloc.c (revision 260700)
> +++ libexec/rtld-elf/xmalloc.c (working copy)
> @@ -72,14 +72,10 @@
> malloc_aligned(size_t size, size_t align)
> {
> void *mem, *res;
> - uintptr_t x;
> - size_t asize, r;
>
> - r = round(sizeof(void *), align);
> - asize = round(size, align) + r;
> - mem = xmalloc(asize);
> - x = (uintptr_t)mem;
> - res = (void *)round(x, align);
> + mem = xmalloc(size + sizeof(void *) + align - 1);
> + res =(void*)(((uintptr_t)mem + sizeof(void *) + align - 1) &
> + ~(align - 1));
> *(void **)((uintptr_t)res - sizeof(void *)) = mem;
> return (res);
> }
--
My other computer is your windows box.
More information about the freebsd-hackers
mailing list