On Nov 21 00:08, Dan Shelton wrote:
> On Wed, 20 Nov 2024 at 12:03, Corinna Vinschen
> <corinna-cyg...@cygwin.com> wrote:
> >
> > Hi Teemu,
> >
> > On Nov 18 23:28, Teemu Nätkinniemi wrote:
> > > Hello!
> > >
> > > I raised this issue couple of years ago on cygwin-developers.
> >
> > The cause of the problem is well known for a long time.  The underlying
> > dlmalloc implementation was never developed for threaded processes, and
> > Cygwin was originally not multi-thread capable so that wasn't much
> > of a problem.
> >
> > Since that time, Cygwin has moved to multi-threading but we still use
> > dlmalloc under the hood.  The simple approach of just adding a lock
> > to each call into dlmalloc (see winsup/cygwin/mm/malloc_wrapper.cc)
> > avoids crashes, but leads to congestion in processes using lots of
> > memory allocation in lots of threads.
> >
> > This is aggravated by the fact that we use malloc within Cygwin itself.
> >
> > There were a couple of efforts over the years to replace dlmalloc
> > with, for instance, ptmalloc3, or to convert dlmalloc to the USE_LOCKS
> > variant.
> 
> Where can we find that variant?

In the dlmalloc source itself: winsup/cygwin/mm/malloc.cc

> > For some reason or other, none of these efforts where
> > ultimately fruitful yet.  Personally I have to admit defeat in trying
> > to get ptmalloc3 running, more than 10 years ago.
> >
> > Anyway.  Having said that, anybody being able to come up with a malloc
> > port which actually works as part of Cygwin *and* avoids the contention
> > of the current solution will get as many goldstars and plush hippos
> > (see https://cygwin.com/goldstars/) the person asks for.
> 
> What about mimalloc? Would that help?

Who knows without actually trying?

This is a MSFT allocator, so if you try that: Keep in mind that the
allocator must use sbrk() and/or mmap() under the hood, because only
areas allocated via sbrk() and mmap() are inherited after fork().

Having said that...

Whatever allocator you try, given that we have at least a 47 bit address
space nowadays, we could probably add another allocation arena apart
from heap and mmap arena without much problems.  The important thing is
that this arena is reproducably inheritable during fork(), just like
the heap and mmap arenas.

See winsup/cygwin/local_includes/memory_layout.h for the current memory
layout.


Corinna

Reply via email to