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

Commit9a506a6

Browse files
committed
Arrange to call AbsorbFsyncRequests every so often while performing a
checkpoint in the bgwriter. This forestalls overflow of the fsync requestqueue, which is not fatal but causes considerable performance degradationwhen it occurs (because backends then have to do their own fsyncs). Perpatch from Itagaki Takahiro, modified a little bit by me.
1 parentf0bfc02 commit9a506a6

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.202 2006/01/06 00:04:20 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.203 2006/03/03 00:02:01 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -42,6 +42,7 @@
4242

4343
#include"lib/stringinfo.h"
4444
#include"miscadmin.h"
45+
#include"postmaster/bgwriter.h"
4546
#include"storage/buf_internals.h"
4647
#include"storage/bufmgr.h"
4748
#include"storage/bufpage.h"
@@ -61,6 +62,9 @@
6162
#defineLocalBufHdrGetBlock(bufHdr) \
6263
LocalBufferBlockPointers[-((bufHdr)->buf_id + 2)]
6364

65+
/* interval for calling AbsorbFsyncRequests in BufferSync */
66+
#defineWRITES_PER_ABSORB1000
67+
6468

6569
/* GUC variables */
6670
boolzero_damaged_pages= false;
@@ -892,6 +896,7 @@ BufferSync(void)
892896
{
893897
intbuf_id;
894898
intnum_to_scan;
899+
intabsorb_counter;
895900

896901
/*
897902
* Find out where to start the circular scan.
@@ -905,9 +910,23 @@ BufferSync(void)
905910
* Loop over all buffers.
906911
*/
907912
num_to_scan=NBuffers;
913+
absorb_counter=WRITES_PER_ABSORB;
908914
while (num_to_scan-->0)
909915
{
910-
(void)SyncOneBuffer(buf_id, false);
916+
if (SyncOneBuffer(buf_id, false))
917+
{
918+
/*
919+
* If in bgwriter, absorb pending fsync requests after each
920+
* WRITES_PER_ABSORB write operations, to prevent overflow of
921+
* the fsync request queue. If not in bgwriter process, this is
922+
* a no-op.
923+
*/
924+
if (--absorb_counter <=0)
925+
{
926+
AbsorbFsyncRequests();
927+
absorb_counter=WRITES_PER_ABSORB;
928+
}
929+
}
911930
if (++buf_id >=NBuffers)
912931
buf_id=0;
913932
}

‎src/backend/storage/smgr/md.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.118 2005/10/1502:49:26 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.119 2006/03/03 00:02:02 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -28,6 +28,9 @@
2828
#include"utils/memutils.h"
2929

3030

31+
/* interval for calling AbsorbFsyncRequests in mdsync */
32+
#defineFSYNCS_PER_ABSORB10
33+
3134
/*
3235
*The magnetic disk storage manager keeps track of open file
3336
*descriptors in its own descriptor pool. This is done to make it
@@ -702,6 +705,7 @@ mdsync(void)
702705
{
703706
HASH_SEQ_STATUShstat;
704707
PendingOperationEntry*entry;
708+
intabsorb_counter;
705709

706710
if (!pendingOpsTable)
707711
return false;
@@ -714,6 +718,7 @@ mdsync(void)
714718
*/
715719
AbsorbFsyncRequests();
716720

721+
absorb_counter=FSYNCS_PER_ABSORB;
717722
hash_seq_init(&hstat,pendingOpsTable);
718723
while ((entry= (PendingOperationEntry*)hash_seq_search(&hstat))!=NULL)
719724
{
@@ -727,6 +732,19 @@ mdsync(void)
727732
SMgrRelationreln;
728733
MdfdVec*seg;
729734

735+
/*
736+
* If in bgwriter, absorb pending requests every so often to
737+
* prevent overflow of the fsync request queue. The hashtable
738+
* code does not specify whether entries added by this will be
739+
* visited by our search, but we don't really care: it's OK if
740+
* we do, and OK if we don't.
741+
*/
742+
if (--absorb_counter <=0)
743+
{
744+
AbsorbFsyncRequests();
745+
absorb_counter=FSYNCS_PER_ABSORB;
746+
}
747+
730748
/*
731749
* Find or create an smgr hash entry for this relation. This may
732750
* seem a bit unclean -- md calling smgr? But it's really the

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp