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 1hCzTx-0002gh-Nb for pgsql-hackers@arkaria.postgresql.org; Sun, 07 Apr 2019 04:32:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hCzTu-0004lp-NF for pgsql-hackers@arkaria.postgresql.org; Sun, 07 Apr 2019 04:32:34 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hCzTu-0004iT-23 for pgsql-hackers@lists.postgresql.org; Sun, 07 Apr 2019 04:32:34 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hCzTm-0004Ji-TJ for pgsql-hackers@lists.postgresql.org; Sun, 07 Apr 2019 04:32:32 +0000 Received: by mail-pl1-x642.google.com with SMTP id ck15so5330580plb.3 for ; Sat, 06 Apr 2019 21:32:26 -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=0gK6MIBJJuS+r3I/xlFupFzCny9qtRHEuxweJSzdPDU=; b=APFyJ1LcMOZv6Ub892qpvTrYnli+GSEneB+FD96YAuTjMXhr0Z26Vm9TcWg5f3wHy0 tauFmb6qU9w9/a+84gWggajC5+FT6/x3zIbjPw/ab4y1PfUtZUueZ3d5NrJli93q5JEn MZprNeb83A0PHYzbEROPBqOdZPoEJhYti7lGY= 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=0gK6MIBJJuS+r3I/xlFupFzCny9qtRHEuxweJSzdPDU=; b=G+IC9403c8nXClRF1D/6wzh+FM2MzYzkp/Y314fVZ6b0Y6mPELV7Jg3e1gimBMWptG iDBWd7JgBEVdHUO1qwsEzXxdqxwlVOn1GXtuJcHZjNibHUHoHn7F18Kb/dnqlmpfyTw2 N0EXCEyy4Adpwuub0mdBVL9lswxwhFQGkKYFtMnbFW4QqaQapSZtcyD+x30vU5pMauKG /501nGXtNkuFRaUnCZJLt9O6rlkvRncGm/gV80+/FKqYm9wjnc6utU0nZZtwgcX0TIDD tB6OYUdattZ23GoW6s2SdMRYDCQM70tztY/zdCqmHwv539YrnmW669/MP1zFst1foln4 SL6w== X-Gm-Message-State: APjAAAUPQYnjFHba03npBZuThyoR9WrWv6QUHvm2VJSDrm5vRQDAXsbR 5hz4t3QHZsSJr+k0RXv3BQO3rg== X-Google-Smtp-Source: APXvYqw60NgfzP1tqCPP1JHYEDdsb8iKSP4B4dCEWvgeRY9kFKQVYbcwFVXwb3m87NmXdo0YtVljGg== X-Received: by 2002:a17:902:3183:: with SMTP id x3mr22748997plb.170.1554611545216; Sat, 06 Apr 2019 21:32:25 -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 d8sm22745837pgv.34.2019.04.06.21.32.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 06 Apr 2019 21:32:24 -0700 (PDT) Date: Sat, 6 Apr 2019 21:32:21 -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: <20190407043221.GA1914190@rfd.leadboat.com> References: <29823.1525132900@sss.pgh.pa.us> <20180501002419.onmikldoe2ssjauq@alap3.anarazel.de> <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <18088.1554214140@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 Tue, Apr 02, 2019 at 10:09:00AM -0400, Tom Lane wrote: > Noah Misch 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?