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.94.2) (envelope-from ) id 1tZ4ac-000Q4o-Sy for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Jan 2025 08:53:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tZ4aZ-00GcJo-CB for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Jan 2025 08:53:55 +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.94.2) (envelope-from ) id 1tZ4aY-00GcJe-6w for pgsql-hackers@lists.postgresql.org; Sat, 18 Jan 2025 08:53:55 +0000 Received: from fhigh-b1-smtp.messagingengine.com ([202.12.124.152]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tZ4aU-000AXB-0t for pgsql-hackers@lists.postgresql.org; Sat, 18 Jan 2025 08:53:53 +0000 Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfhigh.stl.internal (Postfix) with ESMTP id EFD76254012F; Sat, 18 Jan 2025 03:53:47 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Sat, 18 Jan 2025 03:53:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1737190427; x=1737276827; bh=mLVJqx6PsM vwg5s20mZGheBZd8ZwFPry4thfpE7h9QA=; b=ItfOYzFBJnvvzk9vzZo37EQYbT v12/lDK+tzw9vElHpdhFRfOh55P3w95l2TPN1lxQseR8w4x1a9BjBo7ySZII/HGk 4Y9YIN9c7Oa7V9GcbngE+bLR1OZj/yDMp7xtM3VRvu3n+QIuOsKq/06NhlOsyj+s D2nVHUsgFGvtCju4varw9mZISxJl2pcuzURtFM9qnCwZCJe78s7adyys7g3Le/qr Tdosx7ggOM2wKOaRcQGH+3XfgePPzN9Jd6z3WWroOv+IgtMOHXqtqfTUdgGnwbjb aHPxfqAFZTrESe1AhLpIA8lBBuqdVbQuhPCHtBqCGhbJIeTxMHbxM6Wd8kJQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1737190427; x=1737276827; bh=mLVJqx6PsMvwg5s20mZGheBZd8ZwFPry4th fpE7h9QA=; b=c5paN+XRVWKi6Wq3Xoy9mEfAOjNS++I+dcDNrcWlJO7e0vV7wAo Yo4Znhwrfs93wL6MigwWhGbxAux8e2QE7lvJOjv+XtQegpRawbv3YHRVZTIymCxy w0M5kiwvoHLSFQIvyCFS5ycGs3GfJuPqt3qDfylP4wdIv7GS6TK9ngMc2I7kG95v 7G8fyou+s3tGJzqzz8e1+bNC+jiBXOSggptPyLQqSe4295RWVHSPvSx3NLqz/vHw XUnnRYKcrATP/3Ek5vip8jnFoW4spjyLOrIhLf+UOH3M9HPtZzXICgjQwJDJLwWG +DV4lx8oYu4caZhYzawsvIymZJpoIVoVJaA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeigedguddvfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenfghrlhcuvffnffculdejtddmnecujfgurhepfffhvfevuffk fhggtggujgesghdtreertddtvdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrh cuoehmihgthhgrvghlsehprghquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpeet leeifedufffhhfdtteelgeeggeffhfekueevteeigfduudevudetgfegiedvjeenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghl sehprghquhhivghrrdighiiipdhnsggprhgtphhtthhopeeipdhmohguvgepshhmthhpoh huthdprhgtphhtthhopegsvghrthhrrghnuggurhhouhhvohhtrdhpghesghhmrghilhdr tghomhdprhgtphhtthhopegrnhgurhgvshesrghnrghrrgiivghlrdguvgdprhgtphhtth hopegshigrvhhuiiekudesghhmrghilhdrtghomhdprhgtphhtthhopegrlhhvhhgvrhhr vgesrghlvhhhrdhnohdqihhprdhorhhgpdhrtghpthhtohephhhorhhikhihohhtrgdrnh htthesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehl ihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 18 Jan 2025 03:53:45 -0500 (EST) Date: Sat, 18 Jan 2025 17:53:31 +0900 From: Michael Paquier To: Bertrand Drouvot Cc: Andres Freund , Nazir Bilal Yavuz , Alvaro Herrera , Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org Subject: Re: per backend I/O statistics Message-ID: References: <66efowskppsns35v5u2m7k4sdnl7yoz5bo64tdjwq7r5lhplrz@y7dme5xwh2r5> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="f9Kk0M4NVoBI1YOo" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --f9Kk0M4NVoBI1YOo Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 17, 2025 at 10:23:48AM +0000, Bertrand Drouvot wrote: > Please find attached a patch implementing the ideas above, meaning: >=20 > - It creates a new PendingBackendStats variable > - It uses this variable to increment and flush per backend pending IO sta= tistics >=20 > That way we get rid of the memory allocation for pending IO statistics. >=20 > One remark: a special case has been added in pgstat_flush_pending_entries= (). The > reason is that while the per backend stats are "variable-numbered" stats,= it could > be that their pending stats are not part of pgStatPending. This is curren= tly the > case (with this patch) as the per backend pending IO stats are not tracke= d with > pgstat_prep_backend_pending() and friends anymore. + /* + * There is a special case for some pending stats that are tracked in + * PendingBackendStats. It's possible that those have not been flushed + * above, hence the extra check here. + */ + if (!pg_memory_is_all_zeros(&PendingBackendStats, + sizeof(struct PgStat_BackendPending))) + { + PgStat_EntryRef *entry_ref; + + entry_ref =3D pgstat_get_entry_ref(PGSTAT_KIND_BACKEND, InvalidOid, + MyProcNumber, false, NULL); Hmm. Such special complexities in pgstat.c are annoying. There is a stupid thing I am wondering here. For the WAL stats, why couldn't we place some calls of pgstat_prep_backend_pending() in strategic places like XLogBeginInsert() to force all the allocation steps of the pending entry to happen before we would enter the critical sections when doing a WAL insertion? As far as I can see, there is a special case with 2PC where XLogBeginInsert() could be called in a critical section, but that seems to be the only one at quick glance. -- Michael --f9Kk0M4NVoBI1YOo Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmeLbAsACgkQnvQgOdby QH33xQ/+JBW4fQDHmpLJTqLz0FAMm2erOk05Ege2rcNyziRJ/UngnlBzuwMgDsao jrGH6L8412PfVuU9fVvfR+OR8n1hYtsi0KlfoHDn+K+TnYhTn33Z31YFC1sP3+Gc 9gBXNVen88tIs8BSsc+6WDKe8Xj3wtZjs53tVUWImchw3vZ1YEnd4kFj43z67/Ri 0f1EjNXbufEHJmCBkEiuKMpncp/nzpeQX2cfMgwFUEbxVw1giY+0KX90nYPenIcr 6R3EsZwiaantSMVnrRXCZwZ3r50PU25FL4L5BXGyoqQKPcCHmz+jY+hGvVhtvtpS paVeEcSB04i/azZBHoMXyTVcN38HpT2Z2ud6h1HP8/k7Hxg0cFepgEI/BLjar+6D 5yvaPZxyDPxvD8DwKaOpyU6UbjhAaDMsPGdLJbhs4t+FCT99jNeBZ7FkyMYHuAgV A1uoxWv2cJ4+YmRM5klilv56oSmqMnVVwvSvQFjWbOD0yvw6w4lS6+Ns5qS0RC/L 7F9bcdFtz+aZkPddf9I6fvcuIh8VXd70gzSiY8a2cWmrut8CSbwZfhO7pQxRDBEX VwZp9gr3gLvvHvO4aNN1Ho0CuKXvAjm3qizfiz15wBHExkForQWPr7tY9SAtg7/B Z6DWkAIHYL7osjmT41Q4RS87TJxuMlf1hg7ENeqPNzo87LnxOps= =Htpw -----END PGP SIGNATURE----- --f9Kk0M4NVoBI1YOo--