Re: "could not reattach to shared memory" on buildfarm member dory - Mailing list pgsql-hackers

From Noah Misch
Subject Re: "could not reattach to shared memory" on buildfarm member dory
Date
Msg-id 20190409045401.GA2436694@rfd.leadboat.com
Whole thread Raw
In response to Re: "could not reattach to shared memory" on buildfarm member dory  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Sun, Apr 07, 2019 at 12:43:23AM -0400, Tom Lane wrote:
> Noah Misch <noah@leadboat.com> writes:
> > On Tue, Apr 02, 2019 at 10:09:00AM -0400, Tom Lane wrote:
> >> I worry that your proposed fix is unstable, in particular this assumption
> >> seems shaky:
> >>> + * ... The idea is that, if the allocator handed out
> >>> + * REGION1 pages before REGION2 pages at one occasion, it will do so whenever
> >>> + * both regions are free.
> 
> > True.  If Windows changes to prefer allocating from the most recently freed
> > region, shmem-protective-region-v1.patch would cease to help.  It's not
> > impossible.
> 
> >> I wonder whether it's possible to address this by configuring the "default
> >> thread pool" to have only one thread?  It seems like the extra threads are
> >> just adding backend startup overhead to no benefit, since we won't use 'em.
> 
> > I didn't find a way to configure the pool's size.
> 
> Seems odd ...

I think you're expected to create your own thread pool if you're picky about
the size.  The default thread pool is for non-picky callers and for Windows
libraries to use internally.  The fact that the pool starts before main() also
narrows the use case for configuring it.  If there were an API for "block
until all threads of the pool are alive", that would meet our needs nicely.
Needless to say, I didn't find that, either.

> > Another option is to reattach shared memory earlier, before the default thread
> > pool starts.  A Windows application using only the unavoidable DLLs
> > (kernel32.dll, ntdll.dll, kernelbase.dll) doesn't get a default thread pool;
> > the pool starts when one loads ws2_32.dll, ucrtbased.dll, etc.  Hence, the
> > DllMain() function of a DLL that loads early could avoid the problem.  (Cygwin
> > fork() uses that route to remap shared memory, though it also retries failed
> > forks.)  If we proceed that way, we'd add a tiny pg_shmem.dll that appears
> > early in the load order, just after the unavoidable DLLs.  It would extract
> > applicable parameters from the command line and reattach shared memory.  When
> > it fails, it would set a flag so the usual code can raise an error.  Does that
> > sound more or less attractive than shmem-protective-region-v1.patch?
> 
> Well, it definitely sounds like more work.  Let's not do such work
> until we have to.  Your patch has the advantages of being (a) small
> and (b) done, and there's much to be said for that.

Works for me.  Pushed.



pgsql-hackers by date:

Previous
From: Amit Langote
Date:
Subject: Re: hyrax vs. RelationBuildPartitionDesc
Next
From: Heikki Linnakangas
Date:
Subject: Re: Sparse bit set data structure