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 1whBF1-0003eS-1e for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jul 2026 19:13:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1whBEz-002Ibp-2s for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jul 2026 19:13:58 +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.96) (envelope-from ) id 1whBEz-002Ibg-1u for pgsql-hackers@lists.postgresql.org; Tue, 07 Jul 2026 19:13:58 +0000 Received: from lahtoruutu.iki.fi ([185.185.170.37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1whBEy-0000000021q-06V9 for pgsql-hackers@postgresql.org; Tue, 07 Jul 2026 19:13:57 +0000 Received: from [10.0.2.15] (unknown [130.41.208.2]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4gvrVj2Q9nz49Px6; Tue, 07 Jul 2026 22:13:49 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1783451629; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8A7dWUNwx051VKSQqi3d0aZUTVb0bFSuGRrM7nYjvSw=; b=COBtffuQcJkSs8l0aFCzTdh+IuVtmgEh7CT3xmvGmvMb98RGAYTeTBxdG9BT5A7m1aeoxB kWSepJvvs/zHJ0I807xHgAmcYWs6PQgp3fpBJfEVOaOT9ttGecQSi47qjf/hZgheFxiY6k evm0PbxH7BDJYZnvxN/DVtBKsygXKeayN9Yiph+sw7XZ/3wm7nAZ+u8asZVGMXBF6KRIpO HTvqsopsgTHm0tZ1lJw5uYj7UtdqHq6BrFrmRhTfMTsrH34RiGKJzvzhJRgoizd2Cwdttv 5lq6INQwN+vpAwrRVp9PzsbaQFgzC24X/hHcYC1zm9BujnbFR/GvDg/bh1GINw== ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=lahtoruutu; cv=none; t=1783451629; b=tsEfKW/jnl6wxQg6cAxvExWLpzL6zzy4YwThIhVWyoe49cuCeb12yGp/t3P6PRr4v5aBFP 6IvPMvLlsKDWKwXFkoDlEzKq4/d6vAiovxmyxO5tTX2pc0cuz0rkWy5U1GlpQYed1vxgMs +WgwPM8h8mMHElRABmapT+1AHB/LZI3bJFarcsbED2l2HXPIJB5zYC8gGrnqAR+DUEP78H 3014g4pxm6pPUzgwUWyXM5hzFHvIoTloL1Ha8rBo7TTkeZhf4DB9mcj6B5HS9C/qtIRMO3 tKbbBhOoSMWr0pvBIzgp+VTYixXUCXLHZuzR5FYHFSvGPopT6fxHa0jBaOZUXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1783451629; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8A7dWUNwx051VKSQqi3d0aZUTVb0bFSuGRrM7nYjvSw=; b=dyC3bzwAyRX3sQiH6VmYjXxfR/r1bW0LCfcdKHmqfUKgSpAuH9ZCD1PCpfIEDBIOsaeHFj rhLz6mk20Ydc91Mt5QC0jOLFzKEqYGnembCGPPJ9lRL/vFYvF3JYCPoEFbrtFSTTmYcHWv 08MrTnxc+QeWcHTG3GkSnmLigB7WvFcmzCglzm9BN3G3fn8DZ7nYNCH8JRwfxEyu0i9nHa Iv33LM7R0/0ZXDRvGGG+LGQz4DY1aJa3DWc6GaT7thzsjbE0CW/zyM+3XouVnNY8jf7JXn v4KmU2/RB+W/PD9huPRT1YHL3a+MuKMb9cMM3MVYmIObphHgcPXs915YNOcmJw== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi Message-ID: Date: Tue, 7 Jul 2026 22:13:48 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Restructured Shared Buffer Hash Table To: Dhruv Aron , pgsql-hackers@postgresql.org Cc: haoyu.huang.68@gmail.com References: Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 07/07/2026 21:41, Dhruv Aron wrote: > At Databricks, we’ve found that the existing dynahash table structure is > leaving performance gains on the table when it comes to shared buffer > lookups: the multi-level structure (directory, segment, bucket chain, > freelist) appears excessive for the shared buffers and could be > simplified to boost performance and lower memory overhead. As such, we > are proposing a specialized hash table just for this purpose and would > appreciate feedback on this approach. Yeah, the dynahash has features that we just don't need in the buffer lookup table... The indirection with the directory is actually unnecessary for all the shared memory hash tables, since none of them can be resized. I've wondered if we should try to eliminate that from dynahash for all shmem hash tables. But the buffer lookup table is very performance-critical, so if there are any performance gains to be had, it's indeed probably worthwhile to have a separate implementation just for it. > bufmgr.c also changed slightly to prevent a race condition. Hmm, we're now holding the buffer header lock much longer than before, in InvalidateBuffer(). It's a spinlock, it really should not be held for more than a few instructions. BufTableDelete() is very fast in the new implementation, but still. Could we perhaps do some of BufTableDelete()'s work ahead of time, before we acquire the buffer header lock? Or maybe it's not a problem, in which case some kind of a worst case scenario benchmark to show that would be nice. Maybe test how it behaves when you have a lot of hash collisions, I think that'd make BufTableDelete() more expensive. > My testing > (helper script also attached) indicates that all three standard hash > table operations (insert, lookup, and delete) generally execute > significantly faster than the existing PG18 dynahash counterparts: Nice! I wonder how big the impact is with real world workloads. I've certainly seen the buffer table lookups consume a fair share of CPU time, so I'd assume that it shows up. Another data point: unpatched master, with shared_buffers='128 MB': postgres=# select * from pg_shmem_allocations where name like 'Shared Buffer%' order by name ; name | off | size | allocated_size ----------------------------+-----------+--------+---------------- Shared Buffer Lookup Table | 141607040 | 926000 | 926108 (1 row) With this patch: postgres=# select * from pg_shmem_allocations where name like 'Shared Buffer%' order by name ; name | off | size | allocated_size ------------------------------+-----------+--------+---------------- Shared Buffer Lookup Buckets | 141607040 | 65536 | 65644 Shared Buffer Lookup Entries | 141672576 | 393216 | 393216 (2 rows) So the new hash table takes much less memory. That's nice because you can then fit more in CPU caches. - Heikki