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 1jgvDK-0001s5-W7 for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Jun 2020 19:07:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jgvDJ-0005fP-QW for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Jun 2020 19:07:41 +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 1jgvDJ-0005fI-Jq for pgsql-hackers@lists.postgresql.org; Thu, 04 Jun 2020 19:07:41 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jgvDG-0000Km-C3 for pgsql-hackers@lists.postgresql.org; Thu, 04 Jun 2020 19:07:41 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 054J7Yme1256702; Thu, 4 Jun 2020 15:07:34 -0400 From: Tom Lane To: Andres Freund cc: pgsql-hackers@lists.postgresql.org Subject: Re: Atomic operations within spinlocks In-reply-to: <20200604185525.wuyjtkluppj4eddr@alap3.anarazel.de> References: <1141819.1591208385@sss.pgh.pa.us> <20200603204542.reuladbmgmjqzoi6@alap3.anarazel.de> <1253593.1591293439@sss.pgh.pa.us> <20200604185525.wuyjtkluppj4eddr@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Thu, 04 Jun 2020 11:55:25 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1256700.1591297654.1@sss.pgh.pa.us> Date: Thu, 04 Jun 2020 15:07:34 -0400 Message-ID: <1256701.1591297654@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andres Freund writes: > I'd still like to know which problem we're actually trying to solve > here. I don't understand the "error" issues you mentioned upthread. If you error out of getting the inner spinlock, the outer spinlock is stuck, permanently, because there is no mechanism for spinlock release during transaction abort. Admittedly it's not very likely for the inner acquisition to fail, but it's possible. Aside from timeout scenarios (e.g., process holding lock gets swapped out to Timbuktu), it could be that both spinlocks are mapped onto a single implementation lock by spin.c, which notes * We map all spinlocks onto a set of NUM_SPINLOCK_SEMAPHORES semaphores. * It's okay to map multiple spinlocks onto one semaphore because no process * should ever hold more than one at a time. You've falsified that argument ... and no, I don't want to upgrade the spinlock infrastructure enough to make this OK. We shouldn't ever be holding spinlocks long enough, or doing anything complicated enough inside them, for such an upgrade to have merit. regards, tom lane