Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wL5Xq-001WLD-1S for pgsql-hackers@arkaria.postgresql.org; Thu, 07 May 2026 20:42:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wL5Xp-0064Mn-0M for pgsql-hackers@arkaria.postgresql.org; Thu, 07 May 2026 20:42:05 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wL5Xo-0064Me-2I for pgsql-hackers@lists.postgresql.org; Thu, 07 May 2026 20:42:04 +0000 Received: from mail-qt1-x836.google.com ([2607:f8b0:4864:20::836]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wL5Xm-000000014Y9-1EDO for pgsql-hackers@postgresql.org; Thu, 07 May 2026 20:42:04 +0000 Received: by mail-qt1-x836.google.com with SMTP id d75a77b69052e-50fbd79350dso10751561cf.3 for ; Thu, 07 May 2026 13:42:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778186519; x=1778791319; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=1jj01/Ry1Z2oNbzVEXs0tCM06b7OkpWm2Ra+PNSHbhc=; b=qrU5m9YTGbdXdTjhW08bStSViJ2CCcySJ+kLzIXtUN++oTdzZQ6f44kd2v2uKAa3J/ Hjb2uSwmem52kJ0iIYzPKV6vnXJ4BvpNwaq5ubuWdbpZT9U6Q29ImGUEyJ0Sxbf0+4Rg 5i8v+wL2V0Fhw8iXaIuXc3hiMUnmaJdglF5UvQdfewRBdPl1Bcleaatd8ozHQEu44MNh DKU14X/WjHuFyOHYqMZIiXDHON7TfDU/wfH4khgJ8yi7d/m6mfJ3t3nJlZQdMyeWCMqH QxIropqIpkJc2ToRS0lWqiJ8SiuZWa0A9mZuszqWGhlxAxAKUvdfJmGmS3OvFshGFJkl cKkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778186519; x=1778791319; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1jj01/Ry1Z2oNbzVEXs0tCM06b7OkpWm2Ra+PNSHbhc=; b=fbypqmLaO1pW93oNcgWfaNGpD4SysvhdeI1Ivpz09/WgCYbkyP2zj/S7jc2JIrMs9T QlF/IxGpOfKmIv1u3tb3p4sEcYOhB4RSCim5Kh2mBXO+XlX/5KpHu4qoRfgqiox7Q3Tl AV9pRzMesQslnQxjU0IoaPPPzYco2MOBEFtn3LeahEWpbgwMn7dOMLMDglIl0A+WmocJ RMZNDW6IBUY8z490qEHgGYNW2o/5+PDE7vrqJXh5rtxDGIqt1zZ2NLk/2p5kAAooGCzJ zEFmzQGDsU+PJLgNa5d6NeaggiWL3J9Uu/8a9347cUjnHCGLCcfxBw6meFB/WRZxF7Fq YUYw== X-Gm-Message-State: AOJu0YwMMNwJhqz2cNnPFcFN2nTC238q51ZCNTBzX9ASmSst1Vd8OT4l fA/6tJ1R/3Pmos/KrxvNKv9fptYH+Ce+eO8je5Nx1wktDuKkaYKwEdBaCTTkyg== X-Gm-Gg: AeBDiev521tAe5SqU01H36cjvkQ/tcsOHjWhIZSWId6/yQWnw4Bs8FxYFeQSvkYEWw7 XnLZnO5/a196mj2kNKdNM0HQfAC1Lt7CzUAH0nkE3uCbY9/xrr2lMUXxAyU2Piyru6nO86tXvLI yql5TtVbOFWpnln+drMJpphilIfQ5amOFR0LIUNAsy8rq07k5Gx3RfDQOolQuGk/5Hyh3eDH7JX S68THumFhWhUC779PUMZrHVeQRLy1wz33SprcBdcY1MI6OfNp3L7yXGgdWNcwawcAIQHuYbtr9R t9jWOV4vQIMIhM+8pdtr/QPfUAzkkJ9RuTyQjHKEhDZgV3i/PQZE2Rj1LWA8D/XWU8qyRqXo+lH 0HAgq5MSYPJWLIl0UXzAbuZrcOvqezCJhYCyFzfzAeUzZz245CKuvCZybDrbRUAmi6cKllj1fHL BY/4xtnkCs6CLw6Xj/Ja1IyeVfsA9fqF7NWNzc4LLAsgRmoeYBSgrW1CJEJIrWoga2HdYKIiUU8 1F9HgAtW2d16atoXuKb6A== X-Received: by 2002:a05:622a:420a:b0:50e:5acc:e792 with SMTP id d75a77b69052e-51461befd6emr142886301cf.14.1778186519144; Thu, 07 May 2026 13:41:59 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8b53ca982a1sm242827966d6.38.2026.05.07.13.41.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 13:41:58 -0700 (PDT) Date: Thu, 7 May 2026 15:41:56 -0500 From: Nathan Bossart To: Tom Lane Cc: pgsql-hackers@postgresql.org Subject: Re: small cleanup for s_lock.h Message-ID: References: <369933.1777933007@sss.pgh.pa.us> <532705.1778000169@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="IHFkEDr8CkxIje3R" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --IHFkEDr8CkxIje3R Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, May 05, 2026 at 12:57:10PM -0500, Nathan Bossart wrote: > On Tue, May 05, 2026 at 12:56:09PM -0400, Tom Lane wrote: >> Lastly, I definitely agree now that the file's header comment needs >> some work. Maybe this insight helps you with that? (One thing >> I noticed is that the ending comment about "Equivalent OS-supplied >> mutex routines could be used too" feels pretty obsolete. Maybe >> instead, "Equivalent compiler intrinsics are another popular option".) > > I think it does help, thanks. I'll give it a whirl. Here is a first try. While at it, I removed the note about using "volatile" prior to v9.5, as well as the note about using TAS() in a loop. I couldn't really understand why the latter part needs to be said out loud, so I did some more digging. It was added by commit 7f60b81e and refers to an unsupported platform. At the time, it was apparently normal to use TAS() outside of s_lock.h, but the "NOT part of the API" note above it was added the following year in commit 499abb0c. Two other things I noticed after staring at s_lock.h for a while: * If we're willing to define TAS_SPIN to first do an unlocked test everywhere, we can simplify the ARM and x86 code. Specifically, we can merge the x86 blocks together, and we can remove all but the SPIN_DELAY definition for AArch64. We've thus far been hesistant to add the unlocked test to platforms without evidence of improvements, but I'm a little skeptical that folks have performance-critical workloads on architectures that don't already have it. * Furthermore, do we really need architecture-specific implementations of anything except for SPIN_DELAY()? I suspect that __sync_lock_test_and_set() and __sync_lock_release() work pretty well most of the time, and they've been available in gcc and clang for ~20 years. Perhaps we could even start using the __atomic builtins if available. We've been slowly trying to move away from spinlocks, anyway, and I'm not seeing huge differences in generated code on https://godbolt.org/ for newer compiler versions. Of course, further research and benchmarking would be needed, but I figured I'd at least jot down these thoughts. -- nathan --IHFkEDr8CkxIje3R Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v3-0001-Remove-fallback-declaration-for-tas.patch