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 1w7m5V-005gGK-32 for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Apr 2026 03:17:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w7m5T-00ETrd-0N for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Apr 2026 03:17:47 +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 1w7m5S-00ETrU-2L for pgsql-hackers@lists.postgresql.org; Wed, 01 Apr 2026 03:17:47 +0000 Received: from mail-oo1-xc35.google.com ([2607:f8b0:4864:20::c35]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w7m5P-00000002Hh5-3ChM for pgsql-hackers@lists.postgresql.org; Wed, 01 Apr 2026 03:17:46 +0000 Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-67c2045c0f7so3185239eaf.3 for ; Tue, 31 Mar 2026 20:17:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775013461; cv=none; d=google.com; s=arc-20240605; b=MxCixF+skvNhwrr/Sm/RafMvXmH+JUzOz9H+zo302+oGbdRMDiF/+WhOcXfc7JeuSV VelbS2clGrqrUhWId5j/JoRW/xAqAmzsLgN9/JNgyRCQlso5/rHbUbtkFUvHmM8wfKr7 +DPm7CFOsB8Ofz3V7rxNeuaEvfO7eKkadA2yYRGotOE3ke8J4aoIwjIomp8wilsTZJGO hEtoyJL5oXd5ePbkWldLMGKbsuEmoqsNyrlA5Z419xyRxEx5iG3HP+i39RL3aUdG57Lj nN5ylDwCrqsa7X+nFT0LUiDsLyw16BPqTqJpDxwz+0ZgAWvE5Yefq4ATcBVh70UUmOAK DUNQ== 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=zAS5W4QfynQDAxYeP5IEQrTBiCKzGTLondZv43whi/Y=; fh=c8VJpf+9diccoyK9d1vHwON+LxFH+Wqnfe2Xg6fF3yA=; b=UmTfFe3DajlhxFM7Ups6Seg87O3fRwIVJyGazUlWVHRIsBtgZxtYh92EfKhNqCCoFz 3EmgL8fUS7Lvjkn5NcHHKDdFaMdPWI29kysVpre20iMQvIKeBdOnLybqGBwZY5+o66Xh Bj4ZKhhji4+xffVrM0iuNhVGJR9XFj9juGfKc3YoNAziO9Blh8zCBpTtT1cUC7kBkSg7 Ig3s3hZ2Xw4Jm5PkfL0gAA5cNjtfS8ovu3JNzeshTyTV73xuMgYKzVa2ZPOqzj8F1wdQ URRCuyKjzByu6rFzuKvMpSycIltqWQgrvDDX2z0lEkNGOHXxbDO8IVBi1dwK0zGnZQBr rI2A==; 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=1775013461; x=1775618261; 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=zAS5W4QfynQDAxYeP5IEQrTBiCKzGTLondZv43whi/Y=; b=npJWaBbPRKwPwAm0EzpsUvxm8+lsOZ3+opvn9XX4yr2shiNOUTAwdBH+QimjLFFNM7 PokXvuDr/uC2HYUk6wP/caZ2FaYEooodO45Q5qYqkm8faBz1abKdxnt98AdzlpyKJWBC QXKiZmXOQYOU8Q8azwfDC+ciYOutd0lM2NOuRAcMigOuXbmLYHfmZy/mbz/3DJdIiyKN eGkLkuP3aWHs5RIwuNHuKBbE81pCGRHC9r8cG9Od3iZwtQQs+RywNmfD5yvLkkUxqDLa qlnVll0dDt4V87qAjuJXewJsDR3S6pfwTNUH4ZhTecAU5HLxBegUT6qnqdAj/qcin3vE rdlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775013461; x=1775618261; 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=zAS5W4QfynQDAxYeP5IEQrTBiCKzGTLondZv43whi/Y=; b=fTLGf3y82DnEpWWJSeE5j529iYwGViR9d/m5o59r9ZRnLn9kHQlAp7HzPgyP11Qwh2 xyBjUBG2XKjPrwrOevMekqpXaXaSLM9y4wJZ2C6rj+btRPhxYCKOMbsPkeFH7KY0ulFL Q92C4o7m5DGr0rx6k13ksn2cNtoXz8tbuq9Ma2Exe7FX3mGljNfTOfAYyZS/clQiF58F bR+IRsXbx/HvlBF+CB26CaW3FV1F2oyQvFNeEZI9gS3urHV/+CsgE1K1MOaWTaCT7ou6 uwA8QqRMsSxb5f7wR/SYYUK5EUcOqFsgcSwRMsO7nXlYiN8cqhdLPOmVObEiO9/+rdCc PPQw== X-Forwarded-Encrypted: i=1; AJvYcCVfy4rKk7P7LSwk/soN6wMiN76ZeZsFsq0SknSsqx2AijWKY16PDt1Ll69JWJfTOfzgPbMA8/u1s/Xcfaiu@lists.postgresql.org X-Gm-Message-State: AOJu0YzyJUWi1j06v/3AI9O851xWQU2etp5vzuMuUdwWBC3CwLRJcbd5 Jj4iZOa2fv/L7f3xmHWjcRD4jlH8zERev9OzCrweFQIys9HqlYSQy6lbQa1plmlQsGUy4Y8fJw8 rC7jI4J08q5GboQiQUQ/1e85ucfCxPuo= X-Gm-Gg: ATEYQzwYGUNZ2jrbq2ohd7jXym8JqWBesAGrRE4GqVcGwsFthG0V6FUkpUATCwK5nty ftRZLta63HN6zJRKGj/OrlGgvilOm7ntOG+kEL4tofStIOuW8MBRarQ3aKOoSlXmODtjD8LNLYT yuy3sP2NfPf5S40DWFCYxKLbgBo9MC/TtzAsgb+lJ777wD4qdaItMFQuHYmmBSxz/kxxrP44BX3 GePZax7iOYTNHDPWudY4JoN3sDgpTRVPARAlQ3NeYxxoO0M3jat/TfHnUgkZhlBpE6Zhd/Og2o+ 6rTOZ5ECQSuFS0TlQSLaGNAdsWiXJKIMF3cWcI8= X-Received: by 2002:a05:6820:228c:b0:67b:a667:f53e with SMTP id 006d021491bc7-67fabbd5b1amr908895eaf.1.1775013461365; Tue, 31 Mar 2026 20:17:41 -0700 (PDT) MIME-Version: 1.0 References: <29CA73B2-872A-4D7D-B8E9-D89F76DC18AF@gmail.com> In-Reply-To: From: Fujii Masao Date: Wed, 1 Apr 2026 12:17:28 +0900 X-Gm-Features: AQROBzCrwpAz91s3Zt9S4dgU55nvCEgdFIVCWCIo2xXozTzlW6sbrH3pJ_qy8cI Message-ID: Subject: Re: Avoid multiple SetLatch() calls in procsignal_sigusr1_handler() To: Dilip Kumar Cc: Chao Li , "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 1:21=E2=80=AFPM Dilip Kumar = wrote: > > On Mon, Mar 30, 2026 at 7:58=E2=80=AFAM Chao Li = wrote: > > > > > > > > > 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 explicit= ly > > >>> when the procsignal_sigusr1_handler() can do that for them at the e= nd. > > >> > > >> 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 HandleLogMemoryCo= ntextInterrupt(). > > >> > > >>> 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 h= ere. > > > I agree with the approach and have attached a revised version of the = patch. > > > > > > > > >>> 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 functi= ons > > > behave identically across major versions, so removing redundant SetLa= tch() > > > calls is generally fine. However, as you are concerned, extensions mi= ght call > > > these functions and implicitly rely on the extra SetLatch(). > > > > Actually, after reading this patch, I had the same feeling. Today, in c= ore, 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 individua= l handler functions is fine. But I do not like the idea of adding the comme= nt "latch will be set by procsignal_sigusr1_handler" to every handler funct= ion. My reasons are: > > > > * When a new handler is added, will it become the standard pattern to a= dd the same comment everywhere? That seems like extra burden. > > * Usually, code readers come to procsignal_sigusr1_handler() first, and= then read down into the individual handlers. > > * A handler function could, at least in theory, be reused in some other= context where calling SetLatch() would still be necessary. > > > > So instead of adding the comment everywhere, I would suggest adding one= comment in procsignal_sigusr1_handler(), something like =E2=80=9Chandlers = should 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 whe= ther SetLatch() should be called. When the function is called from procsign= al_sigusr1_handler(), that parameter could disable SetLatch(), while other = callers could enable it as needed. In other words, the control of not calli= ng 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. I *guess* the original comment was added because readers of the interrupt handling code might just wonder why SetLatch() isn't called. If so, it make= s sense to keep that explanation in the handler functions themselves. The existing comment seems sufficient to me. The code isn't complicated eno= ugh to require more comment for future use of functions in advance, and we can revisit it if the functions change in the future. Based on this, I'm thinki= ng to commit v2 patch. Regards, --=20 Fujii Masao