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 1qyOZ4-0087Jv-3U for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Nov 2023 03:40:14 +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 1qyOZ2-00AmzI-Et for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Nov 2023 03:40:12 +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 1qyOZ2-00Amz9-5Z for pgsql-hackers@lists.postgresql.org; Thu, 02 Nov 2023 03:40:12 +0000 Received: from mail-il1-x12e.google.com ([2607:f8b0:4864:20::12e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qyOYz-003Xrb-Lc for pgsql-hackers@postgresql.org; Thu, 02 Nov 2023 03:40:10 +0000 Received: by mail-il1-x12e.google.com with SMTP id e9e14a558f8ab-359381980f7so2454295ab.2 for ; Wed, 01 Nov 2023 20:40:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698896409; x=1699501209; 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=Ftsyflk/B9nnONV1pgNS7I/Fx75jUzUZTRNDo1Y8dRE=; b=XMhzHLvF2ig1XIYKdmx6GNlOLfaFeV2Gcv+B/O/tQiymCoN8fZTfghuHC3heZgrLnc UNDGatGpXycTY21t9cz4N0okARq4gBNc2UQapZMwHwrzGUfI/SvlsSYmscoXbBXERBkM EpE1eKibewtfxCLHoDN0AF82BqCBvCkJj49KbkyNYU0QSSpgz27lpFzSz4HN981dHbu8 5BbZqnfNe2CITqMKkVQtql0jxs5qK6HXWfHmLrA+qTdVCVVZKhQZDecbUrgG7O+b+6bv Rxn3ra+N+gUaOAs6U1qM84lmAXZ8STnM/j0lsHOd2KLWYjGIMBmLLyHNanuoN18W1c16 1o7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698896409; x=1699501209; 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=Ftsyflk/B9nnONV1pgNS7I/Fx75jUzUZTRNDo1Y8dRE=; b=JyamPE1bsKS9cmytiUCdO5XraD5qOqPtb11JMrQvJcC4c6Xo7oyMxsi1GdTY4Y6gWl nQSbDNcH0gMKC+VNiGXMqmnA4bMAQCKh44klmEWDG6r664ops5ATCPqgfzDbaemip1+/ kvn8caKab+4xGGgiKYmT84RdoWzh/oaHNLSxpGhRPQ1CxpoxfVNFYiX2a8h92CnzMEmC 2d7vvliybDSpKHM4Vrdwl1MQvuouZ7im5pVSpMdCxRRDDekJbYGge3Fv/MIz33L1yaYt VlqAwi9baypPBnScOZGSMum1dVk18NfkOFEDWBcZIWzSMM77mdV4VuBQcdYdov6kU/U1 805w== X-Gm-Message-State: AOJu0YxpZZhNHOYyZSiiU0zvCTLaJMFgkhLOteaHFvJIhET1OJaWbRuO ZTyJ++9luSneSHhd31JeQ2w= X-Google-Smtp-Source: AGHT+IEghAwcZxWzmCYgkWmW8qWsvdKpQvr9e7xN2LGvtFEcfxB9ACXMI+U7NXcgVjue3iePC77/oQ== X-Received: by 2002:a05:6e02:11:b0:359:4f85:b215 with SMTP id bb17-20020a056e02001100b003594f85b215mr1714252ilb.31.1698896408696; Wed, 01 Nov 2023 20:40:08 -0700 (PDT) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id l13-20020a92280d000000b00357fa6896f2sm926605ilf.59.2023.11.01.20.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 20:40:08 -0700 (PDT) Date: Wed, 1 Nov 2023 22:40:06 -0500 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: <20231102034006.GA85609@nathanxps13> References: <20231026203433.GA1088329@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 Wed, Nov 01, 2023 at 09:15:20PM +0000, John Morris wrote: > This is a rebased version . Even though I labelled it “v3”, there should be no changes from “v2”. Thanks. I think this is almost ready, but I have to harp on the pg_atomic_read_u64() business once more. The relevant comment in atomics.h has this note: * The read is guaranteed to return a value as it has been written by this or * another process at some point in the past. There's however no cache * coherency interaction guaranteeing the value hasn't since been written to * again. However unlikely, this seems to suggest that CreateCheckPoint() could see an old value with your patch. Out of an abundance of caution, I'd recommend changing this to pg_atomic_compare_exchange_u64() like pg_atomic_read_u64_impl() does in generic.h. @@ -4635,7 +4629,6 @@ XLOGShmemInit(void) SpinLockInit(&XLogCtl->Insert.insertpos_lck); SpinLockInit(&XLogCtl->info_lck); - SpinLockInit(&XLogCtl->ulsn_lck); } Shouldn't we do the pg_atomic_init_u64() here? We can still set the initial value in StartupXLOG(), but it might be safer to initialize the variable where we are initializing the other shared memory stuff. Since this isn't a tremendously performance-sensitive area, IMHO we should code defensively to eliminate any doubts about correctness and to make it easier to reason about. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com