Discussion:
Jemalloc under CYGWIN
Corinna Vinschen
2015-10-21 14:15:23 UTC
Permalink
What exactly is the malloc problem you're seeing?
The specific problem I'm having is that jemalloc's malloc_init() calls
needs to use pthread_mutex_init() or even pthread_mutex with a
initializer. Both in-turn uses malloc, triggering this issue.
A quick fix would be somehow make pthread always use system
malloc/free, which shouldn't be that bad.
What about using a native critical section instead? It shouldn't be too
tricky to conditionalize this in jemalloc.
Another issue I saw is that jemalloc will use readlink() for
"/etc/jemalloc.conf" during malloc_init(), which on cygwin, this
function uses "new" to do some path manipulating work, which also have
the same issue. However, we can probably just disable that .
Or alternatively the file can be reasd like the other files in /etc
Cygwin needs early access to. See the NT_readline class and an
example usage in, e.g, mount_info::from_fstab.
So, the quickest fix would be to make cygwin's thread implementations
always use system malloc.
some small workarounds in jemalloc would be needed afterwards, but it
should be a nice starting point.
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
Yucong Sun
2015-10-21 14:43:55 UTC
Permalink
On Wed, Oct 21, 2015 at 10:15 PM, Corinna Vinschen
Post by Corinna Vinschen
What exactly is the malloc problem you're seeing?
The specific problem I'm having is that jemalloc's malloc_init() calls
needs to use pthread_mutex_init() or even pthread_mutex with a
initializer. Both in-turn uses malloc, triggering this issue.
A quick fix would be somehow make pthread always use system
malloc/free, which shouldn't be that bad.
What about using a native critical section instead? It shouldn't be too
tricky to conditionalize this in jemalloc.
Possibly, jemalloc already have support of this. However I wasn't so
sure that this was possible before,

see https://github.com/jemalloc/jemalloc/blob/dev/include/jemalloc/internal/mutex.h#L80
Corinna Vinschen
2015-10-21 15:40:21 UTC
Permalink
Post by Yucong Sun
On Wed, Oct 21, 2015 at 10:15 PM, Corinna Vinschen
Post by Corinna Vinschen
What exactly is the malloc problem you're seeing?
The specific problem I'm having is that jemalloc's malloc_init() calls
needs to use pthread_mutex_init() or even pthread_mutex with a
initializer. Both in-turn uses malloc, triggering this issue.
A quick fix would be somehow make pthread always use system
malloc/free, which shouldn't be that bad.
What about using a native critical section instead? It shouldn't be too
tricky to conditionalize this in jemalloc.
Possibly, jemalloc already have support of this. However I wasn't so
sure that this was possible before,
see https://github.com/jemalloc/jemalloc/blob/dev/include/jemalloc/internal/mutex.h#L80
Yes, that looks good. Please use critical sections for the time being.
We're going to drop XP support end of this year, but up to that point we
can't use SRW locks.


Thanks,
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
Corinna Vinschen
2015-11-26 09:30:44 UTC
Permalink
Hi Yucong Sun,
Post by Corinna Vinschen
Post by Yucong Sun
On Wed, Oct 21, 2015 at 10:15 PM, Corinna Vinschen
Post by Corinna Vinschen
What exactly is the malloc problem you're seeing?
The specific problem I'm having is that jemalloc's malloc_init() calls
needs to use pthread_mutex_init() or even pthread_mutex with a
initializer. Both in-turn uses malloc, triggering this issue.
A quick fix would be somehow make pthread always use system
malloc/free, which shouldn't be that bad.
What about using a native critical section instead? It shouldn't be too
tricky to conditionalize this in jemalloc.
Possibly, jemalloc already have support of this. However I wasn't so
sure that this was possible before,
see https://github.com/jemalloc/jemalloc/blob/dev/include/jemalloc/internal/mutex.h#L80
Yes, that looks good. Please use critical sections for the time being.
We're going to drop XP support end of this year, but up to that point we
can't use SRW locks.
did you manage to include jemalloc into Cygwin in the meantime? It
would be very cool to get a patch to replace dlmalloc with jemalloc :}


Thanks,
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
Yucong Sun
2015-12-05 14:32:11 UTC
Permalink
I'm sorry, I got distracted from this issue and hadn't make any progress.

One thing specifically I need to be able to work on this issue is some
information describing how to build/test cygwin lib (rather than using
it). I couldn't find any information on the website, (or I havn't look
deeply enough).

Cheers.
Corinna Vinschen
2015-12-06 14:07:56 UTC
Permalink
Post by Yucong Sun
I'm sorry, I got distracted from this issue and hadn't make any progress.
No worries.
Post by Yucong Sun
One thing specifically I need to be able to work on this issue is some
information describing how to build/test cygwin lib (rather than using
it). I couldn't find any information on the website, (or I havn't look
deeply enough).
It's not complicated, really.

1. Install gcc and mingw-gcc.

2. Prepare build dir:

$ mkdir cygwin
$ cd cygwin
$ git clone git://sourceware.org/git/newlib-cygwin.git
[...]
$ mkdir build
$ cd build

3. Build:

$ export PREFIX=/usr
$ ../newlib-cygwin/configure \
--prefix=${PREFIX} \
--exec-prefix=${PREFIX} \
--bindir=${PREFIX}/bin \
--sbindir=${PREFIX}/sbin \
--libexecdir=${PREFIX}/lib \
--datadir=${PREFIX}/share \
--localstatedir=/var \
--sysconfdir=/etc \
--infodir=${PREFIX}/share/info \
--mandir=${PREFIX}/share/man \
--docdir=${PREFIX}/share/doc/cygwin \
--htmldir=${PREFIX}/share/doc/cygwin/html
$ make
# Or for debugging:
$ make CFLAGS='-gdwarf-2' CFLAGS_FOR_TARGET='-gdwarf-2'

Add -j<NUM> as desired.


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