Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w7l7Z-005fH1-1V for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Apr 2026 02:15:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w7l7X-00EBdc-0G for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Apr 2026 02:15:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w7l7W-00EBdU-2T for pgsql-hackers@lists.postgresql.org; Wed, 01 Apr 2026 02:15:51 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w7l7T-00000002HGy-2MG3 for pgsql-hackers@postgresql.org; Wed, 01 Apr 2026 02:15:50 +0000 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-3590042fa8eso4221531a91.1 for ; Tue, 31 Mar 2026 19:15:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775009745; x=1775614545; darn=postgresql.org; h=to:cc:date:message-id:subject:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=ua0IYPhzwm/Tnf0sf6kwQQ7/WBtjlR9jxQ8hCinsES8=; b=UA69v2bunnpk0nD6duyYdLoU2nEfj1nL5xeg5veCCbCbLviSzPhlNUZ9PUGfFjikbg aA41qE5pRDYsOoN8SU3ChL8fxztOFenwzOuC/b1GXIU5Dz240p+ag1OYin6Svf7m9O+W fy8mWDNHIUN/OL6Ps190FG1qkijFA0duU+S1u2aFB81H0M0+Kye0GVKmD1EcWhSTsRXm okfnHSjsXDKOgTfKSOrLeq4FHzNdaOu/Jcc4Phewd0JFI+mNsQq/7s1t3DXbhK3TAg2c SAW9NB0Tjo5stxjw2xFw8xhN4jes5OPuxx9N/2r35HeuJI5vTR/2Op0Vhvtk3BW2Wj91 YfCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775009745; x=1775614545; h=to:cc:date:message-id:subject:mime-version:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ua0IYPhzwm/Tnf0sf6kwQQ7/WBtjlR9jxQ8hCinsES8=; b=EHxnsRh3uXoGnKKRS6M7oyEQk1DhkQKJ0DGZYlSKRnc334G2Z8EfWbeZffL1aoUP7o ggLHWfKV99d7Sylwu8UDTzHp8xQUFwdVvJu586fgbP0WbfeAkilmLib0JCj9ZhY6ibNv qXKa7k3ho/8Y4uwXqeLhR6Vjt6Hn1Ud3Td4W1nbF31ITPwkmI1qJMYaHPZOmz5iQBJfd lEYtik4o1W8Cv1/+mtF5zYx9Z38wAD6EAdisy5Hpmd/2hsoBtS4sY9MkR/QRsZWT58FX +rj1k/xLEQovSMszWLepMQPctsqlYajuRr8T55hnp9w86PT2Q//qdFvX8JWogeZQJSPv wRfQ== X-Gm-Message-State: AOJu0Yz2DldidXhTSuVnVvgAtFju580ewW1Ch7THvr98zHh8QbaWQpI6 lxcHBA9ynTbsXN8H2dl5GQJrLztfD37KzvajmmP3B8Qz1yHWV+zplXDcFrvWDG9s/eE= X-Gm-Gg: ATEYQzzHNVXDyVzc+oF9PY1WaZEIeW0Iz/rXYhSNBmJD1ZddeBXSe5zVa5BgAFs/D2L /crAi9lmIHfEdGfEfJfj1sj41tIXT8EhXVjz1ylYhpiChgrlgs/KaPnNAaOj4srD3y6CXqpTsuk D4VJS+TDdrRa8itiXCQyW9C6XXW5vbc8GQe89waCQTLYUOZ43ZCkjqVNRlEA3woC0AHZUO+3akX Pl/YdBxSsJC4B1EgsPXDfMKcHfQIKAFYSiPaLYKrGZDFTRqG214jvUKfHWCnJh0Fg+TKoWxX1LC RhyLScKtAhn2HI5/7pymgwMpGibZEG7U5mXUxxWJOyBNQwnr7eeeQdOxT4t5pMidtidn880EdFP 8clYSo5kAgNha+XK4UikMyO1cL7XdnkB+6hoKcoB+vqleNRc5eYsBIEiUtQknUt/9Z0qc0qFPm2 S6LgGFIQAPv+8rwGjDowM+lUrW/xUGrS9k X-Received: by 2002:a17:90b:3f45:b0:35d:a84d:e27e with SMTP id 98e67ed59e1d1-35dc6ea6d2emr1713273a91.6.1775009744938; Tue, 31 Mar 2026 19:15:44 -0700 (PDT) Received: from smtpclient.apple ([185.135.79.125]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35dbe959358sm2811231a91.13.2026.03.31.19.15.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Mar 2026 19:15:44 -0700 (PDT) From: Chao Li Content-Type: multipart/mixed; boundary="Apple-Mail=_0299FAA7-DCDE-4F22-AE63-188BCC9FD6C9" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: bufmgr: pass through I/O stats context in FlushUnlockedBuffer() Message-Id: Date: Wed, 1 Apr 2026 10:15:09 +0800 Cc: Andres Freund , Melanie Plageman To: PostgreSQL-development X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_0299FAA7-DCDE-4F22-AE63-188BCC9FD6C9 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 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 =3D BufferDescriptorGetBuffer(buf); BufferLockAcquire(buffer, buf, BUFFER_LOCK_SHARE_EXCLUSIVE); FlushBuffer(buf, reln, IOOBJECT_RELATION, IOCONTEXT_NORMAL); // = <=3D=3D 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/377BC880-1616-4DEF-B9EF-5E297C358F7D@gmail.com Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_0299FAA7-DCDE-4F22-AE63-188BCC9FD6C9 Content-Disposition: attachment; filename=v1-0001-bufmgr-pass-through-I-O-stats-context-in-FlushUnl.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v1-0001-bufmgr-pass-through-I-O-stats-context-in-FlushUnl.patch" Content-Transfer-Encoding: quoted-printable =46rom=20118dfb42dfce72ada4e8a1f7ce081bf5da149809=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20"Chao=20Li=20(Evan)"=20=0A= Date:=20Wed,=201=20Apr=202026=2009:52:41=20+0800=0ASubject:=20[PATCH=20= v1]=20bufmgr:=20pass=20through=20I/O=20stats=20context=20in=0A=20= FlushUnlockedBuffer()=0A=0AFlushUnlockedBuffer()=20accepted=20io_object=20= and=20io_context=20arguments,=20but=0Aignored=20them=20and=20always=20= called=20FlushBuffer()=20with=20IOOBJECT_RELATION=20and=0A= IOCONTEXT_NORMAL.=0A=0AFix=20that=20by=20passing=20the=20caller-provided=20= io_object=20and=20io_context=20through=0Ato=20FlushBuffer().=20While=20= here,=20make=20FlushBuffer()=20use=20its=20io_object=0Aparameter=20when=20= reporting=20I/O=20timing,=20instead=20of=20hardcoding=0A= IOOBJECT_RELATION.=0A=0AAuthor:=20Chao=20Li=20=0A= Reviewed-by:=0ADiscussion:=20https://postgr.es/m/=0A---=0A=20= src/backend/storage/buffer/bufmgr.c=20|=204=20++--=0A=201=20file=20= changed,=202=20insertions(+),=202=20deletions(-)=0A=0Adiff=20--git=20= a/src/backend/storage/buffer/bufmgr.c=20= b/src/backend/storage/buffer/bufmgr.c=0Aindex=2017499451ad2..0619d7b8d62=20= 100644=0A---=20a/src/backend/storage/buffer/bufmgr.c=0A+++=20= b/src/backend/storage/buffer/bufmgr.c=0A@@=20-4583,7=20+4583,7=20@@=20= FlushBuffer(BufferDesc=20*buf,=20SMgrRelation=20reln,=20IOObject=20= io_object,=0A=20=09=20*=20When=20a=20strategy=20is=20not=20in=20use,=20= the=20write=20can=20only=20be=20a=20"regular"=20write=0A=20=09=20*=20of=20= a=20dirty=20shared=20buffer=20(IOCONTEXT_NORMAL=20IOOP_WRITE).=0A=20=09=20= */=0A-=09pgstat_count_io_op_time(IOOBJECT_RELATION,=20io_context,=0A+=09= pgstat_count_io_op_time(io_object,=20io_context,=0A=20=09=09=09=09=09=09=09= IOOP_WRITE,=20io_start,=201,=20BLCKSZ);=0A=20=0A=20=09= pgBufferUsage.shared_blks_written++;=0A@@=20-4614,7=20+4614,7=20@@=20= FlushUnlockedBuffer(BufferDesc=20*buf,=20SMgrRelation=20reln,=0A=20=09= Buffer=09=09buffer=20=3D=20BufferDescriptorGetBuffer(buf);=0A=20=0A=20=09= BufferLockAcquire(buffer,=20buf,=20BUFFER_LOCK_SHARE_EXCLUSIVE);=0A-=09= FlushBuffer(buf,=20reln,=20IOOBJECT_RELATION,=20IOCONTEXT_NORMAL);=0A+=09= FlushBuffer(buf,=20reln,=20io_object,=20io_context);=0A=20=09= BufferLockUnlock(buffer,=20buf);=0A=20}=0A=20=0A--=20=0A2.50.1=20(Apple=20= Git-155)=0A=0A= --Apple-Mail=_0299FAA7-DCDE-4F22-AE63-188BCC9FD6C9--