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 1r0Csu-004AWz-Vg for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Nov 2023 03:36:12 +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 1r0Cst-0046tw-8b for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Nov 2023 03:36:11 +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.94.2) (envelope-from ) id 1r0Css-0046to-T0 for pgsql-hackers@lists.postgresql.org; Tue, 07 Nov 2023 03:36:10 +0000 Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r0Csk-0056mB-EG for pgsql-hackers@postgresql.org; Tue, 07 Nov 2023 03:36:10 +0000 Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-7a68d1698adso135248439f.1 for ; Mon, 06 Nov 2023 19:36:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699328160; x=1699932960; darn=postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=Q1FXp32k71DS8SztpGj21drJ7cYtkNFUF+rX6BkNmhk=; b=EVL0BygBWucTN0NGzbPd3lvPXBbakcCl3Y1grLdQQV/efUNpCrvGptDTIiyWfQ7WFm V4Z0SkjuVkxflKTXD/EAZQbNCKap3ccmQbJtkxYaQGcN//PGA8j3RWmmb+/CZ/osROdO hBa/85cCx+kXlHCDLd8vHCg8G0DfSkeXlHaGjxy61thqEjHC0ZAbFHgsaUr1Fvg0bRLw Khsjs/FHDgmOsu4Z5UoEPnzhQlrp/7ban1b/gr/R/7dIQ/BqxA3GZUuYcygZZW6JoSPb y0VRxGJk8dTFU6otExq8l4Pqldo43Pj4zGJZbvsZffrSlAjSZhhD2B5aTNUTfAwzc1Qm ibzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699328160; x=1699932960; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Q1FXp32k71DS8SztpGj21drJ7cYtkNFUF+rX6BkNmhk=; b=CUvmAJ/hkRhbaHXT+Yb9SUzKAqDidjw1zvpd7HW+aIamvCAKxtVjwXbfZkJsrQTZGi AUtd2BWO/COqODHLxv0FwvmhHFuVGzmgpidobfkqNlRrTLr2bq4G6zEB0n+Tnri+pUGl kh9D6FsvjokRK8P08nahs1jsVyfWLsykIq62InzQ5/y3LCtgAnnK+auZ4oJ3fdHVeGvc ggMneXBodTMH82HjJqTvEpGpKaS5S9KV8m4jP6uvyIr/M3ac3PBDUD4ot/cxwNCTA1T6 6Nn1qFsmeAzNTJJPxtB4mEJAvscLy5a7Nt2Ns6B9MeRaJKCHtpYnDOpJ3LkVu02rlqwc 3B4g== X-Gm-Message-State: AOJu0Yyy+QCzsCmNYo4I3JyolLzWTNysFoIVMhNaXFVq5enoIkm3Id7F u3G6OjrAfZxIoijUxjR5OsA= X-Google-Smtp-Source: AGHT+IEEVt1MBbZRqLkT2urL6Az+Jb7JXPHwSjQB2wnj8PmtgdCAAXzA1aiyuIk/yzSte0pPeBmMPg== X-Received: by 2002:a6b:f419:0:b0:7a6:793d:2079 with SMTP id i25-20020a6bf419000000b007a6793d2079mr1324416iog.1.1699328160251; Mon, 06 Nov 2023 19:36:00 -0800 (PST) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id m18-20020a6bf312000000b00786fd8e764bsm2711067ioh.0.2023.11.06.19.35.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 19:35:59 -0800 (PST) Date: Mon, 6 Nov 2023 21:35:58 -0600 From: Nathan Bossart To: John Morris Cc: Bharath Rupireddy , Andres Freund , Stephen Frost , Michael Paquier , Robert Haas , "pgsql-hackers@postgresql.org" Subject: Re: Atomic ops for unlogged LSN Message-ID: <20231107033558.GC729644@nathanxps13> References: <20231026203433.GA1088329@nathanxps13> <20231102034006.GA85609@nathanxps13> <20231106203350.GA598180@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Nov 07, 2023 at 12:57:32AM +0000, John Morris wrote: > I incorporated your suggestions and added a few more. The changes are > mainly related to catching potential errors if some basic assumptions > aren’t met. Hm. Could we move that to a separate patch? We've lived without these extra checks for a very long time, and I'm not aware of any related issues, so I'm not sure it's worth the added complexity. And IMO it'd be better to keep it separate from the initial atomics conversion, anyway. > I found the comment about cache coherency a bit confusing. We are dealing > with a single address, so there should be no memory ordering or coherency > issues. (Did I misunderstand?) I see it more as a race condition. Rather > than merely explaining why it shouldn’t happen, the new version verifies > the assumptions and throws an Assert() if something goes wrong. I was thinking of the comment for pg_atomic_read_u32() that I cited earlier [0]. This comment also notes that pg_atomic_read_u32/64() has no barrier semantics. My interpretation of that comment is that these functions provide no guarantee that the value returned is the most up-to-date value. But my interpretation could be wrong, and maybe this is meant to highlight that the value might change before we can use the return value in a compare/exchange or something. I spent a little time earlier today reviewing the various underlying implementations, but apparently I need to spend some more time looking at those... [0] https://postgr.es/m/20231102034006.GA85609%40nathanxps13 -- Nathan Bossart Amazon Web Services: https://aws.amazon.com