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

Commit33aaa13

Browse files
committed
Make the number of CLOG buffers adaptive, based on shared_buffers.
Previously, this was hardcoded: we always had 8. Performance testingshows that isn't enough, especially on big SMP systems, so we allow itto scale up as high as 32 when there's adequate memory. On the flipside, when shared_buffers is very small, drop the number of CLOG buffersdown to as little as 4, so that we can start the postmaster evenwhen very little shared memory is available.Per extensive discussion with Simon Riggs, Tom Lane, and others onpgsql-hackers.
1 parent7a72efd commit33aaa13

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

‎src/backend/access/transam/clog.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include"access/clog.h"
3636
#include"access/slru.h"
3737
#include"access/transam.h"
38+
#include"miscadmin.h"
3839
#include"pg_trace.h"
3940

4041
/*
@@ -409,21 +410,49 @@ TransactionIdGetStatus(TransactionId xid, XLogRecPtr *lsn)
409410
returnstatus;
410411
}
411412

413+
/*
414+
* Number of shared CLOG buffers.
415+
*
416+
* Testing during the PostgreSQL 9.2 development cycle revealed that on a
417+
* large multi-processor system, it was possible to have more CLOG page
418+
* requests in flight at one time than the numebr of CLOG buffers which existed
419+
* at that time, which was hardcoded to 8. Further testing revealed that
420+
* performance dropped off with more than 32 CLOG buffers, possibly because
421+
* the linear buffer search algorithm doesn't scale well.
422+
*
423+
* Unconditionally increasing the number of CLOG buffers to 32 did not seem
424+
* like a good idea, because it would increase the minimum amount of shared
425+
* memory required to start, which could be a problem for people running very
426+
* small configurations. The following formula seems to represent a reasonable
427+
* compromise: people with very low values for shared_buffers will get fewer
428+
* CLOG buffers as well, and everyone else will get 32.
429+
*
430+
* It is likely that some further work will be needed here in future releases;
431+
* for example, on a 64-core server, the maximum number of CLOG requests that
432+
* can be simultaneously in flight will be even larger. But that will
433+
* apparently require more than just changing the formula, so for now we take
434+
* the easy way out.
435+
*/
436+
Size
437+
CLOGShmemBuffers(void)
438+
{
439+
returnMin(32,Max(4,NBuffers /512));
440+
}
412441

413442
/*
414443
* Initialization of shared memory for CLOG
415444
*/
416445
Size
417446
CLOGShmemSize(void)
418447
{
419-
returnSimpleLruShmemSize(NUM_CLOG_BUFFERS,CLOG_LSNS_PER_PAGE);
448+
returnSimpleLruShmemSize(CLOGShmemBuffers(),CLOG_LSNS_PER_PAGE);
420449
}
421450

422451
void
423452
CLOGShmemInit(void)
424453
{
425454
ClogCtl->PagePrecedes=CLOGPagePrecedes;
426-
SimpleLruInit(ClogCtl,"CLOG Ctl",NUM_CLOG_BUFFERS,CLOG_LSNS_PER_PAGE,
455+
SimpleLruInit(ClogCtl,"CLOG Ctl",CLOGShmemBuffers(),CLOG_LSNS_PER_PAGE,
427456
CLogControlLock,"pg_clog");
428457
}
429458

‎src/backend/storage/lmgr/lwlock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ NumLWLocks(void)
171171
numLocks+=MaxBackends+NUM_AUXILIARY_PROCS;
172172

173173
/* clog.c needs one per CLOG buffer */
174-
numLocks+=NUM_CLOG_BUFFERS;
174+
numLocks+=CLOGShmemBuffers();
175175

176176
/* subtrans.c needs one per SubTrans buffer */
177177
numLocks+=NUM_SUBTRANS_BUFFERS;

‎src/include/access/clog.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,11 @@ typedef int XidStatus;
2828
#defineTRANSACTION_STATUS_SUB_COMMITTED0x03
2929

3030

31-
/* Number of SLRU buffers to use for clog */
32-
#defineNUM_CLOG_BUFFERS8
33-
34-
3531
externvoidTransactionIdSetTreeStatus(TransactionIdxid,intnsubxids,
3632
TransactionId*subxids,XidStatusstatus,XLogRecPtrlsn);
3733
externXidStatusTransactionIdGetStatus(TransactionIdxid,XLogRecPtr*lsn);
3834

35+
externSizeCLOGShmemBuffers(void);
3936
externSizeCLOGShmemSize(void);
4037
externvoidCLOGShmemInit(void);
4138
externvoidBootStrapCLOG(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp