diff options
author | Alvaro Herrera | 2024-02-28 16:05:31 +0000 |
---|---|---|
committer | Alvaro Herrera | 2024-02-28 16:05:31 +0000 |
commit | 53c2a97a92665be6bd7d70bd62ae6158fe4db96e (patch) | |
tree | 88d853f098fe925024b82e72f2beea523e24cbe6 /doc/src | |
parent | 1c1eec0f2d88b7e823af959103b2100da493caa9 (diff) |
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
d172b717c6f4.)
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 bcdfa5f2e2f2 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 <[email protected]>
Author: Dilip Kumar <[email protected]>
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/[email protected]
Discussion: https://postgr.es/m/CAFiTN-vzDvNz=ExGXz6gdyjtzGixKSqs0mKHMmaQ8sOSEFZ33A@mail.gmail.com
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/config.sgml | 139 | ||||
-rw-r--r-- | doc/src/sgml/monitoring.sgml | 9 |
2 files changed, 147 insertions, 1 deletions
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 36a2a5ce431..43b1a132a2c 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -2006,6 +2006,145 @@ include_dir 'conf.d' </listitem> </varlistentry> + <varlistentry id="guc-commit-timestamp-buffers" xreflabel="commit_timestamp_buffers"> + <term><varname>commit_timestamp_buffers</varname> (<type>integer</type>) + <indexterm> + <primary><varname>commit_timestamp_buffers</varname> configuration parameter</primary> + </indexterm> + </term> + <listitem> + <para> + Specifies the amount of memory to use to cache the contents of + <literal>pg_commit_ts</literal> (see + <xref linkend="pgdata-contents-table"/>). + If this value is specified without units, it is taken as blocks, + that is <symbol>BLCKSZ</symbol> bytes, typically 8kB. + The default value is <literal>0</literal>, which requests + <varname>shared_buffers</varname>/512 up to 1024 blocks, + but not fewer than 16 blocks. + This parameter can only be set at server start. + </para> + </listitem> + </varlistentry> + + <varlistentry id="guc-multixact-member-buffers" xreflabel="multixact_member_buffers"> + <term><varname>multixact_member_buffers</varname> (<type>integer</type>) + <indexterm> + <primary><varname>multixact_member_buffers</varname> configuration parameter</primary> + </indexterm> + </term> + <listitem> + <para> + Specifies the amount of shared memory to use to cache the contents + of <literal>pg_multixact/members</literal> (see + <xref linkend="pgdata-contents-table"/>). + If this value is specified without units, it is taken as blocks, + that is <symbol>BLCKSZ</symbol> bytes, typically 8kB. + The default value is <literal>32</literal>. + This parameter can only be set at server start. + </para> + </listitem> + </varlistentry> + + <varlistentry id="guc-multixact-offset-buffers" xreflabel="multixact_offset_buffers"> + <term><varname>multixact_offset_buffers</varname> (<type>integer</type>) + <indexterm> + <primary><varname>multixact_offset_buffers</varname> configuration parameter</primary> + </indexterm> + </term> + <listitem> + <para> + Specifies the amount of shared memory to use to cache the contents + of <literal>pg_multixact/offsets</literal> (see + <xref linkend="pgdata-contents-table"/>). + If this value is specified without units, it is taken as blocks, + that is <symbol>BLCKSZ</symbol> bytes, typically 8kB. + The default value is <literal>16</literal>. + This parameter can only be set at server start. + </para> + </listitem> + </varlistentry> + + <varlistentry id="guc-notify-buffers" xreflabel="notify_buffers"> + <term><varname>notify_buffers</varname> (<type>integer</type>) + <indexterm> + <primary><varname>notify_buffers</varname> configuration parameter</primary> + </indexterm> + </term> + <listitem> + <para> + Specifies the amount of shared memory to use to cache the contents + of <literal>pg_notify</literal> (see + <xref linkend="pgdata-contents-table"/>). + If this value is specified without units, it is taken as blocks, + that is <symbol>BLCKSZ</symbol> bytes, typically 8kB. + The default value is <literal>16</literal>. + This parameter can only be set at server start. + </para> + </listitem> + </varlistentry> + + <varlistentry id="guc-serializable-buffers" xreflabel="serializable_buffers"> + <term><varname>serializable_buffers</varname> (<type>integer</type>) + <indexterm> + <primary><varname>serializable_buffers</varname> configuration parameter</primary> + </indexterm> + </term> + <listitem> + <para> + Specifies the amount of shared memory to use to cache the contents + of <literal>pg_serial</literal> (see + <xref linkend="pgdata-contents-table"/>). + If this value is specified without units, it is taken as blocks, + that is <symbol>BLCKSZ</symbol> bytes, typically 8kB. + The default value is <literal>32</literal>. + This parameter can only be set at server start. + </para> + </listitem> + </varlistentry> + + <varlistentry id="guc-subtransaction-buffers" xreflabel="subtransaction_buffers"> + <term><varname>subtransaction_buffers</varname> (<type>integer</type>) + <indexterm> + <primary><varname>subtransaction_buffers</varname> configuration parameter</primary> + </indexterm> + </term> + <listitem> + <para> + Specifies the amount of shared memory to use to cache the contents + of <literal>pg_subtrans</literal> (see + <xref linkend="pgdata-contents-table"/>). + If this value is specified without units, it is taken as blocks, + that is <symbol>BLCKSZ</symbol> bytes, typically 8kB. + The default value is <literal>0</literal>, which requests + <varname>shared_buffers</varname>/512 up to 1024 blocks, + but not fewer than 16 blocks. + This parameter can only be set at server start. + </para> + </listitem> + </varlistentry> + + <varlistentry id="guc-transaction-buffers" xreflabel="transaction_buffers"> + <term><varname>transaction_buffers</varname> (<type>integer</type>) + <indexterm> + <primary><varname>transaction_buffers</varname> configuration parameter</primary> + </indexterm> + </term> + <listitem> + <para> + Specifies the amount of shared memory to use to cache the contents + of <literal>pg_xact</literal> (see + <xref linkend="pgdata-contents-table"/>). + If this value is specified without units, it is taken as blocks, + that is <symbol>BLCKSZ</symbol> bytes, typically 8kB. + The default value is <literal>0</literal>, which requests + <varname>shared_buffers</varname>/512 up to 1024 blocks, + but not fewer than 16 blocks. + This parameter can only be set at server start. + </para> + </listitem> + </varlistentry> + <varlistentry id="guc-max-stack-depth" xreflabel="max_stack_depth"> <term><varname>max_stack_depth</varname> (<type>integer</type>) <indexterm> diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 9d73d8c1bbe..4b8b38b70ef 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -4482,12 +4482,19 @@ description | Waiting for a newly initialized WAL file to reach durable storage <para> <productname>PostgreSQL</productname> accesses certain on-disk information - via <firstterm>SLRU</firstterm> (simple least-recently-used) caches. + via <literal>SLRU</literal> (<firstterm>simple least-recently-used</firstterm>) + caches. The <structname>pg_stat_slru</structname> view will contain one row for each tracked SLRU cache, showing statistics about access to cached pages. </para> + <para> + For each <literal>SLRU</literal> cache that's part of the core server, + there is a configuration parameter that controls its size, with the suffix + <literal>_buffers</literal> appended. + </para> + <table id="pg-stat-slru-view" xreflabel="pg_stat_slru"> <title><structname>pg_stat_slru</structname> View</title> <tgroup cols="1"> |