Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kppQC-0005SA-1Y for pgsql-committers@arkaria.postgresql.org; Thu, 17 Dec 2020 09:18:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kppQA-0006uT-Qm for pgsql-committers@arkaria.postgresql.org; Thu, 17 Dec 2020 09:18:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kppQA-0006uM-L2 for pgsql-committers@lists.postgresql.org; Thu, 17 Dec 2020 09:18:02 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kppQ8-0002rp-FE for pgsql-committers@lists.postgresql.org; Thu, 17 Dec 2020 09:18:02 +0000 Received: from hnk.local (sp183-74-204-109.msb.spmode.ne.jp [183.74.204.109]) by oss.nttdata.com (Postfix) with ESMTPSA id 9A9C562720; Thu, 17 Dec 2020 18:17:55 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.3 at oss.nttdata.com Subject: Re: pgsql: Get rid of the dedicated latch for signaling the startup process From: Fujii Masao To: Heikki Linnakangas , Fujii Masao , pgsql-committers@lists.postgresql.org References: <5c1f8a85-747c-7bf9-241e-dd467d8a3586@iki.fi> <3d3c42ca-c1bd-605d-71cf-8cd6353e895b@iki.fi> <8f02685c-4029-c038-8bbb-99fe22d09379@oss.nttdata.com> Message-ID: <5dd3bbe0-3845-52d4-ce69-083102ba0094@oss.nttdata.com> Date: Thu, 17 Dec 2020 18:17:54 +0900 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020/11/05 23:32, Fujii Masao wrote: > > > On 2020/11/05 6:02, Fujii Masao wrote: >> >> >> On 2020/11/05 5:36, Heikki Linnakangas wrote: >>> On 04/11/2020 15:17, Heikki Linnakangas wrote: >>>> On 04/11/2020 14:03, Fujii Masao wrote: >>>>> Or ISTM that WakeupRecovery() should set the latch only when the latch >>>>> has not been reset to NULL yet. >>>> >>>> Got to be careful with race conditions, if the latch is set to NULL at >>>> the same time that WakeupRecovery() is called. >>> >>> I don't think commit 113d3591b8 got this quite right: >>> >>>> void >>>> WakeupRecovery(void) >>>> { >>>>     if (XLogCtl->recoveryWakeupLatch) >>>>         SetLatch(XLogCtl->recoveryWakeupLatch); >>>> } >>> >>> If XLogCtl->recoveryWakeupLatch is set to NULL between the if and the SetLatch, you'll still get a segfault. That's highly unlikely to happen in practice because the compiler will optimize that into a single load instruction, but could happen with -O0. I think you'd need to do the access only once, using a volatile pointer, to make that safe. > > On second thought, since fetching the latch pointer might not be atomic, > maybe we need to use spinlock like WalRcvForceReply() does. But using > spinlock in every calls of WakeupRecovery() might cause performance > overhead. So I'm thinking to use spinlock only when it's necessary, i.e., > when the latch may be reset to NULL concurrently. Attached is the POC > patch implementing that. Thought? Previously I added this patch to next CommitFest. But I reverted the commit ac22929a26 and 113d3591b8 because those changes have other issue. So this patch is no longer necessary, and I dropped it from next CommitFest. Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION