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 1q8qbe-0006pX-1O for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Jun 2023 23:05:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q8qbb-0007PA-Nm for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Jun 2023 23:05:47 +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 1q8qbb-0007P0-Cv for pgsql-hackers@lists.postgresql.org; Mon, 12 Jun 2023 23:05:47 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1q8qbY-0020tV-EY for pgsql-hackers@postgresql.org; Mon, 12 Jun 2023 23:05:46 +0000 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1b025d26f4fso37335995ad.1 for ; Mon, 12 Jun 2023 16:05:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686611142; x=1689203142; 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=tGLnWtbAmktDLypgRGCZPcwZgqJb0adyAp8zbMSCkEQ=; b=QUvS3drn4to/RatxZN1AFafiK/eXEcdGEd7sy0ng8ictOvTcLVbkXwdwhN87ibRLzn qg8lzliDCwQ+j+7leg/WqGxukou3mEok4Nhc7Vaj1uD23A+psoQ4dpzu68PqC+H8HOBM CCgVaO+hB2A6kDnLCvy0lQnbhQutuoI8LomMV1vu5KW4xaa7SKuqiBY5Bnc9nBiSaNud TrnuvcHr7SwqPpmgzGr0Cjs/nkLJz3zvy8yhNTcDV5uMg6KcK8MX5Jcnq9cQ/HHvSjMY VoftKRN+JJZSkcf0uug+EZLEERRZGR3bpM9fh8unoGnQ4vn5aGi7MpRPaSEoshEXmnw5 0/+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686611142; x=1689203142; h=in-reply-to: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=tGLnWtbAmktDLypgRGCZPcwZgqJb0adyAp8zbMSCkEQ=; b=ArWE3HsoYfgQJ6HRQbKtrOkCnOG5JQcj21nybYGurEpuoBAzng/LKVURamOlgOBCSD +4le0QP2vEh5XlZnVOPN48416e1X1RcbiKsJ17njLNSMkVF2tXOw9UZXaxAxucaa0xgO cSJEL+9alupGktHpRsT6AfHj2lnRLSP0pYNcFfV22ipM9jQIRoOqYNU9uavX+IwAnXZ5 ma2mUCvPz2zrr2NlcL8eFMCMTkK6ql0cz5g9oTQEe/FLeVmkQFWlXzvqZ8pwmkHwnbHF +IcwOEw0mXARF8PpQmfxFpyJfWJwlRPNLLvSogW5QJiFiEMKxbsydmsVq5PuzpjIC4MW mmDQ== X-Gm-Message-State: AC+VfDzLdOPbvQ882sGzXM9IohQymw4m7VP5YBRDcn+CLtRm0VkQiFSx Dmh/duEuu1daqJqYewNdJpM= X-Google-Smtp-Source: ACHHUZ4bWJ/6VPrGlH7whXy1w21DCtWwc5X718Qp9FqDT9cR9iT6iwSKNmFNAVHYZtf4kmUjP497UQ== X-Received: by 2002:a17:902:8502:b0:1ae:8892:7d27 with SMTP id bj2-20020a170902850200b001ae88927d27mr7918664plb.42.1686611141977; Mon, 12 Jun 2023 16:05:41 -0700 (PDT) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id q16-20020a170902dad000b001ab0669d84csm8762768plx.26.2023.06.12.16.05.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 16:05:41 -0700 (PDT) Date: Mon, 12 Jun 2023 16:05:39 -0700 From: Nathan Bossart To: Michael Paquier Cc: Andres Freund , Robert Haas , John Morris , "pgsql-hackers@postgresql.org" , Stephen Frost Subject: Re: Atomic ops for unlogged LSN Message-ID: <20230612230539.GB178071@nathanxps13> References: <20230524214958.mt6f5xokpumvnrio@awork3.anarazel.de> 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 On Thu, May 25, 2023 at 07:41:21AM +0900, Michael Paquier wrote: > On Wed, May 24, 2023 at 02:49:58PM -0700, Andres Freund wrote: >> So we indeed loose some "barrier strength" - but I think that's fine. For one, >> it's a debugging-only value. Is it? I see uses in GiST indexing (62401db), so it's not immediately obvious to me how it is debugging-only. If it is, then I think this patch ought to clearly document it so that nobody else tries to use it for non-debugging-only stuff. >> But more importantly, I don't see what reordering >> the barrier could prevent - a barrier is useful for things like sequencing two >> memory accesses to happen in the intended order - but unloggedLSN doesn't >> interact with another variable that's accessed within the ControlFileLock >> afaict. > > This stuff is usually tricky enough that I am never completely sure > whether it is fine without reading again README.barrier, which is > where unloggedLSN is saved in the control file under its LWLock. > Something that I find confusing in the patch is that it does not > document the reason why this is OK. My concern would be whether GetFakeLSNForUnloggedRel or CreateCheckPoint might see an old value of unloggedLSN. From the following note in README.barrier, it sounds like this would be a problem even if we ensured full barrier semantics: 3. No ordering guarantees. While memory barriers ensure that any given process performs loads and stores to shared memory in order, they don't guarantee synchronization. In the queue example above, we can use memory barriers to be sure that readers won't see garbage, but there's nothing to say whether a given reader will run before or after a given writer. If this matters in a given situation, some other mechanism must be used instead of or in addition to memory barriers. IIUC we know that shared memory accesses cannot be reordered to precede aquisition or follow release of a spinlock (thanks to 0709b7e), which is why this isn't a problem in the current implementation. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com