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 1tYSjh-00B2bb-RX for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Jan 2025 16:28:50 +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 1tYSjg-00FjE9-1u for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Jan 2025 16:28:48 +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 1tYSjf-00FjE1-KD for pgsql-hackers@lists.postgresql.org; Thu, 16 Jan 2025 16:28:48 +0000 Received: from fout-b8-smtp.messagingengine.com ([202.12.124.151]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tYSje-000jry-2P for pgsql-hackers@lists.postgresql.org; Thu, 16 Jan 2025 16:28:47 +0000 Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfout.stl.internal (Postfix) with ESMTP id 0326A11401B2; Thu, 16 Jan 2025 11:28:44 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Thu, 16 Jan 2025 11:28:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-transfer-encoding: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=1737044924; x=1737131324; bh=mavngtdrkCs8PybrVwIz82u+OQINP277MrnPXrBfEoY=; b= VVYPRah4StCl2zW5AAfCBV6ydJefWz0qR5ib3Pfr68XmYqxu5prCkicjr0lDmhsK lmM3zWzVsZm3eNW3xJuXilwLMoUxeC6QvjHMsa87//VU5qjyXBuNuzcLgoggbQHW 9eRee0yALBOmyAJzT+9pZ6bcEV9QvHzbJBpCGFVWHDIo+GVnDYHpvukGWV6jQMTN fdV1whl84+jq/wiyGp3T8mohrgIEQc/mhW32VNME2m3DnZPKn3Bz9OF/zrzNe8P2 L3w+x3eR4YrQsquo1g7KJwCtXn5xvpj/K9PuY4SR2Sgo0ff4D6tWhCDg5wT6gYRF w5NsZf0XvS37QA+/LEjMXA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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=1737044924; x= 1737131324; bh=mavngtdrkCs8PybrVwIz82u+OQINP277MrnPXrBfEoY=; b=d Dp/Ez767eX5N/1/Q5QG+MUMJXDFnddCPYefLNarAgxC67cZIR2exqRtAtwNb4VON ukJv0ldwD4FsWoYQDycyRMfM/EWzi97UiaDc3c7cdqIXOtCbixOY359wtJ1Ojmhj qLRD9fQdTM6VathX695FkyrVWrgjR5rltyTVyVpz8qLdKt229cNTdPvrZClj5bc9 8dvAzBqXlFr3aXg6aCas9YeGnGQNhvzC50b2axTQNv0sMsYucCeT9na0I7rgK7Qa BFOswJq6AnMAJGLDAPhzgKAAAxNAHsJHxI3tEGqV+NWMi2ecwfJkOm3EFHlJbZcn tfbhuZ+h61pYH11SvRI4A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeiuddgkeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggugfgjsehtkefstddttddu necuhfhrohhmpeetnhgurhgvshcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgrii gvlhdruggvqeenucggtffrrghtthgvrhhnpefgtdeltdevgfevtdetueffgeeguefhffff leffgffhgeejgefggeehfeeiueejfeenucffohhmrghinhepphhoshhtghhrvghsqhhlrd horhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhep rghnughrvghssegrnhgrrhgriigvlhdruggvpdhnsggprhgtphhtthhopeeipdhmohguvg epshhmthhpohhuthdprhgtphhtthhopegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhp rdhorhhgpdhrtghpthhtohepsggvrhhtrhgrnhguughrohhuvhhothdrphhgsehgmhgrih hlrdgtohhmpdhrtghpthhtohepsgihrghvuhiikedusehgmhgrihhlrdgtohhmpdhrtghp thhtohephhhorhhikhihohhtrgdrnhhtthesghhmrghilhdrtghomhdprhgtphhtthhope hpghhsqhhlqdhhrggtkhgvrhhssehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrghdp rhgtphhtthhopehmihgthhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 16 Jan 2025 11:28:44 -0500 (EST) Date: Thu, 16 Jan 2025 11:28:43 -0500 From: Andres Freund To: Michael Paquier Cc: Bertrand Drouvot , Nazir Bilal Yavuz , Alvaro Herrera , Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org Subject: Re: per backend I/O statistics Message-ID: <66efowskppsns35v5u2m7k4sdnl7yoz5bo64tdjwq7r5lhplrz@y7dme5xwh2r5> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2025-01-15 18:27:22 +0900, Michael Paquier wrote: > 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. > > > > Yeah, I encountered the exact same thing and mentioned it in [1] (see R1.). > > > > In [1] I did propose to use a new PendingBackendWalStats variable to "bypass" the > > pgstat_prep_backend_pending() usage. > > > > Michael mentioned in [2] that is not really consistent with the rest (what 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? > > > > [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. The issue here imo is that recently IO stats were turned into a variable numbered stat, where it previously wasn't. It seems like a bad idea that now we regularly do a somewhat sizable memory allocation for backend stats. For table stats allocating the pending memory is somewhat a necessity - there could be a lot of different tables after all. And later transactions won't necessarily access the same set of tables, so we can't just keep the memory for pending around - but that's not true for IO. > 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. That seems somewhat fundamental - you could have arbitrary numbers of injection points and thus need arbitrary amounts of memory. You can't just do that in a critical section. And it's not just about a potential memory allocation for pending stats, the DSM allocation can't be done in a critical section either. > 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. That seems like an *incredibly* bad idea. That restriction exists for a reason. > Andres, do you have any thoughts about that? Not sure what would be > 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. My view is that for IO stats no memory allocation should be required - that used to be the case and should be the case again. And for something like injection points (not really convinced that it's a good thing to have stats for, but ...), allocation the shared memory stats object outside of the critical section and not having any pending stats seems to be the right approach. Greetings, Andres Freund