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 1kDu4b-0002z8-Ik for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Sep 2020 18:35:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kDu4a-00088u-5u for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Sep 2020 18:35:00 +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 1kDu4Z-00088n-QB for pgsql-hackers@lists.postgresql.org; Thu, 03 Sep 2020 18:34:59 +0000 Received: from mail-qk1-x744.google.com ([2607:f8b0:4864:20::744]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kDu4X-0001ZW-0w for pgsql-hackers@lists.postgresql.org; Thu, 03 Sep 2020 18:34:59 +0000 Received: by mail-qk1-x744.google.com with SMTP id d20so4031336qka.5 for ; Thu, 03 Sep 2020 11:34:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=nFQEAkcr0oQLjk/pUsm8lX6m4ymnJY2GI1HPqKJbpQ0=; b=dXNVtgQ9uAk3MLER8GPZyDGRaaTI0OwbJ7A1zPGtwXYPmKOaE/yIdmIj6DULW7oDBH aNnbdM4GRSCL3uC+LFGVLIFXOb6SSRkt9+Uw3ZRNqpS4rhBDfOENXeOjhBIzKUyTSjLt 4+N0rHTzhsFSIRs/98z3UFOyP3BBNqHlGswFeCHdXKUf/kquT829dhm+q65fnhbagK7+ 2dvZQtzMMByja2cBkcXljLNPl019NFsGSFRZ1IdmSkro5nSw/2xd26D/mA1lyfYXEh/Z raJVo85zMpQmmk8vgGD/9aFi3MTW3/E+lOlYFgRO0gjNmVLsNsCEYbyOS2iwc+hJVHqS ProQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=nFQEAkcr0oQLjk/pUsm8lX6m4ymnJY2GI1HPqKJbpQ0=; b=TqpDITBVBL0NUjIFEoP0wsFt/JJj0//7V6at/KXjUUcU7CPvSU2JyPcWLc4aQyWJLV P6Y0ThST+I0l7sKFrD3F44uoQkfU2vp4k2Jzbi7n6WpgN/12jRoqIzrkNcEU7HqgDpNl ig3hqE1esnDV7ztq9SFLOm5xCPBqwfCj/ZB9FOHesiWaG54gw9phpuTGcBtSrr5mgSp+ PvpwM24QNhdoCKkv7dBOj6ibhWIZrXBRx0Yhv+tB0JdjjvTjoTq8wXCqk4YKI/YNz38P GkpovvBdmMx0FKwNvSTMTqoTrIcLBDm6k823aEaLJn6opji7ZnE2Ko50Qah6Abe52iAG /1CQ== X-Gm-Message-State: AOAM530OKKoTtM8UW+ODS275Nov/kplJ6ZVOVJyEyoZqGH/p6cbymMiJ vVD6rDQCXC/h0xHwis/fNN8mklMMD9P8VA== X-Google-Smtp-Source: ABdhPJxDfSQk2PJOaEHxTWz3mF+hOi9Us21LVKgKC/SrunoTVgv8VTLM/IyqbXPE2o7rG5TTm0RC/A== X-Received: by 2002:a05:620a:554:: with SMTP id o20mr4559108qko.205.1599158094575; Thu, 03 Sep 2020 11:34:54 -0700 (PDT) Received: from perhan.alvh.no-ip.org ([190.95.19.47]) by smtp.gmail.com with ESMTPSA id l64sm2783284qkc.21.2020.09.03.11.34.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 11:34:53 -0700 (PDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 236E22A154F; Thu, 3 Sep 2020 14:34:52 -0400 (-04) Date: Thu, 3 Sep 2020 14:34:52 -0400 From: Alvaro Herrera To: Andres Freund Cc: pgsql-hackers@lists.postgresql.org, Jaime Casanova Subject: Re: LogwrtResult contended spinlock Message-ID: <20200903183452.GA10634@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Looking at patterns like this if (XLogCtl->LogwrtRqst.Write < EndPos) XLogCtl->LogwrtRqst.Write = EndPos; It seems possible to implement with do { XLogRecPtr currwrite; currwrite = pg_atomic_read_u64(LogwrtRqst.Write); if (currwrite > EndPos) break; // already done by somebody else if (pg_atomic_compare_exchange_u64(LogwrtRqst.Write, currwrite, EndPos)) break; // successfully updated } while (true); This assumes that LogwrtRqst.Write never goes backwards, so it doesn't seem good material for a general routine. This *seems* correct to me, though this is muddy territory to me. Also, are there better ways to go about this? -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services