public inbox for cygwin-developers@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin-developers@cygwin.com
Subject: Re: More (?) steps toward jemalloc within Cygwin DLL
Date: Tue, 21 Jul 2020 14:00:02 +0200	[thread overview]
Message-ID: <20200721120002.GN16360@calimero.vinschen.de> (raw)
In-Reply-To: <75b43adc-ebcd-1d98-bd3e-33b8337f0475@maxrnd.com>

Hi Mark,

On Jul 21 01:50, Mark Geisert wrote:
> Corinna Vinschen wrote:
> > [...]
> > ...the big problem are dependencies on malloc during Cygwin startup,
> > especially in fork/exec, so the real challenge is to get the new malloc
> > still let Cygwin processes start up correctly first time and especially
> > in fork/exec situations, and to make sure the malloc bookkeeping
> > survives fork/exec.
> 
> O.K., understood.
> 
> > These malloc dependencies sometimes crop up in the weirdest situations,
> > so that's something to look out for.  For instance, using pthread
> > functions may call malloc as well.  If a problem can be solved by
> > changing another part of Cygwin, don't hesitate to discuss this!
> 
> Yes, a couple of the malloc packages I'm testing want to allocate locks and
> TLS slots right off the bat so there's nasty recursion possible.

Given these locks are process-only, it's probably a good idea to overload
the functions with equivalent WinAPI function calls using, for instance,
slim R/W Locks.  If these locks are stored as global NO_COPY objects, they
don't even have to be initialized at process startup explicitely.  If they
have to be created dynamically, they should probably go into the cygheap,
so they are duplicated automagically.

> [...]
> Here's a question I didn't expect to come up: If it turns out a home-grown
> wrapper on the Win32 HeapXXX functions performs better (hint: it does, 2.5
> to 3 times better) than any malloc package derived from dlmalloc, is there
> any reason why we ought not use it?  Assuming it can be made to work for all
> those cases you mentioned above, of course.

It won't work with fork.  Malloc'd memory has to be duplicated in the exact
same spot during fork (think application pointers to allocated memory).
Windows Heaps are ASLR'ed and the mechanism the heap is allocating and
freeing memory is not built for reproducability in another process.

That's why we have our own process heap given away via sbrk, as well as
diligent bookkeeping of mmap'ed memory.

> > The only danger here is this: If you manage to get dlmalloc replaced
> > reliably, you *will* get a pink plush hippo!
> 
> Oh, gee, that sounds like a really nice reward... Wow, I'm gonna have to do
> this project now for sure!

I'm really looking forward to it!


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer

  reply	other threads:[~2020-07-21 12:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-16  9:16 Mark Geisert
2020-06-30  9:24 ` Corinna Vinschen
2020-07-03  6:57   ` Mark Geisert
2020-07-03 10:11     ` Corinna Vinschen
2020-07-21  8:50       ` Mark Geisert
2020-07-21 12:00         ` Corinna Vinschen [this message]
2020-07-21 22:06         ` Ford, Brian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200721120002.GN16360@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin-developers@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).