diff -cpr pgsql-orig/src/backend/storage/buffer/bufmgr.c pgsql/src/backend/storage/buffer/bufmgr.c *** pgsql-orig/src/backend/storage/buffer/bufmgr.c 2006-01-16 22:05:14.000000000 +0900 --- pgsql/src/backend/storage/buffer/bufmgr.c 2006-01-16 22:33:24.000000000 +0900 *************** *** 51,56 **** --- 51,57 ---- #include "utils/relcache.h" #include "utils/resowner.h" #include "pgstat.h" + #include "postmaster/bgwriter.h" /* Note: these two macros only work on shared buffers, not local ones! */ *************** static bool IsForInput; *** 82,87 **** --- 83,90 ---- /* local state for LockBufferForCleanup */ static volatile BufferDesc *PinCountWaitBuf = NULL; + /* interval to call AbsorbFsyncRequests in BufferSync */ + #define BUFFERS_PER_ABSORB 10 static bool PinBuffer(volatile BufferDesc *buf); static void PinBuffer_Locked(volatile BufferDesc *buf); *************** BufferSync(void) *** 892,897 **** --- 895,902 ---- { int buf_id; int num_to_scan; + int absorb_counter; + int absorb_interval = NBuffers / BUFFERS_PER_ABSORB; /* * Find out where to start the circular scan. *************** BufferSync(void) *** 905,915 **** --- 910,930 ---- * Loop over all buffers. */ num_to_scan = NBuffers; + absorb_counter = 0; while (num_to_scan-- > 0) { (void) SyncOneBuffer(buf_id, false); if (++buf_id >= NBuffers) buf_id = 0; + if (++absorb_counter >= absorb_interval) + { + /* + * We absorb pending requests after each writing some + * buffers to avoid overflow of the request queue. + */ + AbsorbFsyncRequests(); + absorb_counter = 0; + } } } diff -cpr pgsql-orig/src/backend/storage/smgr/md.c pgsql/src/backend/storage/smgr/md.c *** pgsql-orig/src/backend/storage/smgr/md.c 2006-01-16 22:05:14.000000000 +0900 --- pgsql/src/backend/storage/smgr/md.c 2006-01-16 22:17:46.000000000 +0900 *************** mdsync(void) *** 728,733 **** --- 728,739 ---- MdfdVec *seg; /* + * We absorb pending requests at each fsync to avoid overflow of + * the request queue. + */ + AbsorbFsyncRequests(); + + /* * 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