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 1vt6Zm-003035-0p for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Feb 2026 16:08:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vt6Zl-004GKd-0S for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Feb 2026 16:08:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vt6Zk-004GKV-2i for pgsql-hackers@lists.postgresql.org; Thu, 19 Feb 2026 16:08:24 +0000 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vt6Zh-000000009gs-4B7f for pgsql-hackers@postgresql.org; Thu, 19 Feb 2026 16:08:23 +0000 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-45f171cb842so774710b6e.1 for ; Thu, 19 Feb 2026 08:08:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771517303; x=1772122103; 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=mOUzzddFQ6YZhdIOj/NzZ/uJgBPYIE+k9gEZD+QnPjs=; b=Ngzf+H9MV/J33pvFLPwK1CUUBCszKdxrDeEOMwXGUI4LDVR9ZTcEDwV/d3YzAfdmjt zf8dEU/8TswSSynRIrfDFfmYcgs9pGkCO+Nf0LTFb1ythgOaCH5whYHDr2le2IlL4yW5 EJTucF58+XUoE6QgNXI4e2Lc6Y6ILQeo4d/TsWdeT1Lb5tIhepQc2BygB2gefkyVw3TP qSEZyc7xAZ3p4MQ+23BVp/DTUdT4DLpQ9PwQPNw6lTSpGe40k9O7XM1AEkbDJFxEwd6L 5YnT43oUe1RxBeMO6efpn6Mr2Ibz8D/XS+xQcNun5SBCgyUhXgv8DYgLamAQyKmEeP4C Ev1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771517303; x=1772122103; 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=mOUzzddFQ6YZhdIOj/NzZ/uJgBPYIE+k9gEZD+QnPjs=; b=CdvJS41Lp9WIhQUWdXoaIXgcAyBj/ery7XSEEsdrywCjJNtvNv28zkX9p8zHNSPSU1 pX7wPFsfdJBDyd4Vbijd3ZjfO+1+BTYY54cxy6Kxo+dkA2ItgHYYxs3jlQW8bFWT3Sh6 bfr33hzHO191byku4T6zG4Nibe2lQr9gX4uaQu9qZZxys+vFUbVbP0EYISPdupmsDovH GB8Chkze5SEtaymYT+X/VOI+Fb4zGvl9Q09cOotj6Lz//QYIP59dpqCiKZS9dTOW8eOD ovknLWN9FFQplfS3dj9GpgnAp4Zf0qC+Qip6gmYGlk5zZj1BMgNNgNXRICM9cVFkUjEU bT2A== X-Forwarded-Encrypted: i=1; AJvYcCVU50ZIYnjGuVzZPbklBiCGwuvdKrg5/Zjc8pl8ArzWAGpTq1mcdAjepg/mNGTYJ1DMe/aeaDjTwd92vfQc@postgresql.org X-Gm-Message-State: AOJu0YzlSJvrloSS5ZdlWDVz/0qkglXq62A9Maovh6Q+V5lLJV9QrqCm MzIa8prfwACufcwhIWslSeeLRE/MvckpdWCTusVPiFHCvK7buHM6XOGubklXWw== X-Gm-Gg: AZuq6aJw4Pm+55lfwMGrTPP/lOdjxsacd9lnv2TC8NU/291HeH9ETWfqQ2+nUdkOPXn 947zkZ2P+eC51tm15nRgQivHcKbEhmkJI6Hoh0FhWf0sEAuVkFuUysvaKOgKlke84CmeWoPaaLG 3KKzVaDUuQygCUWAd5y92sMrLiYmbxhIeQaRjDaHEc8153kZ+6u6PZ9gYLeYdHZ7LsvYpEC1rSI +9pnhL4s4ewxZkXvNe7knYn80pmmkLWRGJWUxacxWGAFT0vo7oWcY6QI9o2vixp0PAf09HTvOGp v6tcrAM0V4heh1e5y+AjESORmngnL8jEmlxzWNshgu09dpMq6uxvW82iOgaVZo8E6cLbE3ywpAI qgU+nCzb+r/NzuNGXOrB7Mn28ZArbbJECkwlOScvRXijmHbUaU3ix9SO0OTSmJEmnevEvIjIn9s KI1T3C046RVYHDVriD6lOt554XSyMp6BJi+lZ1FRoURjowY1hraKFSPhEWYgbR2JHzVYXHsyQHl PPPKUwNLD8iopnn8ZR9NQ== X-Received: by 2002:a05:6808:308b:b0:450:d4b5:3527 with SMTP id 5614622812f47-4642761c69cmr1135878b6e.24.1771517302481; Thu, 19 Feb 2026 08:08:22 -0800 (PST) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-40eaeeab492sm24617665fac.5.2026.02.19.08.08.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Feb 2026 08:08:22 -0800 (PST) Date: Thu, 19 Feb 2026 10:08:20 -0600 From: Nathan Bossart To: Andres Freund Cc: Heikki Linnakangas , "pgsql-hackers@postgresql.org" Subject: Re: convert SpinLock* macros to static inline functions Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Thanks for looking. On Wed, Feb 18, 2026 at 04:23:28PM -0500, Andres Freund wrote: > Not quite as sure it's the right thing to remove it from SpinLockAcquire() > though. I think removing it more widely would likely cause issues, e.g. if you > removed it from s_lock(), the compiler would be in its right to just turn: > > int > s_lock(volatile slock_t *lock, const char *file, int line, const char *func) > ... > while (TAS_SPIN(lock)) > { > perform_spin_delay(&delayStatus); > } > ... > > into > ... > if (*lock) > { > while (true) > perform_spin_delay(&delayStatus); > } > else > TAS(lock); > ... > > as without the volatile, or a compiler barrier, the compiler can assume that > nothing will change the the value of *lock (at least theoretically, if it can > prove that perform_spin_delay() doesn't change the value of *lock). This crossed my mind, but I couldn't see how it could introduce any issues that don't already exist. Both tas() and s_lock() have the lock parameter marked as volatile, and S_LOCK is often expanded into functions where the lock variable is not marked volatile. Why would those existing cases not be subject to this problem but the static inline function would? And why would marking SpinLockAcquire()'s lock parameter volatile fix it if doing so for tas() and s_lock() doesn't? FWIW I don't see any changes to the code generated for s_lock() with these patches, although I only looked on a couple of machines. Perhaps it's still worth doing out of an abundance of caution, or maybe I am missing something subtle about the liberties that compilers take in this area... -- nathan