wrong performance of malloc/free under multi-threading

Corinna Vinschen corinna-cygwin@cygwin.com
Tue Feb 26 09:14:00 GMT 2013

On Feb 26 15:35, MITSUNARI Shigeo wrote:
> Hi.
> I found that the performance of malloc/free is wrong under multi-threading.
> The following test program reproduces the problem.
> The program repeats malloc and free under multi-thread.
> I measured the timing on Cygwin and Linux.
> timing(sec)|      threadNum
> -----------+----------+-------------
>            | 1        |     2
> -----------+----------+-------------
> Linux      | 1.45     |     0.69
> -----------+----------+-------------
> Cygwin     | 2.059    |    53.165
> -----------+----------+-------------
> The timing under Linux seems good scale but it is very wrong under Cygwin.
> Is it intentional behavior or do I use pthread in bad way?

No, you're right.  This is easily reproducable.  I just had a look and
it seems that our malloc is really slow in multi-threading scenarios.
We're using Doug Lea's malloc unchanged with just additional locks
surrounding the underlying malloc/free calls.

This appears to be a serious performance problem.  I just learned that
glibc uses another version of dlmalloc, called ptmalloc, which is a
derived version of dlmalloc optimized for multi-threading environments.

Perhaps we have to do the same, but I don't know how long it takes to
port ptmalloc to Cygwin and obviously I don't know how big the
performance gain might be.


Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

More information about the Cygwin mailing list