Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 53c2a97

Browse files
committed
Improve performance of subsystems on top of SLRU
More precisely, what we do here is make the SLRU cache sizes configurable with new GUCs, so that sites with high concurrency and big ranges of transactions in flight (resp. multixacts/subtransactions) can benefit from bigger caches. In order for this to work with good performance, two additional changes are made: 1. the cache is divided in "banks" (to borrow terminology from CPU caches), and algorithms such as eviction buffer search only affect one specific bank. This forestalls the problem that linear searching for a specific buffer across the whole cache takes too long: we only have to search the specific bank, whose size is small. This work is authored by Andrey Borodin. 2. Change the locking regime for the SLRU banks, so that each bank uses a separate LWLock. This allows for increased scalability. This work is authored by Dilip Kumar. (A part of this was previously committed as d172b71.) Special care is taken so that the algorithms that can potentially traverse more than one bank release one bank's lock before acquiring the next. This should happen rarely, but particularly clog.c's group commit feature needed code adjustment to cope with this. I (Álvaro) also added lots of comments to make sure the design is sound. The new GUCs match the names introduced by bcdfa5f in the pg_stat_slru view. The default values for these parameters are similar to the previous sizes of each SLRU. commit_ts, clog and subtrans accept value 0, which means to adjust by dividing shared_buffers by 512 (so 2MB for every 1GB of shared_buffers), with a cap of 8MB. (A new slru.c function SimpleLruAutotuneBuffers() was added to support this.) The cap was previously 1MB for clog, so for sites with more than 512MB of shared memory the total memory used increases, which is likely a good tradeoff. However, other SLRUs (notably multixact ones) retain smaller sizes and don't support a configured value of 0. These values based on shared_buffers may need to be revisited, but that's an easy change. There was some resistance to adding these new GUCs: it would be better to adjust to memory pressure automatically somehow, for example by stealing memory from shared_buffers (where the caches can grow and shrink naturally). However, doing that seems to be a much larger project and one which has made virtually no progress in several years, and because this is such a pain point for so many users, here we take the pragmatic approach. Author: Andrey Borodin <x4mmm@yandex-team.ru> Author: Dilip Kumar <dilipbalaut@gmail.com> Reviewed-by: Amul Sul, Gilles Darold, Anastasia Lubennikova, Ivan Lazarev, Robert Haas, Thomas Munro, Tomas Vondra, Yura Sokolov, Васильев Дмитрий (Dmitry Vasiliev). Discussion: https://postgr.es/m/2BEC2B3F-9B61-4C1D-9FB5-5FAB0F05EF86@yandex-team.ru Discussion: https://postgr.es/m/CAFiTN-vzDvNz=ExGXz6gdyjtzGixKSqs0mKHMmaQ8sOSEFZ33A@mail.gmail.com
1 parent 1c1eec0 commit 53c2a97

File tree

26 files changed

+1177
-353
lines changed

26 files changed

+1177
-353
lines changed

doc/src/sgml/config.sgml

+139
Original file line numberDiff line numberDiff line change
@@ -2006,6 +2006,145 @@ include_dir 'conf.d'
20062006
</listitem>
20072007
</varlistentry>
20082008

2009+
<varlistentry id="guc-commit-timestamp-buffers" xreflabel="commit_timestamp_buffers">
2010+
<term><varname>commit_timestamp_buffers</varname> (<type>integer</type>)
2011+
<indexterm>
2012+
<primary><varname>commit_timestamp_buffers</varname> configuration parameter</primary>
2013+
</indexterm>
2014+
</term>
2015+
<listitem>
2016+
<para>
2017+
Specifies the amount of memory to use to cache the contents of
2018+
<literal>pg_commit_ts</literal> (see
2019+
<xref linkend="pgdata-contents-table"/>).
2020+
If this value is specified without units, it is taken as blocks,
2021+
that is <symbol>BLCKSZ</symbol> bytes, typically 8kB.
2022+
The default value is <literal>0</literal>, which requests
2023+
<varname>shared_buffers</varname>/512 up to 1024 blocks,
2024+
but not fewer than 16 blocks.
2025+
This parameter can only be set at server start.
2026+
</para>
2027+
</listitem>
2028+
</varlistentry>
2029+
2030+
<varlistentry id="guc-multixact-member-buffers" xreflabel="multixact_member_buffers">
2031+
<term><varname>multixact_member_buffers</varname> (<type>integer</type>)
2032+
<indexterm>
2033+
<primary><varname>multixact_member_buffers</varname> configuration parameter</primary>
2034+
</indexterm>
2035+
</term>
2036+
<listitem>
2037+
<para>
2038+
Specifies the amount of shared memory to use to cache the contents
2039+
of <literal>pg_multixact/members</literal> (see
2040+
<xref linkend="pgdata-contents-table"/>).
2041+
If this value is specified without units, it is taken as blocks,
2042+
that is <symbol>BLCKSZ</symbol> bytes, typically 8kB.
2043+
The default value is <literal>32</literal>.
2044+
This parameter can only be set at server start.
2045+
</para>
2046+
</listitem>
2047+
</varlistentry>
2048+
2049+
<varlistentry id="guc-multixact-offset-buffers" xreflabel="multixact_offset_buffers">
2050+
<term><varname>multixact_offset_buffers</varname> (<type>integer</type>)
2051+
<indexterm>
2052+
<primary><varname>multixact_offset_buffers</varname> configuration parameter</primary>
2053+
</indexterm>
2054+
</term>
2055+
<listitem>
2056+
<para>
2057+
Specifies the amount of shared memory to use to cache the contents
2058+
of <literal>pg_multixact/offsets</literal> (see
2059+
<xref linkend="pgdata-contents-table"/>).
2060+
If this value is specified without units, it is taken as blocks,
2061+
that is <symbol>BLCKSZ</symbol> bytes, typically 8kB.
2062+
The default value is <literal>16</literal>.
2063+
This parameter can only be set at server start.
2064+
</para>
2065+
</listitem>
2066+
</varlistentry>
2067+
2068+
<varlistentry id="guc-notify-buffers" xreflabel="notify_buffers">
2069+
<term><varname>notify_buffers</varname> (<type>integer</type>)
2070+
<indexterm>
2071+
<primary><varname>notify_buffers</varname> configuration parameter</primary>
2072+
</indexterm>
2073+
</term>
2074+
<listitem>
2075+
<para>
2076+
Specifies the amount of shared memory to use to cache the contents
2077+
of <literal>pg_notify</literal> (see
2078+
<xref linkend="pgdata-contents-table"/>).
2079+
If this value is specified without units, it is taken as blocks,
2080+
that is <symbol>BLCKSZ</symbol> bytes, typically 8kB.
2081+
The default value is <literal>16</literal>.
2082+
This parameter can only be set at server start.
2083+
</para>
2084+
</listitem>
2085+
</varlistentry>
2086+
2087+
<varlistentry id="guc-serializable-buffers" xreflabel="serializable_buffers">
2088+
<term><varname>serializable_buffers</varname> (<type>integer</type>)
2089+
<indexterm>
2090+
<primary><varname>serializable_buffers</varname> configuration parameter</primary>
2091+
</indexterm>
2092+
</term>
2093+
<listitem>
2094+
<para>
2095+
Specifies the amount of shared memory to use to cache the contents
2096+
of <literal>pg_serial</literal> (see
2097+
<xref linkend="pgdata-contents-table"/>).
2098+
If this value is specified without units, it is taken as blocks,
2099+
that is <symbol>BLCKSZ</symbol> bytes, typically 8kB.
2100+
The default value is <literal>32</literal>.
2101+
This parameter can only be set at server start.
2102+
</para>
2103+
</listitem>
2104+
</varlistentry>
2105+
2106+
<varlistentry id="guc-subtransaction-buffers" xreflabel="subtransaction_buffers">
2107+
<term><varname>subtransaction_buffers</varname> (<type>integer</type>)
2108+
<indexterm>
2109+
<primary><varname>subtransaction_buffers</varname> configuration parameter</primary>
2110+
</indexterm>
2111+
</term>
2112+
<listitem>
2113+
<para>
2114+
Specifies the amount of shared memory to use to cache the contents
2115+
of <literal>pg_subtrans</literal> (see
2116+
<xref linkend="pgdata-contents-table"/>).
2117+
If this value is specified without units, it is taken as blocks,
2118+
that is <symbol>BLCKSZ</symbol> bytes, typically 8kB.
2119+
The default value is <literal>0</literal>, which requests
2120+
<varname>shared_buffers</varname>/512 up to 1024 blocks,
2121+
but not fewer than 16 blocks.
2122+
This parameter can only be set at server start.
2123+
</para>
2124+
</listitem>
2125+
</varlistentry>
2126+
2127+
<varlistentry id="guc-transaction-buffers" xreflabel="transaction_buffers">
2128+
<term><varname>transaction_buffers</varname> (<type>integer</type>)
2129+
<indexterm>
2130+
<primary><varname>transaction_buffers</varname> configuration parameter</primary>
2131+
</indexterm>
2132+
</term>
2133+
<listitem>
2134+
<para>
2135+
Specifies the amount of shared memory to use to cache the contents
2136+
of <literal>pg_xact</literal> (see
2137+
<xref linkend="pgdata-contents-table"/>).
2138+
If this value is specified without units, it is taken as blocks,
2139+
that is <symbol>BLCKSZ</symbol> bytes, typically 8kB.
2140+
The default value is <literal>0</literal>, which requests
2141+
<varname>shared_buffers</varname>/512 up to 1024 blocks,
2142+
but not fewer than 16 blocks.
2143+
This parameter can only be set at server start.
2144+
</para>
2145+
</listitem>
2146+
</varlistentry>
2147+
20092148
<varlistentry id="guc-max-stack-depth" xreflabel="max_stack_depth">
20102149
<term><varname>max_stack_depth</varname> (<type>integer</type>)
20112150
<indexterm>

doc/src/sgml/monitoring.sgml

+8-1
Original file line numberDiff line numberDiff line change
@@ -4482,12 +4482,19 @@ description | Waiting for a newly initialized WAL file to reach durable storage
44824482

44834483
<para>
44844484
<productname>PostgreSQL</productname> accesses certain on-disk information
4485-
via <firstterm>SLRU</firstterm> (simple least-recently-used) caches.
4485+
via <literal>SLRU</literal> (<firstterm>simple least-recently-used</firstterm>)
4486+
caches.
44864487
The <structname>pg_stat_slru</structname> view will contain
44874488
one row for each tracked SLRU cache, showing statistics about access
44884489
to cached pages.
44894490
</para>
44904491

4492+
<para>
4493+
For each <literal>SLRU</literal> cache that's part of the core server,
4494+
there is a configuration parameter that controls its size, with the suffix
4495+
<literal>_buffers</literal> appended.
4496+
</para>
4497+
44914498
<table id="pg-stat-slru-view" xreflabel="pg_stat_slru">
44924499
<title><structname>pg_stat_slru</structname> View</title>
44934500
<tgroup cols="1">

0 commit comments

Comments
 (0)