Branch data Line data Source code
1 : : /* -------------------------------------------------------------------------
2 : : *
3 : : * pgstat_io.c
4 : : * Implementation of IO statistics.
5 : : *
6 : : * This file contains the implementation of IO statistics. It is kept separate
7 : : * from pgstat.c to enforce the line between the statistics access / storage
8 : : * implementation and the details about individual types of statistics.
9 : : *
10 : : * Copyright (c) 2021-2026, PostgreSQL Global Development Group
11 : : *
12 : : * IDENTIFICATION
13 : : * src/backend/utils/activity/pgstat_io.c
14 : : * -------------------------------------------------------------------------
15 : : */
16 : :
17 : : #include "postgres.h"
18 : :
19 : : #include "executor/instrument.h"
20 : : #include "storage/bufmgr.h"
21 : : #include "utils/pgstat_internal.h"
22 : :
23 : : static PgStat_PendingIO PendingIOStats;
24 : : static bool have_iostats = false;
25 : :
26 : : /*
27 : : * Check that stats have not been counted for any combination of IOObject,
28 : : * IOContext, and IOOp which are not tracked for the passed-in BackendType.
29 : : * Non-zero time with a zero operation count is allowed as there are cases
30 : : * where this may be appropriate -- like when a backend is waiting on IO
31 : : * initiated by another backend.
32 : : *
33 : : * The passed-in PgStat_BktypeIO must contain stats from the BackendType
34 : : * specified by the second parameter. Caller is responsible for locking the
35 : : * passed-in PgStat_BktypeIO, if needed.
36 : : */
37 : : bool
38 : 0 : pgstat_bktype_io_stats_valid(PgStat_BktypeIO *backend_io,
39 : : BackendType bktype)
40 : : {
41 [ # # ]: 0 : for (int io_object = 0; io_object < IOOBJECT_NUM_TYPES; io_object++)
42 : : {
43 [ # # ]: 0 : for (int io_context = 0; io_context < IOCONTEXT_NUM_TYPES; io_context++)
44 : : {
45 [ # # ]: 0 : for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
46 : : {
47 : : /* we don't track it, and it is not 0 */
48 [ # # ]: 0 : if (!pgstat_tracks_io_op(bktype, io_object, io_context, io_op) &&
49 [ # # ]: 0 : (backend_io->counts[io_object][io_context][io_op] != 0 ||
50 [ # # ]: 0 : backend_io->times[io_object][io_context][io_op] != 0))
51 : 0 : return false;
52 : : }
53 : : }
54 : : }
55 : :
56 : 0 : return true;
57 : : }
58 : :
59 : : void
60 : 95155439 : pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op,
61 : : uint32 cnt, uint64 bytes)
62 : : {
63 : : Assert((unsigned int) io_object < IOOBJECT_NUM_TYPES);
64 : : Assert((unsigned int) io_context < IOCONTEXT_NUM_TYPES);
65 : : Assert(pgstat_is_ioop_tracked_in_bytes(io_op) || bytes == 0);
66 : : Assert(pgstat_tracks_io_op(MyBackendType, io_object, io_context, io_op));
67 : :
68 : 95155439 : PendingIOStats.counts[io_object][io_context][io_op] += cnt;
69 : 95155439 : PendingIOStats.bytes[io_object][io_context][io_op] += bytes;
70 : :
71 : : /* Add the per-backend counts */
72 : 95155439 : pgstat_count_backend_io_op(io_object, io_context, io_op, cnt, bytes);
73 : :
74 : 95155439 : have_iostats = true;
75 : 95155439 : pgstat_report_fixed = true;
76 : 95155439 : }
77 : :
78 : : /*
79 : : * Initialize the internal timing for an IO operation, depending on an
80 : : * IO timing GUC.
81 : : */
82 : : instr_time
83 : 6976684 : pgstat_prepare_io_time(bool track_io_guc)
84 : : {
85 : : instr_time io_start;
86 : :
87 [ + + ]: 6976684 : if (track_io_guc)
88 : 5 : INSTR_TIME_SET_CURRENT(io_start);
89 : : else
90 : : {
91 : : /*
92 : : * There is no need to set io_start when an IO timing GUC is disabled.
93 : : * Initialize it to zero to avoid compiler warnings and to let
94 : : * pgstat_count_io_op_time() know that timings should be ignored.
95 : : */
96 : 6976679 : INSTR_TIME_SET_ZERO(io_start);
97 : : }
98 : :
99 : 6976684 : return io_start;
100 : : }
101 : :
102 : : /*
103 : : * Like pgstat_count_io_op() except it also accumulates time.
104 : : *
105 : : * The calls related to pgstat_count_buffer_*() are for pgstat_database. As
106 : : * pg_stat_database only counts block read and write times, these are done for
107 : : * IOOP_READ, IOOP_WRITE and IOOP_EXTEND.
108 : : *
109 : : * pgBufferUsage is used for EXPLAIN. pgBufferUsage has write and read stats
110 : : * for shared, local and temporary blocks. pg_stat_io does not track the
111 : : * activity of temporary blocks, so these are ignored here.
112 : : */
113 : : void
114 : 6976668 : pgstat_count_io_op_time(IOObject io_object, IOContext io_context, IOOp io_op,
115 : : instr_time start_time, uint32 cnt, uint64 bytes)
116 : : {
117 [ + + ]: 6976668 : if (!INSTR_TIME_IS_ZERO(start_time))
118 : : {
119 : : instr_time io_time;
120 : :
121 : 5 : INSTR_TIME_SET_CURRENT(io_time);
122 : 5 : INSTR_TIME_SUBTRACT(io_time, start_time);
123 : :
124 [ + - ]: 5 : if (io_object != IOOBJECT_WAL)
125 : : {
126 [ + + - + ]: 5 : if (io_op == IOOP_WRITE || io_op == IOOP_EXTEND)
127 : : {
128 : 1 : pgstat_count_buffer_write_time(INSTR_TIME_GET_MICROSEC(io_time));
129 [ + - ]: 1 : if (io_object == IOOBJECT_RELATION)
130 : 1 : INSTR_TIME_ADD(pgBufferUsage.shared_blk_write_time, io_time);
131 [ # # ]: 0 : else if (io_object == IOOBJECT_TEMP_RELATION)
132 : 0 : INSTR_TIME_ADD(pgBufferUsage.local_blk_write_time, io_time);
133 : : }
134 [ + - ]: 4 : else if (io_op == IOOP_READ)
135 : : {
136 : 4 : pgstat_count_buffer_read_time(INSTR_TIME_GET_MICROSEC(io_time));
137 [ + - ]: 4 : if (io_object == IOOBJECT_RELATION)
138 : 4 : INSTR_TIME_ADD(pgBufferUsage.shared_blk_read_time, io_time);
139 [ # # ]: 0 : else if (io_object == IOOBJECT_TEMP_RELATION)
140 : 0 : INSTR_TIME_ADD(pgBufferUsage.local_blk_read_time, io_time);
141 : : }
142 : : }
143 : :
144 : 5 : INSTR_TIME_ADD(PendingIOStats.pending_times[io_object][io_context][io_op],
145 : : io_time);
146 : :
147 : : /* Add the per-backend count */
148 : 5 : pgstat_count_backend_io_op_time(io_object, io_context, io_op,
149 : : io_time);
150 : : }
151 : :
152 : 6976668 : pgstat_count_io_op(io_object, io_context, io_op, cnt, bytes);
153 : 6976668 : }
154 : :
155 : : PgStat_IO *
156 : 94 : pgstat_fetch_stat_io(void)
157 : : {
158 : 94 : pgstat_snapshot_fixed(PGSTAT_KIND_IO);
159 : :
160 : 94 : return &pgStatLocal.snapshot.io;
161 : : }
162 : :
163 : : /*
164 : : * Simpler wrapper of pgstat_io_flush_cb()
165 : : */
166 : : void
167 : 194175 : pgstat_flush_io(bool nowait)
168 : : {
169 : 194175 : (void) pgstat_io_flush_cb(nowait);
170 : 194175 : }
171 : :
172 : : /*
173 : : * Flush out locally pending IO statistics
174 : : *
175 : : * If no stats have been recorded, this function returns false.
176 : : *
177 : : * If nowait is true, this function returns true if the lock could not be
178 : : * acquired. Otherwise, return false.
179 : : */
180 : : bool
181 : 235576 : pgstat_io_flush_cb(bool nowait)
182 : : {
183 : : LWLock *bktype_lock;
184 : : PgStat_BktypeIO *bktype_shstats;
185 : :
186 [ + + ]: 235576 : if (!have_iostats)
187 : 41460 : return false;
188 : :
189 : 194116 : bktype_lock = &pgStatLocal.shmem->io.locks[MyBackendType];
190 : 194116 : bktype_shstats =
191 : 194116 : &pgStatLocal.shmem->io.stats.stats[MyBackendType];
192 : :
193 [ + + ]: 194116 : if (!nowait)
194 : 171318 : LWLockAcquire(bktype_lock, LW_EXCLUSIVE);
195 [ + + ]: 22798 : else if (!LWLockConditionalAcquire(bktype_lock, LW_EXCLUSIVE))
196 : 4 : return true;
197 : :
198 [ + + ]: 776448 : for (int io_object = 0; io_object < IOOBJECT_NUM_TYPES; io_object++)
199 : : {
200 [ + + ]: 3494016 : for (int io_context = 0; io_context < IOCONTEXT_NUM_TYPES; io_context++)
201 : : {
202 [ + + ]: 26205120 : for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
203 : : {
204 : : instr_time time;
205 : :
206 : 23293440 : bktype_shstats->counts[io_object][io_context][io_op] +=
207 : 23293440 : PendingIOStats.counts[io_object][io_context][io_op];
208 : :
209 : 23293440 : bktype_shstats->bytes[io_object][io_context][io_op] +=
210 : 23293440 : PendingIOStats.bytes[io_object][io_context][io_op];
211 : :
212 : 23293440 : time = PendingIOStats.pending_times[io_object][io_context][io_op];
213 : :
214 : 23293440 : bktype_shstats->times[io_object][io_context][io_op] +=
215 : 23293440 : INSTR_TIME_GET_MICROSEC(time);
216 : : }
217 : : }
218 : : }
219 : :
220 : : Assert(pgstat_bktype_io_stats_valid(bktype_shstats, MyBackendType));
221 : :
222 : 194112 : LWLockRelease(bktype_lock);
223 : :
224 : 194112 : memset(&PendingIOStats, 0, sizeof(PendingIOStats));
225 : :
226 : 194112 : have_iostats = false;
227 : :
228 : 194112 : return false;
229 : : }
230 : :
231 : : const char *
232 : 22980 : pgstat_get_io_context_name(IOContext io_context)
233 : : {
234 [ + + + + : 22980 : switch (io_context)
+ - ]
235 : : {
236 : 4596 : case IOCONTEXT_BULKREAD:
237 : 4596 : return "bulkread";
238 : 4596 : case IOCONTEXT_BULKWRITE:
239 : 4596 : return "bulkwrite";
240 : 4596 : case IOCONTEXT_INIT:
241 : 4596 : return "init";
242 : 4596 : case IOCONTEXT_NORMAL:
243 : 4596 : return "normal";
244 : 4596 : case IOCONTEXT_VACUUM:
245 : 4596 : return "vacuum";
246 : : }
247 : :
248 [ # # ]: 0 : elog(ERROR, "unrecognized IOContext value: %d", io_context);
249 : : pg_unreachable();
250 : : }
251 : :
252 : : const char *
253 : 4596 : pgstat_get_io_object_name(IOObject io_object)
254 : : {
255 [ + + + - ]: 4596 : switch (io_object)
256 : : {
257 : 1532 : case IOOBJECT_RELATION:
258 : 1532 : return "relation";
259 : 1532 : case IOOBJECT_TEMP_RELATION:
260 : 1532 : return "temp relation";
261 : 1532 : case IOOBJECT_WAL:
262 : 1532 : return "wal";
263 : : }
264 : :
265 [ # # ]: 0 : elog(ERROR, "unrecognized IOObject value: %d", io_object);
266 : : pg_unreachable();
267 : : }
268 : :
269 : : void
270 : 1268 : pgstat_io_init_shmem_cb(void *stats)
271 : : {
272 : 1268 : PgStatShared_IO *stat_shmem = (PgStatShared_IO *) stats;
273 : :
274 [ + + ]: 26628 : for (int i = 0; i < BACKEND_NUM_TYPES; i++)
275 : 25360 : LWLockInitialize(&stat_shmem->locks[i], LWTRANCHE_PGSTATS_DATA);
276 : 1268 : }
277 : :
278 : : void
279 : 264 : pgstat_io_reset_all_cb(TimestampTz ts)
280 : : {
281 [ + + ]: 5544 : for (int i = 0; i < BACKEND_NUM_TYPES; i++)
282 : : {
283 : 5280 : LWLock *bktype_lock = &pgStatLocal.shmem->io.locks[i];
284 : 5280 : PgStat_BktypeIO *bktype_shstats = &pgStatLocal.shmem->io.stats.stats[i];
285 : :
286 : 5280 : LWLockAcquire(bktype_lock, LW_EXCLUSIVE);
287 : :
288 : : /*
289 : : * Use the lock in the first BackendType's PgStat_BktypeIO to protect
290 : : * the reset timestamp as well.
291 : : */
292 [ + + ]: 5280 : if (i == 0)
293 : 264 : pgStatLocal.shmem->io.stats.stat_reset_timestamp = ts;
294 : :
295 : 5280 : memset(bktype_shstats, 0, sizeof(*bktype_shstats));
296 : 5280 : LWLockRelease(bktype_lock);
297 : : }
298 : 264 : }
299 : :
300 : : void
301 : 898 : pgstat_io_snapshot_cb(void)
302 : : {
303 [ + + ]: 18858 : for (int i = 0; i < BACKEND_NUM_TYPES; i++)
304 : : {
305 : 17960 : LWLock *bktype_lock = &pgStatLocal.shmem->io.locks[i];
306 : 17960 : PgStat_BktypeIO *bktype_shstats = &pgStatLocal.shmem->io.stats.stats[i];
307 : 17960 : PgStat_BktypeIO *bktype_snap = &pgStatLocal.snapshot.io.stats[i];
308 : :
309 : 17960 : LWLockAcquire(bktype_lock, LW_SHARED);
310 : :
311 : : /*
312 : : * Use the lock in the first BackendType's PgStat_BktypeIO to protect
313 : : * the reset timestamp as well.
314 : : */
315 [ + + ]: 17960 : if (i == 0)
316 : 898 : pgStatLocal.snapshot.io.stat_reset_timestamp =
317 : 898 : pgStatLocal.shmem->io.stats.stat_reset_timestamp;
318 : :
319 : : /* using struct assignment due to better type safety */
320 : 17960 : *bktype_snap = *bktype_shstats;
321 : 17960 : LWLockRelease(bktype_lock);
322 : : }
323 : 898 : }
324 : :
325 : : /*
326 : : * IO statistics are not collected for all BackendTypes.
327 : : *
328 : : * The following BackendTypes do not participate in the cumulative stats
329 : : * subsystem or do not perform IO on which we currently track:
330 : : * - Dead-end backend because it is not connected to shared memory and
331 : : * doesn't do any IO
332 : : * - Syslogger because it is not connected to shared memory
333 : : * - Archiver because most relevant archiving IO is delegated to a
334 : : * specialized command or module
335 : : *
336 : : * Function returns true if BackendType participates in the cumulative stats
337 : : * subsystem for IO and false if it does not.
338 : : *
339 : : * When adding a new BackendType, also consider adding relevant restrictions to
340 : : * pgstat_tracks_io_object() and pgstat_tracks_io_op().
341 : : */
342 : : bool
343 : 92828 : pgstat_tracks_io_bktype(BackendType bktype)
344 : : {
345 : : /*
346 : : * List every type so that new backend types trigger a warning about
347 : : * needing to adjust this switch.
348 : : */
349 [ + + - ]: 92828 : switch (bktype)
350 : : {
351 : 376 : case B_INVALID:
352 : : case B_DEAD_END_BACKEND:
353 : : case B_ARCHIVER:
354 : : case B_LOGGER:
355 : 376 : return false;
356 : :
357 : 92452 : case B_DATACHECKSUMSWORKER_LAUNCHER:
358 : : case B_DATACHECKSUMSWORKER_WORKER:
359 : : case B_AUTOVAC_LAUNCHER:
360 : : case B_AUTOVAC_WORKER:
361 : : case B_BACKEND:
362 : : case B_BG_WORKER:
363 : : case B_BG_WRITER:
364 : : case B_CHECKPOINTER:
365 : : case B_IO_WORKER:
366 : : case B_SLOTSYNC_WORKER:
367 : : case B_STANDALONE_BACKEND:
368 : : case B_STARTUP:
369 : : case B_WAL_RECEIVER:
370 : : case B_WAL_SENDER:
371 : : case B_WAL_SUMMARIZER:
372 : : case B_WAL_WRITER:
373 : 92452 : return true;
374 : : }
375 : :
376 : 0 : return false;
377 : : }
378 : :
379 : : /*
380 : : * Some BackendTypes do not perform IO on certain IOObjects or in certain
381 : : * IOContexts. Some IOObjects are never operated on in some IOContexts. Check
382 : : * that the given BackendType is expected to do IO in the given IOContext and
383 : : * on the given IOObject and that the given IOObject is expected to be operated
384 : : * on in the given IOContext.
385 : : */
386 : : bool
387 : 90948 : pgstat_tracks_io_object(BackendType bktype, IOObject io_object,
388 : : IOContext io_context)
389 : : {
390 : : bool no_temp_rel;
391 : :
392 : : /*
393 : : * Some BackendTypes should never track IO statistics.
394 : : */
395 [ - + ]: 90948 : if (!pgstat_tracks_io_bktype(bktype))
396 : 0 : return false;
397 : :
398 : : /*
399 : : * Currently, IO on IOOBJECT_WAL objects can only occur in the
400 : : * IOCONTEXT_NORMAL and IOCONTEXT_INIT IOContexts.
401 : : */
402 [ + + + + ]: 90948 : if (io_object == IOOBJECT_WAL &&
403 [ + + ]: 18384 : (io_context != IOCONTEXT_NORMAL &&
404 : : io_context != IOCONTEXT_INIT))
405 : 4596 : return false;
406 : :
407 : : /*
408 : : * Currently, IO on temporary relations can only occur in the
409 : : * IOCONTEXT_NORMAL IOContext.
410 : : */
411 [ + + + + ]: 86352 : if (io_context != IOCONTEXT_NORMAL &&
412 : : io_object == IOOBJECT_TEMP_RELATION)
413 : 6128 : return false;
414 : :
415 : : /*
416 : : * In core Postgres, only regular backends and WAL Sender processes
417 : : * executing queries will use local buffers and operate on temporary
418 : : * relations. Parallel workers will not use local buffers (see
419 : : * InitLocalBuffers()); however, extensions leveraging background workers
420 : : * have no such limitation, so track IO on IOOBJECT_TEMP_RELATION for
421 : : * BackendType B_BG_WORKER.
422 : : */
423 [ + + + + ]: 75712 : no_temp_rel = bktype == B_AUTOVAC_LAUNCHER || bktype == B_BG_WRITER ||
424 [ + + + + ]: 68192 : bktype == B_CHECKPOINTER || bktype == B_AUTOVAC_WORKER ||
425 [ + + + + ]: 56912 : bktype == B_STANDALONE_BACKEND || bktype == B_STARTUP ||
426 [ + + + + : 155936 : bktype == B_WAL_SUMMARIZER || bktype == B_WAL_WRITER ||
+ + ]
427 : : bktype == B_WAL_RECEIVER;
428 : :
429 [ + + + + : 80224 : if (no_temp_rel && io_context == IOCONTEXT_NORMAL &&
+ + ]
430 : : io_object == IOOBJECT_TEMP_RELATION)
431 : 846 : return false;
432 : :
433 : : /*
434 : : * Some BackendTypes only perform IO under IOOBJECT_WAL, hence exclude all
435 : : * rows for all the other objects for these.
436 : : */
437 [ + + + + : 79378 : if ((bktype == B_WAL_SUMMARIZER || bktype == B_WAL_RECEIVER ||
+ + ]
438 [ + + ]: 6486 : bktype == B_WAL_WRITER) && io_object != IOOBJECT_WAL)
439 : 1410 : return false;
440 : :
441 : : /*
442 : : * Some BackendTypes do not currently perform any IO in certain
443 : : * IOContexts, and, while it may not be inherently incorrect for them to
444 : : * do so, excluding those rows from the view makes the view easier to use.
445 : : */
446 [ + + + + : 77968 : if ((bktype == B_CHECKPOINTER || bktype == B_BG_WRITER) &&
+ + ]
447 [ + + ]: 7144 : (io_context == IOCONTEXT_BULKREAD ||
448 [ + + ]: 6956 : io_context == IOCONTEXT_BULKWRITE ||
449 : : io_context == IOCONTEXT_VACUUM))
450 : 564 : return false;
451 : :
452 [ + + + + ]: 77404 : if (bktype == B_AUTOVAC_LAUNCHER && io_context == IOCONTEXT_VACUUM)
453 : 94 : return false;
454 : :
455 [ + + + + : 77310 : if ((bktype == B_AUTOVAC_WORKER || bktype == B_AUTOVAC_LAUNCHER) &&
+ + ]
456 : : io_context == IOCONTEXT_BULKWRITE)
457 : 188 : return false;
458 : :
459 : : /*
460 : : * The data checksums launcher scans catalogs and emits WAL records for
461 : : * checksum state changes. Catalog scans can use a bulkread strategy.
462 : : */
463 [ + + ]: 77122 : if (bktype == B_DATACHECKSUMSWORKER_LAUNCHER)
464 : : {
465 [ + + + + ]: 3760 : if (io_object == IOOBJECT_WAL ||
466 [ + + ]: 1974 : (io_object == IOOBJECT_RELATION &&
467 [ + + ]: 1128 : (io_context == IOCONTEXT_BULKREAD ||
468 : : io_context == IOCONTEXT_NORMAL)))
469 : 3384 : return true;
470 : :
471 : 376 : return false;
472 : : }
473 : :
474 : : /*
475 : : * The worker also scans catalogs, then processes relations using a vacuum
476 : : * access strategy. Catalog scans can use a bulkread strategy.
477 : : */
478 [ + + ]: 73362 : if (bktype == B_DATACHECKSUMSWORKER_WORKER)
479 : : {
480 [ + + + + ]: 4512 : if (io_object == IOOBJECT_WAL ||
481 [ + + ]: 2726 : (io_object == IOOBJECT_RELATION &&
482 [ + + ]: 1880 : (io_context == IOCONTEXT_BULKREAD ||
483 [ + + ]: 1034 : io_context == IOCONTEXT_NORMAL ||
484 : : io_context == IOCONTEXT_VACUUM)))
485 : 4230 : return true;
486 : :
487 : 282 : return false;
488 : : }
489 : :
490 : 68850 : return true;
491 : : }
492 : :
493 : : /*
494 : : * Some BackendTypes will never do certain IOOps and some IOOps should not
495 : : * occur in certain IOContexts or on certain IOObjects. Check that the given
496 : : * IOOp is valid for the given BackendType in the given IOContext and on the
497 : : * given IOObject. Note that there are currently no cases of an IOOp being
498 : : * invalid for a particular BackendType only within a certain IOContext and/or
499 : : * only on a certain IOObject.
500 : : */
501 : : bool
502 : 67968 : pgstat_tracks_io_op(BackendType bktype, IOObject io_object,
503 : : IOContext io_context, IOOp io_op)
504 : : {
505 : : bool strategy_io_context;
506 : :
507 : : /* if (io_context, io_object) will never collect stats, we're done */
508 [ - + ]: 67968 : if (!pgstat_tracks_io_object(bktype, io_object, io_context))
509 : 0 : return false;
510 : :
511 : : /*
512 : : * Some BackendTypes will not do certain IOOps.
513 : : */
514 [ + + + + ]: 67968 : if (bktype == B_BG_WRITER &&
515 [ + + + + ]: 2632 : (io_op == IOOP_READ || io_op == IOOP_EVICT || io_op == IOOP_HIT))
516 : 1128 : return false;
517 : :
518 [ + + + + ]: 66840 : if (bktype == B_CHECKPOINTER &&
519 [ + + + + ]: 3008 : ((io_object != IOOBJECT_WAL && io_op == IOOP_READ) ||
520 [ + + ]: 2444 : (io_op == IOOP_EVICT || io_op == IOOP_HIT)))
521 : 940 : return false;
522 : :
523 [ + + + + : 65900 : if ((bktype == B_BG_WRITER || bktype == B_CHECKPOINTER) &&
+ + ]
524 : : io_op == IOOP_EXTEND)
525 : 752 : return false;
526 : :
527 : : /*
528 : : * Some BackendTypes do not perform reads with IOOBJECT_WAL.
529 : : */
530 [ + + + + : 65148 : if (io_object == IOOBJECT_WAL && io_op == IOOP_READ &&
+ + ]
531 [ + - + + ]: 2688 : (bktype == B_WAL_RECEIVER || bktype == B_BG_WRITER ||
532 [ + + + + ]: 2500 : bktype == B_AUTOVAC_LAUNCHER || bktype == B_AUTOVAC_WORKER ||
533 [ + + ]: 2124 : bktype == B_DATACHECKSUMSWORKER_LAUNCHER ||
534 [ + + ]: 1936 : bktype == B_DATACHECKSUMSWORKER_WORKER ||
535 : : bktype == B_WAL_WRITER))
536 : 1128 : return false;
537 : :
538 : : /*
539 : : * Temporary tables are not logged and thus do not require fsync'ing.
540 : : * Writeback is not requested for temporary tables.
541 : : */
542 [ + + + + ]: 64020 : if (io_object == IOOBJECT_TEMP_RELATION &&
543 [ + + ]: 3486 : (io_op == IOOP_FSYNC || io_op == IOOP_WRITEBACK))
544 : 996 : return false;
545 : :
546 : : /*
547 : : * Some IOOps are not valid in certain IOContexts and some IOOps are only
548 : : * valid in certain contexts.
549 : : */
550 [ + + + + ]: 63024 : if (io_context == IOCONTEXT_BULKREAD && io_op == IOOP_EXTEND)
551 : 1062 : return false;
552 : :
553 [ + + ]: 54528 : strategy_io_context = io_context == IOCONTEXT_BULKREAD ||
554 [ + + + + ]: 116490 : io_context == IOCONTEXT_BULKWRITE || io_context == IOCONTEXT_VACUUM;
555 : :
556 : : /*
557 : : * IOOP_REUSE is only relevant when a BufferAccessStrategy is in use.
558 : : */
559 [ + + + + ]: 61962 : if (!strategy_io_context && io_op == IOOP_REUSE)
560 : 5874 : return false;
561 : :
562 : : /*
563 : : * IOOBJECT_WAL IOObject will not do certain IOOps depending on IOContext.
564 : : */
565 [ + + + + : 56088 : if (io_object == IOOBJECT_WAL && io_context == IOCONTEXT_INIT &&
+ + ]
566 [ + + ]: 7970 : !(io_op == IOOP_WRITE || io_op == IOOP_FSYNC))
567 : 6438 : return false;
568 : :
569 [ + + + + : 49650 : if (io_object == IOOBJECT_WAL && io_context == IOCONTEXT_NORMAL &&
+ + ]
570 [ + + + + ]: 7970 : !(io_op == IOOP_WRITE || io_op == IOOP_READ || io_op == IOOP_FSYNC))
571 : 5564 : return false;
572 : :
573 : : /*
574 : : * IOOP_FSYNC IOOps done by a backend using a BufferAccessStrategy are
575 : : * counted in the IOCONTEXT_NORMAL IOContext. See comment in
576 : : * register_dirty_segment() for more details.
577 : : */
578 [ + + + + ]: 44086 : if (strategy_io_context && io_op == IOOP_FSYNC)
579 : 2622 : return false;
580 : :
581 : :
582 : 41464 : return true;
583 : : }
|