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 1tYTOp-00B9Mr-8s for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Jan 2025 17:11:19 +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 1tYTOm-00GJC2-GW for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Jan 2025 17:11:16 +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 1tYTOm-00GJBu-6l for pgsql-hackers@lists.postgresql.org; Thu, 16 Jan 2025 17:11:16 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tYTOk-000npH-0W for pgsql-hackers@lists.postgresql.org; Thu, 16 Jan 2025 17:11:16 +0000 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-38a25d4b9d4so673064f8f.0 for ; Thu, 16 Jan 2025 09:11:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737047472; x=1737652272; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=kCq1hLYUdy4z8w8g1oEHEfplZZIRHS9uOBdl6S/heJQ=; b=lnlLPP98y4ODA/HR+ugaN2xFaC5DQCzVEwoaxap4tg+1lG9g/Y0a6iStzrgvD8pqde qS+vp9OxyPTRZWOYrYhXKMQM4Qlb8Ss3yHLf8jUzYgp99GoJT0Mr1x8xAEIhI9szhzWm Q8D84LsHppaoX2dmnXhRBUt/1QsMpSWG3RN7sJcLZuLLxCi6PpONdKR+VNaxNZYxFxw1 SMjBsZ4ms34NoyARgfHxd3QUMjFN4e5aGL0YafLacasZ3mNC79nlzVZmTvHpoPt5by3/ mrfyIw6czXgPwql5WfPfkmyOZRmgjho7yoZK4UYKYBYPEc+M4OPH50Q/3s8n4ePUTjW7 odEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737047472; x=1737652272; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=kCq1hLYUdy4z8w8g1oEHEfplZZIRHS9uOBdl6S/heJQ=; b=kmyn9yOxpcPHQjHEXcuo+3C1+r9U/M1AJIHS6gQ+dtlhY3pnxfHBPlUVzL5NpgkCs6 QCFuBHom9csMcJ7rJPJJ1oCxENjqELDunyihHgY50oRsNq0sbqXZSpTJM9leFcEKYbF1 NSt5GgEpSxQdDfEyazBgYgA2/cFVupwcVOqPCipUy7VXNKtXQ2CnTgKo/NJL0OBfTJCA choRHrri0XmtCOjCQhlKpr7L+cMKkZ97HK1G6n2LQbq018ZKyFBRBdSaq4+Zjlyg8xtt FvUzVeDF9WBObSup87TGr37fNM1OINLKHo//FRZENWieihBQg0T3iILVPRzCPUAI7pWP GfkQ== X-Forwarded-Encrypted: i=1; AJvYcCXQC7WnmHiQ+8Z7MMI7uY81amLqR2LJYjeFzlcJgTr7945v1MI0qI2DqmKQIgY6ZmtEooCehfap1Bc67zaa@lists.postgresql.org X-Gm-Message-State: AOJu0YwylelwYm8jhh1TN9PYbRNMDrx5/jXroTJiH/7sfroHI5L1CO71 XXtkCw8GWPLkpdD5ZOM7wQ3OIU+t1Uk7Blw7fUlYgLwFDCwFfOa1 X-Gm-Gg: ASbGncsDwuBMUk72uVg0oPbjmAbb4D1TIdqIV33xKgtetLxFGXiR4wlNAiHEhayidtH ujVvHfnaV4r1X6Ix8s1WPi35SJ2V2b2DPsQ1PIBQPVfPPTbyqqJLEIAy80pD28pJdWyJ9UzxX7n tMmxk+RmEhTazSkCuflrjN38OXoXSdjxTptxvM5VNTJpatbWNLvV3kpttqJiOhRJo8+lUoFgcPD E3BPQYm75cK15Mct12bX0xwqeRPqH0i868oJR9eZR9UWmSlmGTw+qtg+DynnhrC+4oG+bU8kTi2 7qs/uESs6L1V2xffChuOWpK1KWIGw/SH8hg+ARe5ErISe8W74hP1x1+9PmvRhULTPGiJLVzc7fc GTOY7eCQ= X-Google-Smtp-Source: AGHT+IFxVqgFEbduprnRjOMsk4q6dR8YAOVyMb1H6NEPdQgLKEibRqOimI3x2KCpA+vouAswAhDHkA== X-Received: by 2002:a05:6000:470f:b0:385:f092:e1a with SMTP id ffacd0b85a97d-38a872cb24fmr25338189f8f.11.1737047471556; Thu, 16 Jan 2025 09:11:11 -0800 (PST) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-236-134-5.eu-west-3.compute.amazonaws.com. [15.236.134.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38bf3215023sm356680f8f.9.2025.01.16.09.11.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 09:11:10 -0800 (PST) Date: Thu, 16 Jan 2025 17:11:09 +0000 From: Bertrand Drouvot To: Andres Freund Cc: Michael Paquier , pgsql-hackers@lists.postgresql.org Subject: Re: per backend WAL statistics Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Thu, Jan 16, 2025 at 11:38:47AM -0500, Andres Freund wrote: > Hi, > > On 2025-01-16 15:59:31 +0000, Bertrand Drouvot wrote: > > On Wed, Jan 15, 2025 at 03:11:32PM +0900, Michael Paquier wrote: > > > On Fri, Jan 10, 2025 at 09:40:38AM +0000, Bertrand Drouvot wrote: > > > + * WAL pending statistics are incremented inside a critical section > > > + * (see XLogWrite()), so we can't use pgstat_prep_pending_entry() and we rely on > > > + * PendingBackendWalStats instead. > > > + */ > > > +extern PGDLLIMPORT PgStat_PendingWalStats PendingBackendWalStats; > > > > > > Hmm. This makes me wonder if we should rethink a bit the way pending > > > entries are retrieved and if we should do it beforehand for the WAL > > > paths to avoid allocations in some critical sections. Isn't that also > > > because we avoid calling pgstat_prep_backend_pending() for the I/O > > > case as only backends are supported now, discarding cases like the > > > checkpointer where I/O could happen in a critical path? As a whole, > > > the approach taken by the patch is not really consistent with the > > > rest. > > > I agree that's better to have a generic solution and to be consistent with > > the other variable-numbered stats. > > > > The attached is implementing in 0001 the proposition done in [1], i.e: > > > > 1. It adds a new allow_critical_section to PgStat_KindInfo for pgstats kinds > > 2. It ensures to set temporarly allowInCritSection to true when needed > > > > Note that for safety reason 0001 does set allowInCritSection back to false > > unconditionally (means not checking again for allow_critical_section). > > This is a preposterously bad idea. The restriction to not allocate memory in > critical sections exists for a reason, Thanks for sharing your thoughts on it. In [1], you said: " 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 " So, do you think that the initial proposal that has been made here (See R1. in [2]) i.e make use of a new PendingBackendWalStats variable: " 0003 does not rely on pgstat_prep_backend_pending() for its pending statistics but on a new PendingBackendWalStats variable. The reason is that the pending wal statistics are incremented in a critical section (see XLogWrite(), and so a call to pgstat_prep_pending_entry() could trigger a failed assertion: MemoryContextAllocZero()->"CritSectionCount == 0 || (context)->allowInCritSection" " and implemented up to v4 is a viable approach? [1]: https://www.postgresql.org/message-id/66efowskppsns35v5u2m7k4sdnl7yoz5bo64tdjwq7r5lhplrz%40y7dme5xwh2r5 [2]: https://www.postgresql.org/message-id/Z3zqc4o09dM/Ezyz%40ip-10-97-1-34.eu-west-3.compute.internal Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com