Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hDim0-0001l3-5q for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Apr 2019 04:54:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hDily-000661-OW for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Apr 2019 04:54:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hDily-00065t-8F for pgsql-hackers@lists.postgresql.org; Tue, 09 Apr 2019 04:54:14 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hDilr-0005Fv-1J for pgsql-hackers@lists.postgresql.org; Tue, 09 Apr 2019 04:54:13 +0000 Received: by mail-pf1-x444.google.com with SMTP id t21so6635307pfh.2 for ; Mon, 08 Apr 2019 21:54:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=arPh5JX3juXVJZclJ7AKyIRSN+ybszOR3+4MLBOr9hs=; b=Xtw/nPLtSZr5opKMzZP8dI69G7VCHBClbGeN2VeOqn5fkXPonwtoV502P0tW8R7QiN hYdhVQeMJPM+6NwwgFCqfjFVG9Yqq2OKubimt3GKg9M3etxzaF1UUiGydcBvASjh/Pkk +5CKxhFa8pAXPW+Mx7U3YJgTqVyCOzWkJt0TI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=arPh5JX3juXVJZclJ7AKyIRSN+ybszOR3+4MLBOr9hs=; b=qiUkAusNhkiBUeOHnFDFD5yUBEZjoSh5MZfFRJM7Lv1ZVq/WJM1ZgFmW3P3cAQfxOe GvIK6dckS+Yvj52HTfCQepkTkcNWmgkXYWIkmMg0dNHDCi13ThzCDfwqpbF7BCz/Bad+ 5kOJyx6i1PykOlVNmy9YLwHgRxmYgAsxjL4MD6yYLKpcc0WQW03uxcft4P0P5HqKsXjD a0JzAsrJ5vDq+H2dzCnjb+/d2eTd7cyxd8FIQNErDmEekQtPfvNG2HVDAtgnnO0xri0g +k+C2WaZeEhlC7gQTT8abkfZldF4687VPD0nJMSXtpJfSK89QtzEF4twTs4y+OLXc28x VI7A== X-Gm-Message-State: APjAAAUBqA12/dd44hWkv3FlfsqEq12mxwCNzf/HolJeIv0qz9D09gCh 0DnG2IJHTfwsnoX39VKVAtOsHg== X-Google-Smtp-Source: APXvYqxBeSoXjgkBD3mkfg5LEW7gUGcjpjOr39JYlykiYQxplk03rfdtST3GANl9E9vh6ffqBYFPpQ== X-Received: by 2002:a65:5106:: with SMTP id f6mr31889790pgq.253.1554785644534; Mon, 08 Apr 2019 21:54:04 -0700 (PDT) Received: from rfd.leadboat.com (108-233-125-46.lightspeed.sntcca.sbcglobal.net. [108.233.125.46]) by smtp.gmail.com with ESMTPSA id k9sm41762139pga.22.2019.04.08.21.54.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Apr 2019 21:54:03 -0700 (PDT) Date: Mon, 8 Apr 2019 21:54:01 -0700 From: Noah Misch To: Tom Lane Cc: Heath Lord , Stephen Frost , Andres Freund , Thomas Munro , PostgreSQL Hackers , joseph.ayers@crunchydata.com Subject: Re: "could not reattach to shared memory" on buildfarm member dory Message-ID: <20190409045401.GA2436694@rfd.leadboat.com> References: <18056.1525148010@sss.pgh.pa.us> <22096.1525188710@sss.pgh.pa.us> <20180819020007.GD3795674@rfd.leadboat.com> <14554.1537811585@sss.pgh.pa.us> <20180925150512.GA3990982@rfd.leadboat.com> <20181203053506.GB2860387@rfd.leadboat.com> <20190402135442.GA1173872@rfd.leadboat.com> <18088.1554214140@sss.pgh.pa.us> <20190407043221.GA1914190@rfd.leadboat.com> <32723.1554612203@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <32723.1554612203@sss.pgh.pa.us> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sun, Apr 07, 2019 at 12:43:23AM -0400, Tom Lane wrote: > Noah Misch 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.