Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9a506a6

Browse files
committed
Arrange to call AbsorbFsyncRequests every so often while performing a
checkpoint in the bgwriter. This forestalls overflow of the fsync request queue, which is not fatal but causes considerable performance degradation when it occurs (because backends then have to do their own fsyncs). Per patch from Itagaki Takahiro, modified a little bit by me.
1 parent f0bfc02 commit 9a506a6

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/backend/storage/buffer/bufmgr.c

+21-2
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
#define LocalBufHdrGetBlock(bufHdr) \
6263
LocalBufferBlockPointers[-((bufHdr)->buf_id + 2)]
6364

65+
/* interval for calling AbsorbFsyncRequests in BufferSync */
66+
#define WRITES_PER_ABSORB 1000
67+
6468

6569
/* GUC variables */
6670
bool zero_damaged_pages = false;
@@ -892,6 +896,7 @@ BufferSync(void)
892896
{
893897
int buf_id;
894898
int num_to_scan;
899+
int absorb_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

+19-1
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/15 02: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+
#define FSYNCS_PER_ABSORB 10
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_STATUS hstat;
704707
PendingOperationEntry *entry;
708+
int absorb_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
SMgrRelation reln;
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)