Index: src/backend/storage/buffer/bufmgr.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v retrieving revision 1.202 diff -c -r1.202 bufmgr.c *** src/backend/storage/buffer/bufmgr.c 6 Jan 2006 00:04:20 -0000 1.202 --- src/backend/storage/buffer/bufmgr.c 2 Mar 2006 23:54:29 -0000 *************** *** 42,47 **** --- 42,48 ---- #include "lib/stringinfo.h" #include "miscadmin.h" + #include "postmaster/bgwriter.h" #include "storage/buf_internals.h" #include "storage/bufmgr.h" #include "storage/bufpage.h" *************** *** 61,66 **** --- 62,70 ---- #define LocalBufHdrGetBlock(bufHdr) \ LocalBufferBlockPointers[-((bufHdr)->buf_id + 2)] + /* interval for calling AbsorbFsyncRequests in BufferSync */ + #define WRITES_PER_ABSORB 1000 + /* GUC variables */ bool zero_damaged_pages = false; *************** *** 892,897 **** --- 896,902 ---- { int buf_id; int num_to_scan; + int absorb_counter; /* * Find out where to start the circular scan. *************** *** 905,913 **** * Loop over all buffers. */ num_to_scan = NBuffers; while (num_to_scan-- > 0) { ! (void) SyncOneBuffer(buf_id, false); if (++buf_id >= NBuffers) buf_id = 0; } --- 910,932 ---- * Loop over all buffers. */ num_to_scan = NBuffers; + absorb_counter = WRITES_PER_ABSORB; while (num_to_scan-- > 0) { ! if (SyncOneBuffer(buf_id, false)) ! { ! /* ! * If in bgwriter, absorb pending fsync requests after each ! * WRITES_PER_ABSORB write operations, to prevent overflow of ! * the fsync request queue. If not in bgwriter process, this is ! * a no-op. ! */ ! if (--absorb_counter <= 0) ! { ! AbsorbFsyncRequests(); ! absorb_counter = WRITES_PER_ABSORB; ! } ! } if (++buf_id >= NBuffers) buf_id = 0; } Index: src/backend/storage/smgr/md.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v retrieving revision 1.118 diff -c -r1.118 md.c *** src/backend/storage/smgr/md.c 15 Oct 2005 02:49:26 -0000 1.118 --- src/backend/storage/smgr/md.c 2 Mar 2006 23:54:29 -0000 *************** *** 28,33 **** --- 28,36 ---- #include "utils/memutils.h" + /* interval for calling AbsorbFsyncRequests in mdsync */ + #define FSYNCS_PER_ABSORB 10 + /* * The magnetic disk storage manager keeps track of open file * descriptors in its own descriptor pool. This is done to make it *************** *** 702,707 **** --- 705,711 ---- { HASH_SEQ_STATUS hstat; PendingOperationEntry *entry; + int absorb_counter; if (!pendingOpsTable) return false; *************** *** 714,719 **** --- 718,724 ---- */ AbsorbFsyncRequests(); + absorb_counter = FSYNCS_PER_ABSORB; hash_seq_init(&hstat, pendingOpsTable); while ((entry = (PendingOperationEntry *) hash_seq_search(&hstat)) != NULL) { *************** *** 728,733 **** --- 733,751 ---- MdfdVec *seg; /* + * If in bgwriter, absorb pending requests every so often to + * prevent overflow of the fsync request queue. The hashtable + * code does not specify whether entries added by this will be + * visited by our search, but we don't really care: it's OK if + * we do, and OK if we don't. + */ + if (--absorb_counter <= 0) + { + AbsorbFsyncRequests(); + absorb_counter = FSYNCS_PER_ABSORB; + } + + /* * Find or create an smgr hash entry for this relation. This may * seem a bit unclean -- md calling smgr? But it's really the * best solution. It ensures that the open file reference isn't