Skip to content

Commit fc34b0d

Browse files
committed
Introduce a maintenance_io_concurrency setting.
Introduce a GUC and a tablespace option to control I/O prefetching, much like effective_io_concurrency, but for work that is done on behalf of many client sessions. Use the new setting in heapam.c instead of the hard-coded formula effective_io_concurrency + 10 introduced by commit 558a916. Go with a default value of 10 for now, because it's a round number pretty close to the value used for that existing case. Discussion: https://postgr.es/m/CA%2BhUKGJUw08dPs_3EUcdO6M90GnjofPYrWp4YSLaBkgYwS-AqA%40mail.gmail.com
1 parent b09ff53 commit fc34b0d

File tree

12 files changed

+109
-23
lines changed

12 files changed

+109
-23
lines changed

doc/src/sgml/config.sgml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,6 +2229,26 @@ include_dir 'conf.d'
22292229
</listitem>
22302230
</varlistentry>
22312231

2232+
<varlistentry id="guc-maintenance-io-concurrency" xreflabel="maintenance_io_concurrency">
2233+
<term><varname>maintenance_io_concurrency</varname> (<type>integer</type>)
2234+
<indexterm>
2235+
<primary><varname>maintenance_io_concurrency</varname> configuration parameter</primary>
2236+
</indexterm>
2237+
</term>
2238+
<listitem>
2239+
<para>
2240+
Similar to <varname>effective_io_concurrency</varname>, but used
2241+
for maintenance work that is done on behalf of many client sessions.
2242+
</para>
2243+
<para>
2244+
The default is 10 on supported systems, otherwise 0. This value can
2245+
be overridden for tables in a particular tablespace by setting the
2246+
tablespace parameter of the same name (see
2247+
<xref linkend="sql-altertablespace"/>).
2248+
</para>
2249+
</listitem>
2250+
</varlistentry>
2251+
22322252
<varlistentry id="guc-max-worker-processes" xreflabel="max_worker_processes">
22332253
<term><varname>max_worker_processes</varname> (<type>integer</type>)
22342254
<indexterm>

doc/src/sgml/ref/alter_tablespace.sgml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,16 @@ ALTER TABLESPACE <replaceable>name</replaceable> RESET ( <replaceable class="par
8484
<para>
8585
A tablespace parameter to be set or reset. Currently, the only
8686
available parameters are <varname>seq_page_cost</varname>,
87-
<varname>random_page_cost</varname> and <varname>effective_io_concurrency</varname>.
88-
Setting either value for a particular tablespace will override the
87+
<varname>random_page_cost</varname>, <varname>effective_io_concurrency</varname>
88+
and <varname>maintenance_io_concurrency</varname>.
89+
Setting these values for a particular tablespace will override the
8990
planner's usual estimate of the cost of reading pages from tables in
90-
that tablespace, as established by the configuration parameters of the
91+
that tablespace, and the executor's prefetching behavior, as established
92+
by the configuration parameters of the
9193
same name (see <xref linkend="guc-seq-page-cost"/>,
9294
<xref linkend="guc-random-page-cost"/>,
93-
<xref linkend="guc-effective-io-concurrency"/>). This may be useful if
95+
<xref linkend="guc-effective-io-concurrency"/>,
96+
<xref linkend="guc-maintenance-io-concurrency"/>). This may be useful if
9497
one tablespace is located on a disk which is faster or slower than the
9598
remainder of the I/O subsystem.
9699
</para>

doc/src/sgml/ref/create_tablespace.sgml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,16 @@ CREATE TABLESPACE <replaceable class="parameter">tablespace_name</replaceable>
106106
<para>
107107
A tablespace parameter to be set or reset. Currently, the only
108108
available parameters are <varname>seq_page_cost</varname>,
109-
<varname>random_page_cost</varname> and <varname>effective_io_concurrency</varname>.
110-
Setting either value for a particular tablespace will override the
109+
<varname>random_page_cost</varname>, <varname>effective_io_concurrency</varname>
110+
and <varname>maintenance_io_concurrency</varname>.
111+
Setting these values for a particular tablespace will override the
111112
planner's usual estimate of the cost of reading pages from tables in
112-
that tablespace, as established by the configuration parameters of the
113+
that tablespace, and the executor's prefetching behavior, as established
114+
by the configuration parameters of the
113115
same name (see <xref linkend="guc-seq-page-cost"/>,
114116
<xref linkend="guc-random-page-cost"/>,
115-
<xref linkend="guc-effective-io-concurrency"/>). This may be useful if
117+
<xref linkend="guc-effective-io-concurrency"/>,
118+
<xref linkend="guc-maintenance-io-concurrency"/>). This may be useful if
116119
one tablespace is located on a disk which is faster or slower than the
117120
remainder of the I/O subsystem.
118121
</para>

src/backend/access/common/reloptions.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,19 @@ static relopt_int intRelOpts[] =
349349
-1, 0, MAX_IO_CONCURRENCY
350350
#else
351351
0, 0, 0
352+
#endif
353+
},
354+
{
355+
{
356+
"maintenance_io_concurrency",
357+
"Number of simultaneous requests that can be handled efficiently by the disk subsystem for maintenance work.",
358+
RELOPT_KIND_TABLESPACE,
359+
ShareUpdateExclusiveLock
360+
},
361+
#ifdef USE_PREFETCH
362+
-1, 0, MAX_IO_CONCURRENCY
363+
#else
364+
0, 0, 0
352365
#endif
353366
},
354367
{
@@ -1700,7 +1713,8 @@ tablespace_reloptions(Datum reloptions, bool validate)
17001713
static const relopt_parse_elt tab[] = {
17011714
{"random_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, random_page_cost)},
17021715
{"seq_page_cost", RELOPT_TYPE_REAL, offsetof(TableSpaceOpts, seq_page_cost)},
1703-
{"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)}
1716+
{"effective_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, effective_io_concurrency)},
1717+
{"maintenance_io_concurrency", RELOPT_TYPE_INT, offsetof(TableSpaceOpts, maintenance_io_concurrency)}
17041718
};
17051719

17061720
return (bytea *) build_reloptions(reloptions, validate,

src/backend/access/heap/heapam.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7003,7 +7003,6 @@ heap_compute_xid_horizon_for_tuples(Relation rel,
70037003
Page hpage;
70047004
#ifdef USE_PREFETCH
70057005
XidHorizonPrefetchState prefetch_state;
7006-
int io_concurrency;
70077006
int prefetch_distance;
70087007
#endif
70097008

@@ -7026,24 +7025,15 @@ heap_compute_xid_horizon_for_tuples(Relation rel,
70267025
/*
70277026
* Compute the prefetch distance that we will attempt to maintain.
70287027
*
7029-
* We don't use the regular formula to determine how much to prefetch
7030-
* here, but instead just add a constant to effective_io_concurrency.
7031-
* That's because it seems best to do some prefetching here even when
7032-
* effective_io_concurrency is set to 0, but if the DBA thinks it's OK to
7033-
* do more prefetching for other operations, then it's probably OK to do
7034-
* more prefetching in this case, too. It may be that this formula is too
7035-
* simplistic, but at the moment there is no evidence of that or any idea
7036-
* about what would work better.
7037-
*
70387028
* Since the caller holds a buffer lock somewhere in rel, we'd better make
70397029
* sure that isn't a catalog relation before we call code that does
70407030
* syscache lookups, to avoid risk of deadlock.
70417031
*/
70427032
if (IsCatalogRelation(rel))
7043-
io_concurrency = effective_io_concurrency;
7033+
prefetch_distance = maintenance_io_concurrency;
70447034
else
7045-
io_concurrency = get_tablespace_io_concurrency(rel->rd_rel->reltablespace);
7046-
prefetch_distance = Min((io_concurrency) + 10, MAX_IO_CONCURRENCY);
7035+
prefetch_distance =
7036+
get_tablespace_maintenance_io_concurrency(rel->rd_rel->reltablespace);
70477037

70487038
/* Start prefetching. */
70497039
xid_horizon_prefetch_buffer(rel, &prefetch_state, prefetch_distance);

src/backend/storage/buffer/bufmgr.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ bool track_io_timing = false;
119119
*/
120120
int effective_io_concurrency = 0;
121121

122+
/*
123+
* Like effective_io_concurrency, but used by maintenance code paths that might
124+
* benefit from a higher setting because they work on behalf of many sessions.
125+
* Overridden by the tablespace setting of the same name.
126+
*/
127+
int maintenance_io_concurrency = 0;
128+
122129
/*
123130
* GUC variables about triggering kernel writeback for buffers written; OS
124131
* dependent defaults are set via the GUC mechanism.

src/backend/utils/cache/spccache.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,17 @@ get_tablespace_io_concurrency(Oid spcid)
221221
else
222222
return spc->opts->effective_io_concurrency;
223223
}
224+
225+
/*
226+
* get_tablespace_maintenance_io_concurrency
227+
*/
228+
int
229+
get_tablespace_maintenance_io_concurrency(Oid spcid)
230+
{
231+
TableSpaceCacheEntry *spc = get_tablespace(spcid);
232+
233+
if (!spc->opts || spc->opts->maintenance_io_concurrency < 0)
234+
return maintenance_io_concurrency;
235+
else
236+
return spc->opts->maintenance_io_concurrency;
237+
}

src/backend/utils/misc/guc.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ static bool check_autovacuum_max_workers(int *newval, void **extra, GucSource so
196196
static bool check_max_wal_senders(int *newval, void **extra, GucSource source);
197197
static bool check_autovacuum_work_mem(int *newval, void **extra, GucSource source);
198198
static bool check_effective_io_concurrency(int *newval, void **extra, GucSource source);
199+
static bool check_maintenance_io_concurrency(int *newval, void **extra, GucSource source);
199200
static void assign_pgstat_temp_directory(const char *newval, void *extra);
200201
static bool check_application_name(char **newval, void **extra, GucSource source);
201202
static void assign_application_name(const char *newval, void *extra);
@@ -2884,6 +2885,24 @@ static struct config_int ConfigureNamesInt[] =
28842885
check_effective_io_concurrency, NULL, NULL
28852886
},
28862887

2888+
{
2889+
{"maintenance_io_concurrency",
2890+
PGC_USERSET,
2891+
RESOURCES_ASYNCHRONOUS,
2892+
gettext_noop("A variant of effective_io_concurrency that is used for maintenance work."),
2893+
NULL,
2894+
GUC_EXPLAIN
2895+
},
2896+
&maintenance_io_concurrency,
2897+
#ifdef USE_PREFETCH
2898+
10,
2899+
#else
2900+
0,
2901+
#endif
2902+
0, MAX_IO_CONCURRENCY,
2903+
check_maintenance_io_concurrency, NULL, NULL
2904+
},
2905+
28872906
{
28882907
{"backend_flush_after", PGC_USERSET, RESOURCES_ASYNCHRONOUS,
28892908
gettext_noop("Number of pages after which previously performed writes are flushed to disk."),
@@ -11466,6 +11485,19 @@ check_effective_io_concurrency(int *newval, void **extra, GucSource source)
1146611485
return true;
1146711486
}
1146811487

11488+
static bool
11489+
check_maintenance_io_concurrency(int *newval, void **extra, GucSource source)
11490+
{
11491+
#ifndef USE_PREFETCH
11492+
if (*newval != 0)
11493+
{
11494+
GUC_check_errdetail("maintenance_io_concurrency must be set to 0 on platforms that lack posix_fadvise().");
11495+
return false;
11496+
}
11497+
#endif /* USE_PREFETCH */
11498+
return true;
11499+
}
11500+
1146911501
static void
1147011502
assign_pgstat_temp_directory(const char *newval, void *extra)
1147111503
{

src/bin/psql/tab-complete.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2140,7 +2140,7 @@ psql_completion(const char *text, int start, int end)
21402140
/* ALTER TABLESPACE <foo> SET|RESET ( */
21412141
else if (Matches("ALTER", "TABLESPACE", MatchAny, "SET|RESET", "("))
21422142
COMPLETE_WITH("seq_page_cost", "random_page_cost",
2143-
"effective_io_concurrency");
2143+
"effective_io_concurrency", "maintenance_io_concurrency");
21442144

21452145
/* ALTER TEXT SEARCH */
21462146
else if (Matches("ALTER", "TEXT", "SEARCH"))

src/include/commands/tablespace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ typedef struct TableSpaceOpts
4040
float8 random_page_cost;
4141
float8 seq_page_cost;
4242
int effective_io_concurrency;
43+
int maintenance_io_concurrency;
4344
} TableSpaceOpts;
4445

4546
extern Oid CreateTableSpace(CreateTableSpaceStmt *stmt);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy