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.96) (envelope-from ) id 1w747p-004vRQ-1u for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Mar 2026 04:21:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w747m-0018qY-2Z for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Mar 2026 04:21:15 +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.96) (envelope-from ) id 1w747m-0018qQ-1Y for pgsql-hackers@lists.postgresql.org; Mon, 30 Mar 2026 04:21:14 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w747k-00000001vwV-1vn5 for pgsql-hackers@lists.postgresql.org; Mon, 30 Mar 2026 04:21:14 +0000 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-59e5aa4ca41so2325043e87.2 for ; Sun, 29 Mar 2026 21:21:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774844472; cv=none; d=google.com; s=arc-20240605; b=h0EU7bi+W5MxZVMIdfZ2vxxYZJB+YyV2MR/RfZWxbFrnaEtQ3zr0Mmb+rbHX/Ue1cZ ofxcGO/jb338HxwR4wqpuWpQcbUVmqv4P9g2rfeUJ0h5YqUV0zQjHEFR7LJyLDsTvrKo 254VaXYJ2TNQiNsNit8ZPF6oo6gwsBNDzgYtjQCIB00o4dPpHeAkUSol5Ahe+PDP8tEA g9yI5B1oP8DtRi0fsxIzqdiIzQZOUU3um7Xxw5P3/zfOVPs+K5T485UNN7bse6H03S30 RApSrOKo+kGbKwMWohlHXnIOQaRzdwkinvYVXP3VOZlqhW/pZb1QxuvkS6YlP62Lof3p zC/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=WT3RbIB4nY84dgK5yTgh75RAmNOgcyATV8PoT534QTE=; fh=nlo53KgM6r1EBL1DLKhXH6r8ZrpUbFFzYIdQqob4nTY=; b=KF2nb2QfSLVleqYDWFr3WqEGDS9HEd+vehFOBv2+Fp0Z7AHIIbD3/5R8a1SB4XMeqW uaB6LevIMRgC9ZAt9wsJbclYcPlL1BUAuzM5KXL9suaNTmaMhCWaB/B7m2uNYtVWvvDg 9cLTdVArTsUxRVBmkdY2kVbont01jqH5S2jjExNAYpC4s7p+mux0mDHqD5zskDuY2sd0 xzO89DOtXodXP7PeHqbO3HhzhmDsPBO5iX1W3Uutnej2KNqdLJVQm9XU/ILi5CI068kh 6FKHxkz6Fyfekca86GMTT1kD6ZwcQDqenceG40xUKWCPGSkp7nGDTFpnXzwoE4VCD2Tf gwtw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774844472; x=1775449272; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=WT3RbIB4nY84dgK5yTgh75RAmNOgcyATV8PoT534QTE=; b=HTzH3AG8UwonVnFGCcjqkYtlqTa8Rgbvzx5PqKQb29LyuaBomMDl1ubcunq3FGA6QC pN4j9sg4u8Q8nzD9ssOKUOI9PGQbeHc30W/fbz7ojWqVp7nD0ZqccR1j0SH0KikPHbs4 zwf3YAAv41db/VON6P7tvuKhll70hiAGMr23E+ICRUx9bLeTIPaBMOcqLutQLWfRzq5Z avMp8S9rBWnULR01nYPh+eVxIonhNCRfnmbW8AIsvCJdSVrnt9uNwiLjFFGeKFzo9xIx pCZBTiJ4BKZmJ1JuiXFJfpbAwHFTfmyrwfjRlaUJc1UrpND42vbtL9HxmZKHmrn8KI2/ uBqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774844472; x=1775449272; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=WT3RbIB4nY84dgK5yTgh75RAmNOgcyATV8PoT534QTE=; b=RIeOgXmVrwsHfgjKx59gVmrluljsm3tCbT5Y7pfb3lycyYFpp7BdA7oPKmCfDBB3Q9 0A70WyePHr4rY97antoS8zKuzO+iuHwayggKveW8GhQZAn+V8vXG+ncfb6Y1dUreFRXo Zs5yUlhsgPKIxOx0So4wThlRnVaI9MklOMKG65qhPnFj11Q8LfNMy7h8R7fgqtDKBVm9 +pBM9LQEcLJB0Ycrg9r+/mOeEfDkeCNtz17KnYulKJRBQ5HQMe96d4HA0gVva9pc0GnT UtuweEtFTRoTkBVQe1WUkrg4GBjcDh6RSMoMJz5eFEdaXP+QwA8P6Ze/Wa0spisppPBO XCzA== X-Forwarded-Encrypted: i=1; AJvYcCWtMYxCrphKXaYkTkAINiSNX29G7TxMOPhvjwmWYVMPQ8Q0fwXybAf2dCX82IL9E9s0REub08XkgA0Riwku@lists.postgresql.org X-Gm-Message-State: AOJu0Yx+Xum0sneQl3L1IHLyd+gndlquXfMg16DLX6uC24G+dp05jgkI lGoQ7p1keQ6bVgJxtyGBlLQkJaU38srOsVJ2O/Eju63sKRv/Lu8rUu223Y9lF5YF3454sCB/WEc t1cKjAH6Q36VsUqWrJ1/brbIPnOjvWcs= X-Gm-Gg: ATEYQzwpcX/2z99hkG1NjCnV5vYB2GbH6fFRcW8ukJmtjaiTenD2oJreFdNI4Op8CoQ YiTdcKyCPsD+tNsGxlxaJDZ0JwnvfPRKAQu3OS9J+Nnh0l0VyhSqk0q6cnOw088a31WG+PvlwLy PUp5Zl0c8r/3KNgW+D+Q1i/TZIumlcC6vcYYrPCopyYPpufeEZVmnNTc3i8XeD8/nhGdxvHzUrn Gk/+jv2HN/FgLxIsF44ZQofeSd0WmwE6akB7wIlRisWUj144EQTehp0zRz2HUUKUcXnklqRJVeP aJ7KH0vHbIhQyfzcbQcxETJwCoTsk1PI2/dnOg== X-Received: by 2002:a05:6512:b99:b0:5a1:34d2:b6db with SMTP id 2adb3069b0e04-5a2ab7e95b7mr4525818e87.1.1774844471757; Sun, 29 Mar 2026 21:21:11 -0700 (PDT) MIME-Version: 1.0 References: <29CA73B2-872A-4D7D-B8E9-D89F76DC18AF@gmail.com> In-Reply-To: <29CA73B2-872A-4D7D-B8E9-D89F76DC18AF@gmail.com> From: Dilip Kumar Date: Mon, 30 Mar 2026 09:50:54 +0530 X-Gm-Features: AQROBzDSq2iAIWoLXb2MTVTBe1aITKN1FpZb8zsq8N5W5jFkEPDbI5iH2Cg-UgU Message-ID: Subject: Re: Avoid multiple SetLatch() calls in procsignal_sigusr1_handler() To: Chao Li Cc: Fujii Masao , "Drouvot, Bertrand" , Bharath Rupireddy , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Mar 30, 2026 at 7:58=E2=80=AFAM Chao Li wr= ote: > > > > > On Mar 30, 2026, at 08:30, Fujii Masao wrote: > > > > On Thu, Mar 9, 2023 at 9:24=E2=80=AFPM Drouvot, Bertrand > > wrote: > >> > >> Hi, > >> > >> On 2/28/23 4:30 PM, Bharath Rupireddy wrote: > >>> Hi, > >>> > >>> Most of the multiplexed SIGUSR1 handlers are setting latch explicitly > >>> when the procsignal_sigusr1_handler() can do that for them at the end= . > >> > >> Right. > >> > >>> These multiplexed handlers are currently being used as SIGUSR1 > >>> handlers, not as independent handlers, so no problem if SetLatch() is > >>> removed from them. > >> > >> Agree, they are only used in procsignal_sigusr1_handler(). > >> > >>> A few others do it right by saying /* latch will be > >>> set by procsignal_sigusr1_handler */. > >> > >> Yeap, so do HandleProcSignalBarrierInterrupt() and HandleLogMemoryCont= extInterrupt(). > >> > >>> Although, calling SetLatch() in > >>> quick succession does no harm (it just returns if the latch was > >>> previously set), it seems unnecessary. > >>> > >> > >> Agree. > > > > While reviewing the patch in [1], I noticed this issue and ended up her= e. > > I agree with the approach and have attached a revised version of the pa= tch. > > > > > >>> I'm attaching a patch that avoids multiple SetLatch() calls. > >>> > >>> Thoughts? > >>> > >> > >> I agree with the idea behind the patch. The thing > >> that worry me a bit is that the changed functions are defined > >> as external and so may produce an impact outside of core pg and I'm > >> not sure that's worth it. > > > > I understand the concern. There's no guarantee that PostgreSQL function= s > > behave identically across major versions, so removing redundant SetLatc= h() > > calls is generally fine. However, as you are concerned, extensions migh= t call > > these functions and implicitly rely on the extra SetLatch(). > > Actually, after reading this patch, I had the same feeling. Today, in cor= e, those handler functions are only called by procsignal_sigusr1_handler(),= but is it possible that they may have other callers in the future? > > IMO, removing the current duplicate SetLatch() calls from the individual = handler functions is fine. But I do not like the idea of adding the comment= "latch will be set by procsignal_sigusr1_handler" to every handler functio= n. My reasons are: > > * When a new handler is added, will it become the standard pattern to add= the same comment everywhere? That seems like extra burden. > * Usually, code readers come to procsignal_sigusr1_handler() first, and t= hen read down into the individual handlers. > * A handler function could, at least in theory, be reused in some other c= ontext where calling SetLatch() would still be necessary. > > So instead of adding the comment everywhere, I would suggest adding one c= omment in procsignal_sigusr1_handler(), something like =E2=80=9Chandlers sh= ould not call SetLatch() themselves=E2=80=9D. If a handler ever needs to be= used in different contexts, then it could take a parameter to decide wheth= er SetLatch() should be called. When the function is called from procsignal= _sigusr1_handler(), that parameter could disable SetLatch(), while other ca= llers could enable it as needed. In other words, the control of not calling= SetLatch() for handlers stays in procsignal_sigusr1_handler(). Shouldn't we add a comment to the handler function header stating that SetLatch should be called by the caller? procsignal_sigusr1_handler() is currently the only caller and handles it, but this would ensure any future callers are responsible for the same. --=20 Regards, Dilip Kumar Google