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 1tXynF-00055c-Bs for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Jan 2025 08:30:29 +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 1tXynD-008xYF-Ta for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Jan 2025 08:30:28 +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 1tXynD-008xY6-KD for pgsql-hackers@lists.postgresql.org; Wed, 15 Jan 2025 08:30:28 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tXynB-000W2Z-1s for pgsql-hackers@lists.postgresql.org; Wed, 15 Jan 2025 08:30:27 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-437a92d7b96so16147445e9.2 for ; Wed, 15 Jan 2025 00:30:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736929823; x=1737534623; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=N5+n1GLy0mLaODFdGHuczbTbZt6jlHgvdalSDjeQOOA=; b=WaP4/hn3I51UPr/wnn7qen0PxbvcvZf4Y1NsK4qYdb9V2ubhk2XaxYrdojXXri1upu MSGQyh+g0/AYQnlWaPsHfIHEOB9gTd6vAes5rDckaoUGk3+owt1MDuHCqDnvbYwJVrYz EvYWc0TNqV4b7N5J5JGnk3wik3BANgmdCWG66cqImBFdbMLkm22GarO0Dj1OUqouv1pa O0KhbsXkg6kYENs/MwIkvvLtnJPXatgG1Ip9UbmW5SIF4pjk/pwnuj6/k17LNZrnF/YV 4F6HeBWtd7HkWvtJqRk9RvwXzJpyPKknGa0ErOoAa9ERJI5ra5RvQHQFcJwP2z5/IFBR hvFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736929823; x=1737534623; h=in-reply-to:content-transfer-encoding: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=N5+n1GLy0mLaODFdGHuczbTbZt6jlHgvdalSDjeQOOA=; b=nYm1aLGsBrMwSGlV3urQpVlUtdWhZp4BRppsXJDuZUvCBI3SX8VD3WYerR+QhcmVNn N6leOxUmwVnKeD/HqAjag3zvnDU09lOGTEzlo6Egk9C802bXnbRh4yyFWc4fOKz7xcGp N56svl7USHJQihIYWq7t8VyaMs5BrCHDeSG51n1FSP2IFDBxz12yQcTvia9ir0aJQJ/K rDlvXS1/NkWirJ/BxtSUWwStzjFpF9Atm9lLZWKda4rxt7L73xLQssGUnNHj8dRsH8iW B+6vf5FZS3/af9MheVYjUgkIqbNfy5eT2qYtG0+cQQiR0mfTbydOAHnmkU0oDvrH7Isv ggSg== X-Forwarded-Encrypted: i=1; AJvYcCV69lZVAApQA7Cmj+byHc0PHeHImbbMDDOTaYAjjEaKL0yecCjCSWXdwyadtDXOSMmAS26Jipgp7UTm3st7@lists.postgresql.org X-Gm-Message-State: AOJu0Yyf/bp5yX4WRqH9ZgXYHbulBs1VwJuR7d2LC1e2c/DOF0WuM7Tr W+wscu2vAuc8lLGNSuaOb3U7dbammU2JHccKrXCq7g4wFeidYon1 X-Gm-Gg: ASbGncsifn4PckvLJp2i2D9V7SB6OKje0waEPbq837ylA2r/V2cfmbtjJmApQun3ubX 9fFI+aOGNdJFTkTbW8YfgYaROpuuJsr5Qw4tYzdd/vSA+icgVcdca+2kBlKNIZRzhORiuZuwfke DXUgC2AqcEvjgyrlv32SLyPL0WQGEF52tU6yLUjyMwsoO/s4JkZwWJ0MB5qx1HtKdajqPis4F40 envjfvVOwLWdS7JzOYc3l6Dc0ZWwNOc5I5zBs2YmNIABIkhDB27fcrqsrUd4CzlKDXf9oXEyh8U eQAGNr8Ksf4yxxaS5/DiWYlxrSuW7NWOmz2NOV46+F2YMJIWuyYxv2SCT8duTM9erxfM4s6NIAK hcH9eDAU= X-Google-Smtp-Source: AGHT+IFcPZaT9R4SGFSz64utkNr30g//SrjwDYsU8s+GtuT50BaOOiKcb4Go5qaeszj5Caiy/lMfQQ== X-Received: by 2002:a05:600c:4704:b0:436:469f:2210 with SMTP id 5b1f17b1804b1-436e267f796mr205465325e9.1.1736929822499; Wed, 15 Jan 2025 00:30:22 -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 5b1f17b1804b1-437c74ac73csm15161195e9.15.2025.01.15.00.30.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 00:30:21 -0800 (PST) Date: Wed, 15 Jan 2025 08:30:20 +0000 From: Bertrand Drouvot To: Nazir Bilal Yavuz Cc: Michael Paquier , Alvaro Herrera , Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org Subject: Re: per backend I/O statistics Message-ID: 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 Wed, Jan 15, 2025 at 11:03:54AM +0300, Nazir Bilal Yavuz wrote: > Hi, > > On Thu, 19 Dec 2024 at 07:22, Michael Paquier wrote: > > > > Fixed that, bumped the two version counters, and done. > > I encountered a problem while trying to add WAL stats to pg_stat_io > and I wanted to hear your thoughts. > > Right now, pgstat_prep_backend_pending() is called in both > pgstat_count_io_op() and pgstat_count_io_op_time() to create a local > PgStat_BackendPending entry. In that process, > pgstat_prep_pending_entry() -> MemoryContextAllocZero() is called. The > problem is that MemoryContextAllocZero() can not be called in the > critical sections. > > For example, here is what happens in the walsender backend: > > ''' > ... -> > exec_replication_command() -> > SendBaseBackup() -> > ... -> > XLogInsertRecord() -> > START_CRIT_SECTION() /* Now we are in the critical section */ -> > ... -> > XLogWrite() -> > pgstat_count_io_op_time() for the pg_pwrite() IO -> > pgstat_prep_backend_pending() -> > pgstat_prep_pending_entry() -> > MemoryContextAllocZero() -> > Failed at Assert("CritSectionCount == 0 || (context)->allowInCritSection") > ''' > > 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 Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com