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 1tXzgd-000Zfs-Nc for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Jan 2025 09:27:44 +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 1tXzga-009VmF-DM for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Jan 2025 09:27:40 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tXzgZ-009Vm7-41 for pgsql-hackers@lists.postgresql.org; Wed, 15 Jan 2025 09:27:40 +0000 Received: from fout-a2-smtp.messagingengine.com ([103.168.172.145]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tXzgY-000VmY-09 for pgsql-hackers@lists.postgresql.org; Wed, 15 Jan 2025 09:27:38 +0000 Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id 3CBA913802BF; Wed, 15 Jan 2025 04:27:36 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Wed, 15 Jan 2025 04:27:36 -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=1736933256; x=1737019656; bh=iKA7bGCxCP LFnupAFIMzZWKrgt2Wq1ABw3ts4Plj074=; b=ualXPvuYRGx0k4+GWd5zxArhsP 4uhOPofs4Tjpbumt9PbOtCsFrFG/bJjjzoufBcWM317PVYpCKS0KUHLKsJStUa7q d9cJ/Rw7IHWT1hnPB/OMHXWZyud18hvXPLBi17oFcJvh2e9s7PzI7wnAHtcupZjg Tdl5B9Ttb6U/1MgY3A+0PANMinX9NEHU9h/GsE2Gu52W0csqGbcNwgJPWExNnccO rsvkqRdDRXa0KUycDKoaoO/PjBrliUQcTyxR2SrxCAa6ptpxhwnTwnmtqfUqSZpJ cz2R6OMkcpKU5eL3Ydncvr7xJ+hMLieTw1HHJ7i7V5DqQLql0DsnWQymbk+A== 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= 1736933256; x=1737019656; bh=iKA7bGCxCPLFnupAFIMzZWKrgt2Wq1ABw3t s4Plj074=; b=dg0rNVxtyhz188DazY53pm4GXW4TlXXBQ9PkTrbnB9TmJbeFFdf akcrXYiGsqRTZIUV4HaxuwwBhXX6yUJqKLVigkd0cqOnibX5HHRNILLkKAZWj7U+ tuiXzSoUEejSxgPpMrmAVPLr+SXvpUbA9Glm05QQeW/+rsa93VthPNyYrLHeQ+S6 INyjocFzicnIIEk9waSnwzBQQ/nmyJa7ETr1K50seCUoIxWWCE52rA8nRXt2X6vV vmIBcnkx7OzyMs2bYa+kqrqwU9MPg8fW/CKm9zsKuoHR/Uws44Cc13c4WOVfJsrj uMcTtxYNbBEEugLGlVbEtmJk+qwWnoRbC5Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudehkedgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnegfrhhlucfvnfffucdlfeehmdenucfjughrpeffhffvvefukfhf gggtuggjsehgtderredttddunecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruc eomhhitghhrggvlhesphgrqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepgffh leefvdehgfeigeehudettdejuefgledtheeftdefteellefgjeeghefggffgnecuffhomh grihhnpehpohhsthhgrhgvshhqlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecu rfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiiipd hnsggprhgtphhtthhopeeipdhmohguvgepshhmthhpohhuthdprhgtphhtthhopegsvghr thhrrghnuggurhhouhhvohhtrdhpghesghhmrghilhdrtghomhdprhgtphhtthhopegshi grvhhuiiekudesghhmrghilhdrtghomhdprhgtphhtthhopegrlhhvhhgvrhhrvgesrghl vhhhrdhnohdqihhprdhorhhgpdhrtghpthhtohephhhorhhikhihohhtrgdrnhhtthesgh hmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehlihhsthhs rdhpohhsthhgrhgvshhqlhdrohhrghdprhgtphhtthhopegrnhgurhgvshesrghnrghrrg iivghlrdguvg X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 Jan 2025 04:27:33 -0500 (EST) Date: Wed, 15 Jan 2025 18:27:22 +0900 From: Michael Paquier To: Bertrand Drouvot Cc: Nazir Bilal Yavuz , Alvaro Herrera , Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org, Andres Freund Subject: Re: per backend I/O statistics Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="cQ4TuUGeJ7KeJmoM" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --cQ4TuUGeJ7KeJmoM Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jan 15, 2025 at 08:30:20AM +0000, Bertrand Drouvot wrote: > On Wed, Jan 15, 2025 at 11:03:54AM +0300, Nazir Bilal Yavuz wrote: >> With this commit it may not be possible to count IOs in the critical >> sections. I think the problem happens only if the local >> PgStat_BackendPending entry is being created for the first time for >> this backend in the critical section. >=20 > Yeah, I encountered the exact same thing and mentioned it in [1] (see R1.= ). >=20 > In [1]=A0I did propose to use a new PendingBackendWalStats variable to "b= ypass" the > pgstat_prep_backend_pending() usage. >=20 > Michael mentioned in [2] that is not really consistent with the rest (wha= t I > agree with) and that "we should rethink a bit the way pending entries are > retrieved". I did not think about it yet but that might be the way to > go, thoughts?=20 >=20 > [1]: https://www.postgresql.org/message-id/Z3zqc4o09dM/Ezyz%40ip-10-97-1-= 34.eu-west-3.compute.internal > [2]: https://www.postgresql.org/message-id/Z4dRlNuhSQ3hPPv2%40paquier.xyz My problem is that this is not only related to backend stats, but to all variable-numbered stats kinds that require this behavior. One other case where I've seen this as being an issue is injection point stats, for example, while enabling these stats for all callbacks and some of them are run in critical sections. A generic solution to the problem would be to allow pgStatPendingContext to have MemoryContextAllowInCriticalSection() set temporarily for the allocation of the pending data. Perhaps not for all stats kinds, just for these where we're OK with the potential memory footprint so we could have a flag in PgStat_KindInfo. Giving to all stats kinds the responsibility to allocate a pending entry beforehand outside a critical section is another option, but that means going through different tweaks for all stats kinds that require them. Andres, do you have any thoughts about that? Not sure what would be=20 your view on this matter. MemoryContextAllowInCriticalSection() for stats kinds that allow the case would be OK for me I guess, we should not be talking about a lot of memory. -- Michael --cQ4TuUGeJ7KeJmoM Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmeHf3oACgkQnvQgOdby QH21nxAAlUmZXC9rjQqt5uTiIIECXs7mu2IP4lyU1doDoOnvy+3JtedfufssXNAO KFhKUW99hH8NJb10sxCLLgZ4iJSZKLX+Iy2CDWBsatGydXBgbrq2trlF6Q0KSgfj JcjykbqhukmAhv5iwqsXLJI07d/5H+snHmbxmvta9iLyra0roIOguJZzIFAmONib KRW03HtPUkXG6PMxW0VitOnNHMdHwrDj5lebWl9kWoUqzVY43iiKP/Vomo4RHMFu alk6/jKBqC6w7X0DR57hjM0n8liRWJl3pDh6e0d7aH6ZveU7RfNIsEVeMoVU9ige aclOupji6w/QMSFQy/wzK2LaCHxSsdi5OjKRMlseqyByU2oVvLN8DV3EdwC34frX Vfb9DjBnN4uu2UguX1V3Izau6hv4zTUmjDrWG4DwRCa+fdPsVegazRTay9kJpgzj LX+hRLsNaT5sDsFM6qwantp1t3MLEvKak25mcNqwaleuv1rcDYcC9N0oHgBrfAdM PmV/BUTQEIfPtpbaVOlTNSVWJAkoTmCauBpwqRsvj2BXify0e+75jXsZ1uuVKvja laAaZYpg+jKI93c5hUhiIn22XNkdP5Rj8xPfvjV1xTve95Flb+xH4sD+ayhFSwgk GJPv+AVY/7F1DCLO8Iqvnx61Qy83iaQyBoxRr2P+I2ny8XqUjkc= =mMxp -----END PGP SIGNATURE----- --cQ4TuUGeJ7KeJmoM--