Thread overview
Cannot use TCMalloc
Mar 31, 2016
Nordlöw
Mar 31, 2016
Basile B.
Mar 31, 2016
Nordlöw
Mar 31, 2016
Basile B.
Mar 31, 2016
Basile B.
Mar 31, 2016
Basile B.
Mar 31, 2016
Nordlöw
March 31, 2016
Has anybody compiled and run a D program with TCMalloc instead of glibc's own PTMalloc?

The performance, especially multi-thread allocation, looks very promising:
http://goog-perftools.sourceforge.net/doc/tcmalloc.html

I tried adding either

-L-ltcmalloc
-L-ltcmalloc_minimal

to DMD but all these errors as

/usr/bin/ld: cannot find -ltcmalloc
/usr/bin/ld: cannot find -ltcmalloc_minimal

none of them works on my Ubuntu 15.10.

It's installed on my system via

sudo apt-get install libtcmalloc-minimal4

and placed at

/usr/lib/libtcmalloc_minimal_debug.so.4.2.6
/usr/lib/libtcmalloc_minimal.so.4.2.6
/usr/lib/libtcmalloc_minimal_debug.so.4
/usr/lib/libtcmalloc_minimal.so.4

What's wrong?

Please help.
March 31, 2016
On Thursday, 31 March 2016 at 15:28:47 UTC, Nordlöw wrote:
> Has anybody compiled and run a D program with TCMalloc instead of glibc's own PTMalloc?
>
> The performance, especially multi-thread allocation, looks very promising:
> http://goog-perftools.sourceforge.net/doc/tcmalloc.html
>
> I tried adding either
>
> -L-ltcmalloc
> -L-ltcmalloc_minimal
>
> to DMD but all these errors as
>
> /usr/bin/ld: cannot find -ltcmalloc
> /usr/bin/ld: cannot find -ltcmalloc_minimal
>
> none of them works on my Ubuntu 15.10.
>
> It's installed on my system via
>
> sudo apt-get install libtcmalloc-minimal4
>
> and placed at
>
> /usr/lib/libtcmalloc_minimal_debug.so.4.2.6
> /usr/lib/libtcmalloc_minimal.so.4.2.6
> /usr/lib/libtcmalloc_minimal_debug.so.4
> /usr/lib/libtcmalloc_minimal.so.4
>
> What's wrong?
>
> Please help.

You need to install the "-devel" version to get the it as a static library. On OpenSuse it's named gperftools-devel.

Maybe on ubuntu it's this one:

"libgoogle-perftools-dev"

http://packages.ubuntu.com/fr/trusty/amd64/libgoogle-perftools-dev/filelist, because it contains the "*.a" static library you wanna link in.


March 31, 2016
On Thursday, 31 March 2016 at 19:09:20 UTC, Basile B. wrote:
> You need to install the "-devel" version to get the it as a static library. On OpenSuse it's named gperftools-devel.
>
> Maybe on ubuntu it's this one:
>
> "libgoogle-perftools-dev"
>
> http://packages.ubuntu.com/fr/trusty/amd64/libgoogle-perftools-dev/filelist, because it contains the "*.a" static library you wanna link in.

Works. Wonderful. Thanks.

BTW: Will this affect D's builtin GC or does it use mmap directly?
March 31, 2016
On Thursday, 31 March 2016 at 20:21:00 UTC, Nordlöw wrote:
> On Thursday, 31 March 2016 at 19:09:20 UTC, Basile B. wrote:
>> You need to install the "-devel" version to get the it as a static library. On OpenSuse it's named gperftools-devel.
>>
>> Maybe on ubuntu it's this one:
>>
>> "libgoogle-perftools-dev"
>>
>> http://packages.ubuntu.com/fr/trusty/amd64/libgoogle-perftools-dev/filelist, because it contains the "*.a" static library you wanna link in.
>
> Works. Wonderful. Thanks.
>
> BTW: Will this affect D's builtin GC or does it use mmap directly?

It looks like if you manage to hook default malloc, free etc the GC will be affected.

But a simple try to call the functions from the static lib fails (the first script line is passed to DMD by my editor):


    #!runnable flags: -L-ltcmalloc
    extern(C) void* tc_malloc(size_t size);
    extern(C) void  tc_free(void* ptr);

    void main(string[] args)
    {
        auto p = tc_malloc(16);
        tc_free(p);
    }

/tmp/temp_7FCC33C16DF0.d:(.text._Dmain+0xa): référence indéfinie vers « tc_malloc »
/tmp/temp_7FCC33C16DF0.d:(.text._Dmain+0x12): référence indéfinie vers « tc_free »

interface seems to be this:
https://github.com/gperftools/gperftools/blob/master/src/gperftools/tcmalloc.h.in#L88

Do you have the interface or the D sources to call the functions ?
March 31, 2016
On Thursday, 31 March 2016 at 21:26:45 UTC, Basile B. wrote:
> On Thursday, 31 March 2016 at 20:21:00 UTC, Nordlöw wrote:
>> [...]
>
> It looks like if you manage to hook default malloc, free etc the GC will be affected.
>
> [...]

Actually it works, I forgot a hyphen in the scipt line !
Do you plan to make a package or something ? I think it'll be usable in a allocator-like structure.

March 31, 2016
On Thursday, 31 March 2016 at 21:44:21 UTC, Basile B. wrote:
> I think it'll be usable in a allocator-like structure.

it is indeed: http://code.dlang.org/packages/tcmallocd
March 31, 2016
On Thursday, 31 March 2016 at 23:15:18 UTC, Basile B. wrote:
>
> it is indeed: http://code.dlang.org/packages/tcmallocd

Nice! Good work!