@@ -1685,7 +1685,7 @@ GetVictimBuffer(BufferAccessStrategy strategy, IOContext io_context)
1685
1685
FlushBuffer (buf_hdr , NULL , IOOBJECT_RELATION , io_context );
1686
1686
LWLockRelease (content_lock );
1687
1687
1688
- ScheduleBufferTagForWriteback (& BackendWritebackContext ,
1688
+ ScheduleBufferTagForWriteback (& BackendWritebackContext , io_context ,
1689
1689
& buf_hdr -> tag );
1690
1690
}
1691
1691
@@ -2725,8 +2725,11 @@ BufferSync(int flags)
2725
2725
CheckpointWriteDelay (flags , (double ) num_processed / num_to_scan );
2726
2726
}
2727
2727
2728
- /* issue all pending flushes */
2729
- IssuePendingWritebacks (& wb_context );
2728
+ /*
2729
+ * Issue all pending flushes. Only checkpointer calls BufferSync(), so
2730
+ * IOContext will always be IOCONTEXT_NORMAL.
2731
+ */
2732
+ IssuePendingWritebacks (& wb_context , IOCONTEXT_NORMAL );
2730
2733
2731
2734
pfree (per_ts_stat );
2732
2735
per_ts_stat = NULL ;
@@ -3110,7 +3113,11 @@ SyncOneBuffer(int buf_id, bool skip_recently_used, WritebackContext *wb_context)
3110
3113
3111
3114
UnpinBuffer (bufHdr );
3112
3115
3113
- ScheduleBufferTagForWriteback (wb_context , & tag );
3116
+ /*
3117
+ * SyncOneBuffer() is only called by checkpointer and bgwriter, so
3118
+ * IOContext will always be IOCONTEXT_NORMAL.
3119
+ */
3120
+ ScheduleBufferTagForWriteback (wb_context , IOCONTEXT_NORMAL , & tag );
3114
3121
3115
3122
return result | BUF_WRITTEN ;
3116
3123
}
@@ -5445,7 +5452,8 @@ WritebackContextInit(WritebackContext *context, int *max_pending)
5445
5452
* Add buffer to list of pending writeback requests.
5446
5453
*/
5447
5454
void
5448
- ScheduleBufferTagForWriteback (WritebackContext * wb_context , BufferTag * tag )
5455
+ ScheduleBufferTagForWriteback (WritebackContext * wb_context , IOContext io_context ,
5456
+ BufferTag * tag )
5449
5457
{
5450
5458
PendingWriteback * pending ;
5451
5459
@@ -5471,7 +5479,7 @@ ScheduleBufferTagForWriteback(WritebackContext *wb_context, BufferTag *tag)
5471
5479
* is now disabled.
5472
5480
*/
5473
5481
if (wb_context -> nr_pending >= * wb_context -> max_pending )
5474
- IssuePendingWritebacks (wb_context );
5482
+ IssuePendingWritebacks (wb_context , io_context );
5475
5483
}
5476
5484
5477
5485
#define ST_SORT sort_pending_writebacks
@@ -5489,8 +5497,9 @@ ScheduleBufferTagForWriteback(WritebackContext *wb_context, BufferTag *tag)
5489
5497
* error out - it's just a hint.
5490
5498
*/
5491
5499
void
5492
- IssuePendingWritebacks (WritebackContext * wb_context )
5500
+ IssuePendingWritebacks (WritebackContext * wb_context , IOContext io_context )
5493
5501
{
5502
+ instr_time io_start ;
5494
5503
int i ;
5495
5504
5496
5505
if (wb_context -> nr_pending == 0 )
@@ -5503,6 +5512,8 @@ IssuePendingWritebacks(WritebackContext *wb_context)
5503
5512
sort_pending_writebacks (wb_context -> pending_writebacks ,
5504
5513
wb_context -> nr_pending );
5505
5514
5515
+ io_start = pgstat_prepare_io_time ();
5516
+
5506
5517
/*
5507
5518
* Coalesce neighbouring writes, but nothing else. For that we iterate
5508
5519
* through the, now sorted, array of pending flushes, and look forward to
@@ -5556,6 +5567,13 @@ IssuePendingWritebacks(WritebackContext *wb_context)
5556
5567
smgrwriteback (reln , BufTagGetForkNum (& tag ), tag .blockNum , nblocks );
5557
5568
}
5558
5569
5570
+ /*
5571
+ * Assume that writeback requests are only issued for buffers containing
5572
+ * blocks of permanent relations.
5573
+ */
5574
+ pgstat_count_io_op_time (IOOBJECT_RELATION , io_context ,
5575
+ IOOP_WRITEBACK , io_start , wb_context -> nr_pending );
5576
+
5559
5577
wb_context -> nr_pending = 0 ;
5560
5578
}
5561
5579
0 commit comments