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.96) (envelope-from ) id 1wyoX4-003dqd-35 for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Aug 2026 10:37:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wyoX3-007R5G-2V for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Aug 2026 10:37:29 +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.96) (envelope-from ) id 1wyoX3-007R57-1W for pgsql-hackers@lists.postgresql.org; Tue, 25 Aug 2026 10:37:29 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wyoX1-00000001AS9-0Gy1 for pgsql-hackers@lists.postgresql.org; Tue, 25 Aug 2026 10:37:28 +0000 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-8487214ad2bso6092305b3a.1 for ; Tue, 25 Aug 2026 03:37:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787654245; x=1788259045; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:content-type:from:to:cc :subject:date:message-id:reply-to:content-type; bh=iL52F/t3C6dJqAmlP8xoFuqo3ckG3rMlvZUKDJEpmqA=; b=ZsUZxnbdTCBDTc47NRnOpMs6vqZ780X1JyxPOJkxTKnx1BuPsanpoPW2ZtYl05AF28 0wVNw+6MxH3TGimRcZw1lr9DMDoXl6uhjrZsBtSncmfUZQyeB47d3S7+qhiooTcUhZ2D SxFtB0LfsiaC8SGIR/ON1B94iVm6Tnt/NPuNw4IbqAbCLhpRG8nf/1CYYnOz1bvDfhhN dJrR7sErGEUdCkABqF8h914wLD4muk/ZtiGcdz9yq2tRP2QR8wOSo8qNPwET10ZKNCmw dtuUtBZE9vXIhmx3bet+z/sdgcO9xdXZskps0QWyBS8gg+muA6P6TrAOD/4ngL+v+Y2c y+mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787654245; x=1788259045; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:content-type:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=iL52F/t3C6dJqAmlP8xoFuqo3ckG3rMlvZUKDJEpmqA=; b=nuJl/u5M4kNnkUtdg5flXSxyHYtkGqdc6BKSara8gI2KKGNMxcHic0ndT06qz10vvM uZy2Oag42ATcuj2C1xuTfJkMAaS9csDbSNhK5nF7hOXjKnZB1gyM2vSKUfeMFg/qLKw/ R+CLHK9TyX3tU9FRJXaSa+4k8T52B9sFFd2z7NrdQbRCcAc9L5lMnLvY5THKv7fvWtCC ok6GzYZ8N1s6N7ZJ7DJ+x03ZF50bfh6Z7ohEOFFWXka68zJ4cssiUpRi3wPwU4Isv4hy 6xEH3eBTQ0ksXw55Nx+B4D3UTO+UuSo6e2ecyh5s9jG058COdDyo+lqDlqacMUjqH1pF mllQ== X-Forwarded-Encrypted: i=1; AHgh+Rq2s4ypzi/BlHcLJWAhq9gE7r6Iw2aZBOk5bRuuyuYB1G1ONPEmwhIBWr6UJcSNxQNCh9Nzkl9ivafMXktN@lists.postgresql.org X-Gm-Message-State: AFuF++mMiYbxZ6bZHnB3Inj57jKBDOosWW+8YNmR5pMy2BWKJih3T8E7 YIYjRKiBSfBBFUhTBohNO9utSPgY8MqPSl43FegOVcYZOEk/LNqcS40L X-Gm-Gg: AR+sD11yjYmbbpDhUjHWPno7eajT8VJ5t2AYGtdfesXFTWi8lAAJ5Ej/yECUXC2ZI86 I6g/52HYPUS4ss9Mr5AUnEZXBg1vzHQcM2BaCc/buA5fpL9Fu6qkkPJb/psEyUXRJik6G6poEp4 XD9AnLS++EeYViEPZ40pNFO/QXubJiB3pBzdGCmpi1HnZiOCTrJzDousHljwEatLsIN0HdNmJGC qLOpDkPOBXvUIeSPx0uNpCPjVxw/ehJQgZ4suy907AywIqUtNSJAjNdAFeuM2suiuMOhKeOHvF8 cwYvhQTJ2pKm0+zNGc/cUZPSxDIWj2zUpVIFoI3fE6NsPq/Ek2RfcqxfRH5tFLzBLfG7RGgkDvh nl+aBT7LzIXTzVCBF3hfmMNrgZakEOWotsLJEDIjLnVACvvhTiNGW7SNKK0X1uj8u4JuaRBdW8I bsxwNd0DWmfDgYU6lyIsnWYpX9WktpvByzfUE7iAC3As8rM9pqqXC703oU15wJUWf+8jqt4/IF9 FJlCA== X-Received: by 2002:a05:6a21:4d8b:b0:3cd:6f46:aceb with SMTP id adf61e73a8af0-3cd91103da8mr12953169637.8.1787654244617; Tue, 25 Aug 2026 03:37:24 -0700 (PDT) Received: from smtpclient.apple ([128.14.188.156]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-327f91d37d9sm38157286eec.14.2026.08.25.03.37.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Aug 2026 03:37:24 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.700.51.1.1\)) Subject: Re: [PATCH] bufmgr: tighten LWLock:BufferMapping on InvalidateBuffer From: Yuhang Qiu In-Reply-To: Date: Tue, 25 Aug 2026 18:37:11 +0800 Cc: Andres Freund , PostgreSQL Hackers Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Alexandre Felipe X-Mailer: Apple Mail (2.3864.700.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Alexandre, Thanks for sharing the experiments. I have a few concerns. The benchmark runs in a single backend. This mainly measures instruction = and branch overhead. Saving a few nanoseconds here does not necessarily = result in a measurable end-to-end improvement. The patch also adds more interfaces and makes the locking code harder to = use and maintain. Some changes seem to move costs rather than remove them. In 0002, LWLockAcquire is declared as a non-static inline function, = while its external definition is removed, when the compiler does not inline it, = for example with -O0, this whill leave an unresolved LWLockAcquire symbol = and causes a link failure:=20 ```C inline bool LWLockAcquire(LWLock *lock, LWLockMode mode) ``` In 0005, queued is not initialized and is never set to true after = queueing, This can cause repeated queueing, incorrect dequeueing, or prevent the = backend from reaching the normal sleep path: ```C bool queued; if (!queued) { LWLockQueueSelf(lock, mode); continue; } ``` I think it would be more useful to reduce unnecessary LWLock = acquisitions or=20 contention in higher-level code paths, such as buffer mapping and WAL = buffers. For LWLock itself, the important part are atomic operations and = cache-line contention (though there might be no lock contention, but at CPU level, = emmm), wait-list contention, sleep/wakeup mechanism, and fairness... Best Regards, Yuhang Qiu.