public inbox for [email protected]  
help / color / mirror / Atom feed
From: Chao Li <[email protected]>
To: PostgreSQL-development <[email protected]>
Cc: Andres Freund <[email protected]>
Cc: Melanie Plageman <[email protected]>
Subject: bufmgr: pass through I/O stats context in FlushUnlockedBuffer()
Date: Wed, 1 Apr 2026 10:15:09 +0800
Message-ID: <[email protected]> (raw)

Hi,

I noticed that FlushUnlockedBuffer() accepts io_object and io_context, but then ignores them and hardcodes IOOBJECT_RELATIONand IOCONTEXT_NORMAL instead:
```
static void
FlushUnlockedBuffer(BufferDesc *buf, SMgrRelation reln,
					IOObject io_object, IOContext io_context)
{
	Buffer		buffer = BufferDescriptorGetBuffer(buf);

	BufferLockAcquire(buffer, buf, BUFFER_LOCK_SHARE_EXCLUSIVE);
	FlushBuffer(buf, reln, IOOBJECT_RELATION, IOCONTEXT_NORMAL); // <== HERE
	BufferLockUnlock(buffer, buf);
}
```

Unless I am missing something, if a function accepts these parameters, they should generally be used.

FlushBuffer() seems to have the same issue. It takes both io_object and io_context:
```
static void
FlushBuffer(BufferDesc *buf, SMgrRelation reln, IOObject io_object,
         IOContext io_context)
```

but while io_context is used, io_object is ignored:
```
    pgstat_count_io_op_time(IOOBJECT_RELATION, io_context,
          IOOP_WRITE, io_start, 1, BLCKSZ);
```

For comparison, in AsyncReadBuffers(), where io_object is also available locally, it is passed through and used directly:
```
    pgstat_count_io_op_time(io_object, io_context, IOOP_READ,
          io_start, 1, io_buffers_len * BLCKSZ);
```

I raised the same point while reviewing patch [1], but that patch has not been updated yet.

This tiny patch just makes FlushUnlockedBuffer() and FlushBuffer() use the io_object and io_context values passed in by the caller.

[1] Discussion: https://postgr.es/m/[email protected]

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/






Attachments:

  [application/octet-stream] v1-0001-bufmgr-pass-through-I-O-stats-context-in-FlushUnl.patch (1.8K, 2-v1-0001-bufmgr-pass-through-I-O-stats-context-in-FlushUnl.patch)
  download | inline diff:
From 118dfb42dfce72ada4e8a1f7ce081bf5da149809 Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <[email protected]>
Date: Wed, 1 Apr 2026 09:52:41 +0800
Subject: [PATCH v1] bufmgr: pass through I/O stats context in
 FlushUnlockedBuffer()

FlushUnlockedBuffer() accepted io_object and io_context arguments, but
ignored them and always called FlushBuffer() with IOOBJECT_RELATION and
IOCONTEXT_NORMAL.

Fix that by passing the caller-provided io_object and io_context through
to FlushBuffer(). While here, make FlushBuffer() use its io_object
parameter when reporting I/O timing, instead of hardcoding
IOOBJECT_RELATION.

Author: Chao Li <[email protected]>
Reviewed-by:
Discussion: https://postgr.es/m/
---
 src/backend/storage/buffer/bufmgr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 17499451ad2..0619d7b8d62 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -4583,7 +4583,7 @@ FlushBuffer(BufferDesc *buf, SMgrRelation reln, IOObject io_object,
 	 * When a strategy is not in use, the write can only be a "regular" write
 	 * of a dirty shared buffer (IOCONTEXT_NORMAL IOOP_WRITE).
 	 */
-	pgstat_count_io_op_time(IOOBJECT_RELATION, io_context,
+	pgstat_count_io_op_time(io_object, io_context,
 							IOOP_WRITE, io_start, 1, BLCKSZ);
 
 	pgBufferUsage.shared_blks_written++;
@@ -4614,7 +4614,7 @@ FlushUnlockedBuffer(BufferDesc *buf, SMgrRelation reln,
 	Buffer		buffer = BufferDescriptorGetBuffer(buf);
 
 	BufferLockAcquire(buffer, buf, BUFFER_LOCK_SHARE_EXCLUSIVE);
-	FlushBuffer(buf, reln, IOOBJECT_RELATION, IOCONTEXT_NORMAL);
+	FlushBuffer(buf, reln, io_object, io_context);
 	BufferLockUnlock(buffer, buf);
 }
 
-- 
2.50.1 (Apple Git-155)



view thread (3+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: bufmgr: pass through I/O stats context in FlushUnlockedBuffer()
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox