Re: "could not reattach to shared memory" on buildfarm member dory

From: Noah Misch <noah(at)leadboat(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Heath Lord <heath(dot)lord(at)crunchydata(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>, Andres Freund <andres(at)anarazel(dot)de>, Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, joseph(dot)ayers(at)crunchydata(dot)com
Subject: Re: "could not reattach to shared memory" on buildfarm member dory
Date: 2019-04-07 04:32:21
Message-ID: 20190407043221.GA1914190@rfd.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Apr 02, 2019 at 10:09:00AM -0400, Tom Lane wrote:
> Noah Misch <noah(at)leadboat(dot)com> writes:
> > I can reproduce the 4 MiB allocations described
> > in https://postgr.es/m/29823.1525132900@sss.pgh.pa.us; a few times per
> > "vcregress check", they emerge in the middle of PGSharedMemoryReAttach().
> > The 4 MiB allocations are stacks for new threads of the default thread
> > pool[1].
>
> Hah! It is great to finally have an understanding of what is happening
> here.
>
> 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.

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?

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2019-04-07 04:43:23 Re: "could not reattach to shared memory" on buildfarm member dory
Previous Message Ramanarayana 2019-04-07 03:46:24 Re: Problem during Windows service start