Fix PrivateRefCount hash table key size
Hi hackers,
While working on [1]/messages/by-id/aS2b3LoUypW1/Gdz@ip-10-97-1-34.eu-west-3.compute.internal, I noticed that there is a type mismatch when computing
the key size for the PrivateRefCount hash table. Indeed, the first
PrivateRefCountEntry member type is Buffer (int), so the keysize should be
sizeof(Buffer) and not sizeof(int32).
PFA attached a patch to fix it.
It has been kind of automatically detected while working on [1]/messages/by-id/aS2b3LoUypW1/Gdz@ip-10-97-1-34.eu-west-3.compute.internal, so I'm pretty
confident there are no other type mismatches for hash table key size.
Note that this is exactly the kind of issue that the macro proposed in [1]/messages/by-id/aS2b3LoUypW1/Gdz@ip-10-97-1-34.eu-west-3.compute.internal would
avoid.
[1]: /messages/by-id/aS2b3LoUypW1/Gdz@ip-10-97-1-34.eu-west-3.compute.internal
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
Attachments:
v1-0001-Fix-PrivateRefCount-hash-table-key-size.patchtext/x-diff; charset=us-asciiDownload
From 5cc49008cbd1876878d51fd7a1331e2358038148 Mon Sep 17 00:00:00 2001
From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Date: Tue, 2 Dec 2025 14:07:45 +0000
Subject: [PATCH v1] Fix PrivateRefCount hash table key size
The first PrivateRefCountEntry member is Buffer (int), so the keysize should
be sizeof(Buffer) and not sizeof(int32).
---
src/backend/storage/buffer/bufmgr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
100.0% src/backend/storage/buffer/
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index f373cead95f..b6cde7e3803 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -4019,7 +4019,7 @@ InitBufferManagerAccess(void)
memset(&PrivateRefCountArray, 0, sizeof(PrivateRefCountArray));
- hash_ctl.keysize = sizeof(int32);
+ hash_ctl.keysize = sizeof(Buffer);
hash_ctl.entrysize = sizeof(PrivateRefCountEntry);
PrivateRefCountHash = hash_create("PrivateRefCount", 100, &hash_ctl,
--
2.34.1
On Tue, Dec 02, 2025 at 02:43:25PM +0000, Bertrand Drouvot wrote:
- hash_ctl.keysize = sizeof(int32); + hash_ctl.keysize = sizeof(Buffer); hash_ctl.entrysize = sizeof(PrivateRefCountEntry);
LGTM. Appears to be a minor oversight in commit 4b4b680c3d, but it's of no
consequence because Buffer has been a signed 32-bit integer since commit
bdadc9bf1c. Will go commit this.
--
nathan