Re: SLRU optimization - configurable buffer pool and partitioning the SLRU lock
Dilip Kumar <dilipbalaut@gmail.com>
From: Dilip Kumar <dilipbalaut@gmail.com>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2023-11-03T05:28:43Z
Lists: pgsql-hackers
Attachments
- v4-0005-Ensure-slru-buffer-slots-are-in-multiple-of-numbe.patch (application/octet-stream) patch v4-0005
- v4-0001-Make-all-SLRU-buffer-sizes-configurable.patch (application/octet-stream) patch v4-0001
- v4-0003-Partition-wise-slru-locks.patch (application/octet-stream) patch v4-0003
- v4-0002-Add-a-buffer-mapping-table-for-SLRUs.patch (application/octet-stream) patch v4-0002
- v4-0004-Merge-partition-locks-array-with-buffer-locks-arr.patch (application/octet-stream) patch v4-0004
On Mon, Oct 30, 2023 at 11:50 AM Dilip Kumar <dilipbalaut@gmail.com> wrote: > Based on some offlist discussions with Alvaro and Robert in separate conversations, I and Alvaro we came to the same point if a user sets a very high value for the number of slots (say 1GB) then the number of slots in each bank will be 1024 (considering max number of bank 128) and if we continue the sequence search for finding the buffer for the page then that could be costly in such cases. But later in one of the conversations with Robert, I realized that we can have this bank-wise lock approach along with the partitioned hash table. So the idea is, that we will use the buffer mapping hash table something like Thoams used in one of his patches [1], but instead of a normal hash table, we will use the partitioned hash table. The SLRU buffer pool is still divided as we have done in the bank-wise approach and there will be separate locks for each slot range. So now we get the benefit of both approaches 1) By having a mapping hash we can avoid the sequence search 2) By dividing the buffer pool into banks and keeping the victim buffer search within those banks we avoid locking all the partitions during victim buffer search 3) And we can also maintain a bank-wise LRU counter so that we avoid contention on a single variable as we have discussed in my first email of this thread. Please find the updated patch set details and patches attached to the email. [1] 0001-Make-all-SLRU-buffer-sizes-configurable: This is the same patch as the previous patch set [2] 0002-Add-a-buffer-mapping-table-for-SLRUs: Patch to introduce buffer mapping hash table [3] 0003-Partition-wise-slru-locks: Partition the hash table and also introduce partition-wise locks: this is a merge of 0003 and 0004 from the previous patch set but instead of bank-wise locks it has partition-wise locks and LRU counter. [4] 0004-Merge-partition-locks-array-with-buffer-locks-array: merging buffer locks and bank locks in the same array so that the bank-wise LRU counter does not fetch the next cache line in a hot function SlruRecentlyUsed()(same as 0005 from the previous patch set) [5] 0005-Ensure-slru-buffer-slots-are-in-multiple-of-number-of: Ensure that the number of slots is in multiple of the number of banks With this approach, I have also made some changes where the number of banks is constant (i.e. 8) so that some of the computations are easy. I think with a buffer mapping hash table we should not have much problem in keeping this fixed as with very extreme configuration and very high numbers of slots also we do not have performance problems as we are not doing sequence search because of buffer mapping hash and if the number of slots is set so high then the victim buffer search also should not be frequent so we should not be worried about sequence search within a bank for victim buffer search. I have also changed the default value of the number of slots to 64 and the minimum value to 16 I think this is a reasonable default value because the existing values are too low considering the modern hardware and these parameters is configurable so user can set it to low value if running with very low memory. [1] https://www.postgresql.org/message-id/CA%2BhUKGLCLDtgDj2Xsf0uBk5WXDCeHxBDDJPsyY7m65Fde-%3Dpyg%40mail.gmail.com -- Regards, Dilip Kumar EnterpriseDB: http://www.enterprisedb.com
Commits
-
Fix zeroing of pg_serial page without SLRU bank lock
- be2f07310063 17.0 landed
-
Fix misspelled assertions
- 0d3a71d0c8a7 17.0 landed
-
GUC table: Add description to computed variables
- 30b8d6e4ce11 17.0 landed
-
Improve performance of subsystems on top of SLRU
- 53c2a97a9266 17.0 landed
-
Rename SLRU elements in view pg_stat_slru
- bcdfa5f2e2f2 17.0 landed
-
Use atomic access for SlruShared->latest_page_number
- d172b717c6f4 17.0 landed
-
Split use of SerialSLRULock, creating SerialControlLock
- 7b745d85b80d 17.0 landed
-
Index SLRUs by 64-bit integers rather than by 32-bit integers
- 4ed8f0913bfd 17.0 cited
-
Add a macro templatized hashtable.
- b30d3ea824c5 10.0 cited