Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb09ff53

Browse files
committed
Simplify the effective_io_concurrency setting.
The effective_io_concurrency GUC and equivalent tablespace option werepreviously passed through a formula based on a theory about RAIDspindles and probabilities, to arrive at the number of pages to prefetchin bitmap heap scans. Tomas Vondra, Andres Freund and others arguedthat it was anachronistic and hard to justify, and commit558a916already started down the path of bypassing it in new code. We agreed todrop that logic and use the value directly.For the default setting of 1, there is no change in effect. Highersettings can be converted from the old meaning to the new with: select round(sum(OLD / n::float)) from generate_series(1, OLD) s(n);We might want to consider renaming the GUC before the next release giventhe change in meaning, but it's not clear that many users had set itvery carefully anyway. That decision is deferred for now.Discussion:https://postgr.es/m/CA%2BhUKGJUw08dPs_3EUcdO6M90GnjofPYrWp4YSLaBkgYwS-AqA%40mail.gmail.com
1 parentf207bb0 commitb09ff53

File tree

4 files changed

+14
-113
lines changed

4 files changed

+14
-113
lines changed

‎src/backend/executor/nodeBitmapHeapscan.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,6 @@ ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate, int eflags)
707707
{
708708
BitmapHeapScanState*scanstate;
709709
RelationcurrentRelation;
710-
intio_concurrency;
711710

712711
/* check for unsupported flags */
713712
Assert(!(eflags& (EXEC_FLAG_BACKWARD |EXEC_FLAG_MARK)));
@@ -737,8 +736,6 @@ ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate, int eflags)
737736
scanstate->prefetch_iterator=NULL;
738737
scanstate->prefetch_pages=0;
739738
scanstate->prefetch_target=0;
740-
/* may be updated below */
741-
scanstate->prefetch_maximum=target_prefetch_pages;
742739
scanstate->pscan_len=0;
743740
scanstate->initialized= false;
744741
scanstate->shared_tbmiterator=NULL;
@@ -794,20 +791,11 @@ ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate, int eflags)
794791
ExecInitQual(node->bitmapqualorig, (PlanState*)scanstate);
795792

796793
/*
797-
* Determine the maximum for prefetch_target. If the tablespace has a
798-
* specific IO concurrency set, use that to compute the corresponding
799-
* maximum value; otherwise, we already initialized to the value computed
800-
* by the GUC machinery.
794+
* Maximum number of prefetches for the tablespace if configured, otherwise
795+
* the current value of the effective_io_concurrency GUC.
801796
*/
802-
io_concurrency=
797+
scanstate->prefetch_maximum=
803798
get_tablespace_io_concurrency(currentRelation->rd_rel->reltablespace);
804-
if (io_concurrency!=effective_io_concurrency)
805-
{
806-
doublemaximum;
807-
808-
if (ComputeIoConcurrency(io_concurrency,&maximum))
809-
scanstate->prefetch_maximum=rint(maximum);
810-
}
811799

812800
scanstate->ss.ss_currentRelation=currentRelation;
813801

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 7 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ boolzero_damaged_pages = false;
110110
intbgwriter_lru_maxpages=100;
111111
doublebgwriter_lru_multiplier=2.0;
112112
booltrack_io_timing= false;
113+
114+
/*
115+
* How many buffers PrefetchBuffer callers should try to stay ahead of their
116+
* ReadBuffer calls by. Zero means "never prefetch". This value is only used
117+
* for buffers not belonging to tablespaces that have their
118+
* effective_io_concurrency parameter set.
119+
*/
113120
inteffective_io_concurrency=0;
114121

115122
/*
@@ -120,15 +127,6 @@ intcheckpoint_flush_after = 0;
120127
intbgwriter_flush_after=0;
121128
intbackend_flush_after=0;
122129

123-
/*
124-
* How many buffers PrefetchBuffer callers should try to stay ahead of their
125-
* ReadBuffer calls by. This is maintained by the assign hook for
126-
* effective_io_concurrency. Zero means "never prefetch". This value is
127-
* only used for buffers not belonging to tablespaces that have their
128-
* effective_io_concurrency parameter set.
129-
*/
130-
inttarget_prefetch_pages=0;
131-
132130
/* local state for StartBufferIO and related functions */
133131
staticBufferDesc*InProgressBuf=NULL;
134132
staticboolIsForInput;
@@ -461,64 +459,6 @@ static intckpt_buforder_comparator(const void *pa, const void *pb);
461459
staticintts_ckpt_progress_comparator(Datuma,Datumb,void*arg);
462460

463461

464-
/*
465-
* ComputeIoConcurrency -- get the number of pages to prefetch for a given
466-
*number of spindles.
467-
*/
468-
bool
469-
ComputeIoConcurrency(intio_concurrency,double*target)
470-
{
471-
doublenew_prefetch_pages=0.0;
472-
inti;
473-
474-
/*
475-
* Make sure the io_concurrency value is within valid range; it may have
476-
* been forced with a manual pg_tablespace update.
477-
*/
478-
io_concurrency=Min(Max(io_concurrency,0),MAX_IO_CONCURRENCY);
479-
480-
/*----------
481-
* The user-visible GUC parameter is the number of drives (spindles),
482-
* which we need to translate to a number-of-pages-to-prefetch target.
483-
* The target value is stashed in *extra and then assigned to the actual
484-
* variable by assign_effective_io_concurrency.
485-
*
486-
* The expected number of prefetch pages needed to keep N drives busy is:
487-
*
488-
* drives | I/O requests
489-
* -------+----------------
490-
*1 | 1
491-
*2 | 2/1 + 2/2 = 3
492-
*3 | 3/1 + 3/2 + 3/3 = 5 1/2
493-
*4 | 4/1 + 4/2 + 4/3 + 4/4 = 8 1/3
494-
*n | n * H(n)
495-
*
496-
* This is called the "coupon collector problem" and H(n) is called the
497-
* harmonic series. This could be approximated by n * ln(n), but for
498-
* reasonable numbers of drives we might as well just compute the series.
499-
*
500-
* Alternatively we could set the target to the number of pages necessary
501-
* so that the expected number of active spindles is some arbitrary
502-
* percentage of the total. This sounds the same but is actually slightly
503-
* different. The result ends up being ln(1-P)/ln((n-1)/n) where P is
504-
* that desired fraction.
505-
*
506-
* Experimental results show that both of these formulas aren't aggressive
507-
* enough, but we don't really have any better proposals.
508-
*
509-
* Note that if io_concurrency = 0 (disabled), we must set target = 0.
510-
*----------
511-
*/
512-
513-
for (i=1;i <=io_concurrency;i++)
514-
new_prefetch_pages+= (double)io_concurrency / (double)i;
515-
516-
*target=new_prefetch_pages;
517-
518-
/* This range check shouldn't fail, but let's be paranoid */
519-
return (new_prefetch_pages >=0.0&&new_prefetch_pages< (double)INT_MAX);
520-
}
521-
522462
/*
523463
* PrefetchBuffer -- initiate asynchronous read of a block of a relation
524464
*

‎src/backend/utils/misc/guc.c

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ static bool check_autovacuum_max_workers(int *newval, void **extra, GucSource so
196196
staticboolcheck_max_wal_senders(int*newval,void**extra,GucSourcesource);
197197
staticboolcheck_autovacuum_work_mem(int*newval,void**extra,GucSourcesource);
198198
staticboolcheck_effective_io_concurrency(int*newval,void**extra,GucSourcesource);
199-
staticvoidassign_effective_io_concurrency(intnewval,void*extra);
200199
staticvoidassign_pgstat_temp_directory(constchar*newval,void*extra);
201200
staticboolcheck_application_name(char**newval,void**extra,GucSourcesource);
202201
staticvoidassign_application_name(constchar*newval,void*extra);
@@ -2882,7 +2881,7 @@ static struct config_int ConfigureNamesInt[] =
28822881
0,
28832882
#endif
28842883
0,MAX_IO_CONCURRENCY,
2885-
check_effective_io_concurrency,assign_effective_io_concurrency,NULL
2884+
check_effective_io_concurrency,NULL,NULL
28862885
},
28872886

28882887
{
@@ -11457,36 +11456,14 @@ check_max_worker_processes(int *newval, void **extra, GucSource source)
1145711456
staticbool
1145811457
check_effective_io_concurrency(int*newval,void**extra,GucSourcesource)
1145911458
{
11460-
#ifdefUSE_PREFETCH
11461-
doublenew_prefetch_pages;
11462-
11463-
if (ComputeIoConcurrency(*newval,&new_prefetch_pages))
11464-
{
11465-
int*myextra= (int*)guc_malloc(ERROR,sizeof(int));
11466-
11467-
*myextra= (int)rint(new_prefetch_pages);
11468-
*extra= (void*)myextra;
11469-
11470-
return true;
11471-
}
11472-
else
11473-
return false;
11474-
#else
11459+
#ifndefUSE_PREFETCH
1147511460
if (*newval!=0)
1147611461
{
1147711462
GUC_check_errdetail("effective_io_concurrency must be set to 0 on platforms that lack posix_fadvise().");
1147811463
return false;
1147911464
}
11480-
return true;
11481-
#endif/* USE_PREFETCH */
11482-
}
11483-
11484-
staticvoid
11485-
assign_effective_io_concurrency(intnewval,void*extra)
11486-
{
11487-
#ifdefUSE_PREFETCH
11488-
target_prefetch_pages=*((int*)extra);
1148911465
#endif/* USE_PREFETCH */
11466+
return true;
1149011467
}
1149111468

1149211469
staticvoid

‎src/include/storage/bufmgr.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ extern bool zero_damaged_pages;
5757
externintbgwriter_lru_maxpages;
5858
externdoublebgwriter_lru_multiplier;
5959
externbooltrack_io_timing;
60-
externinttarget_prefetch_pages;
60+
externinteffective_io_concurrency;
6161

6262
externintcheckpoint_flush_after;
6363
externintbackend_flush_after;
@@ -66,9 +66,6 @@ extern intbgwriter_flush_after;
6666
/* in buf_init.c */
6767
externPGDLLIMPORTchar*BufferBlocks;
6868

69-
/* in guc.c */
70-
externinteffective_io_concurrency;
71-
7269
/* in localbuf.c */
7370
externPGDLLIMPORTintNLocBuffer;
7471
externPGDLLIMPORTBlock*LocalBufferBlockPointers;
@@ -161,7 +158,6 @@ extern PGDLLIMPORT int32 *LocalRefCount;
161158
/*
162159
* prototypes for functions in bufmgr.c
163160
*/
164-
externboolComputeIoConcurrency(intio_concurrency,double*target);
165161
externvoidPrefetchBuffer(Relationreln,ForkNumberforkNum,
166162
BlockNumberblockNum);
167163
externBufferReadBuffer(Relationreln,BlockNumberblockNum);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp