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.94.2) (envelope-from ) id 1rdqMy-007pFJ-2a for pgsql-hackers@arkaria.postgresql.org; Sat, 24 Feb 2024 11:39:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rdqMw-004eL1-0r for pgsql-hackers@arkaria.postgresql.org; Sat, 24 Feb 2024 11:39:02 +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.94.2) (envelope-from ) id 1rdqMu-004eKD-Dl for pgsql-hackers@lists.postgresql.org; Sat, 24 Feb 2024 11:39:02 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rdqMp-000kx7-Va for pgsql-hackers@postgresql.org; Sat, 24 Feb 2024 11:38:59 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id C9D545C005F; Sat, 24 Feb 2024 06:38:54 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sat, 24 Feb 2024 06:38:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1708774734; x=1708861134; bh=w5+qWVULY2cx07Cx9qOBVFmhcxWTxG5UzyprQR/04XI=; b= FGzEDdJY1tHRnGyOWvk/KlK5xPNfae+6nTY3jQj36Ao//FWxBySG2qFyTk+KB9yf 37iAF1vxyycqhWx14P0JicPx7cvuC9tlf86qQXwqy9Fxp2/A0MAaqZjVywjCD1j2 vG1M5PO2HG16LcSLPsUi5TD9YbJIPy5byQYXwGtPhn45rFtnct3lYG/5CsinjBMK AhY25xsHI5eKwi0XJMWIpTAa6z459OyyF/ucrQ6wSVBpVCOPgpAvhfr7LqAIlak8 XolXNpoO5NSTk5EayJquzZdSpzHk371WPJXr3LU3VKQv8knse6z0qJd+w0AxiNBI 8uPFlIxoSRpZiUomMGfBJw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1708774734; x= 1708861134; bh=w5+qWVULY2cx07Cx9qOBVFmhcxWTxG5UzyprQR/04XI=; b=I FWOO9d19A+/ulJ1F3qOqoNOLSF1RqcjL7US0ahTWqoyrK4LfKntEZEV6iOZJFGS5 EmGmSAWNRZOrW1xrm5rZ+tkVem7qrNyetQjSzTmRjgD8Y+pSgDSPJLo5SHE1sgo0 ns+rcEST+01Jk+hOsGfFj+dPFfTrXDDo+4x9kHHqZ1lpYu61HcYdRE2D7KjJm8J3 Tk6fBf7FhlbWiNKcxe+MrVPLeXUQTweF/dxxJ3FKkaykuFLPlh7MYwxOd6nW3s7H JsLvjfxW92bT/6NTJwLkyl1WWvGb2kflaXoPefoA81BVUDYjJ9AJsTjKaTAqhkXD g7EmLIPmi2yG9WYjYjRnA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfeekgdeftdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtugfgjgesthekredttddtudenucfhrhhomheptehnughr vghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrf grthhtvghrnhepuddtieegleejheeujeeiveegueelhfekleeuffdukeduleduffehfffg teeivefhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh eprghnughrvghssegrnhgrrhgriigvlhdruggv X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 24 Feb 2024 06:38:53 -0500 (EST) Date: Fri, 23 Feb 2024 17:30:26 -0800 From: Andres Freund To: Jeff Davis Cc: Nathan Bossart , Bharath Rupireddy , pgsql-hackers@postgresql.org Subject: Re: locked reads for atomics Message-ID: <20240224013026.t4whp7oqsrfengtd@alap3.anarazel.de> References: <20231110205128.GB1315705@nathanxps13> <20231110231150.fjm77gup2i7xu6hc@alap3.anarazel.de> <20231111023813.GB1408159@nathanxps13> <20231111024839.op2d2id33x777mll@alap3.anarazel.de> <20231111025529.GA1409540@nathanxps13> <20231127210030.GA140335@nathanxps13> <20240223161758.GA1697194@nathanxps13> <274e5925684e71b0df4f7c0f473b8ce6fc6c382b.camel@j-davis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <274e5925684e71b0df4f7c0f473b8ce6fc6c382b.camel@j-davis.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2024-02-23 10:25:00 -0800, Jeff Davis wrote: > On Fri, 2024-02-23 at 10:17 -0600, Nathan Bossart wrote: > > The idea is > > to provide an easy way to remove spinlocks, etc. and use atomics for > > less > > performance-sensitive stuff.  The implementations are intended to be > > relatively inexpensive and might continue to improve in the future, > > but the > > functions are primarily meant to help reason about correctness. > > To be clear: > > x = pg_atomic_[read|write]_membarrier_u64(&v); > > is semantically equivalent to: > > pg_memory_barrier(); > x = pg_atomic_[read|write]_u64(&v); > pg_memory_barrier(); > ? > > If so, that does seem more convenient. Kinda. Semantically I think that's correct, however it doesn't commonly make sense to have both those memory barriers, so you wouldn't really write code like that and thus comparing on the basis of convenience doesn't quite seem right. Rather than convenience, I think performance and simplicity are better arguments. If you're going to execute a read and then a memory barrier, it's going to be faster to just do a single atomic operation. And it's a bit simpler to analyze on which "side" of the read/write the barrier is needed. Greetings, Andres Freund