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 1uuC89-004QRj-EP for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Sep 2025 15:44:10 +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 1uuC88-00HNmB-7s for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Sep 2025 15:44:08 +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 1uuC87-00HNm2-U5 for pgsql-hackers@lists.postgresql.org; Thu, 04 Sep 2025 15:44:08 +0000 Received: from mail-io1-xd2f.google.com ([2607:f8b0:4864:20::d2f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uuC84-000YXM-1t for pgsql-hackers@postgresql.org; Thu, 04 Sep 2025 15:44:07 +0000 Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-88758c2a133so112740239f.0 for ; Thu, 04 Sep 2025 08:44:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757000643; x=1757605443; darn=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=uH5GoaTBRyB7KcBqQJW007sVFYYWWMl/EVhznJc6q9k=; b=EwE69+e2WAjr5Br0bhxrEcXPEO4n0qz+tkoOZiXI1X3KrUlYSIWUvvC1ZuAufIaC/4 MtgU3BaLv7mpMWp4FEyVKnv9v4DJowl4T7QpQBrJtJ00y1HP3G0iiasbc7chTr3+OTWN aB/5C0k565mNVpcOfN+T3X4Wgh6mZQ1TGedL6gOlYjEl3LSZ+bcqTai0WT1sRyefyfD1 eDdS1Rno7DKIv4tG7RjIIy0z6FptW7PWuUQlXV/oONuzIEXhPRXx09LjbpF8GHpQ/ETb vO1UtNPa/KzJ5yJPyy9dkbVuOk1JGJvNRQ9oApn5Hr0W/gr0ubl1TtBeo8tnRK3H7XXm DBVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757000643; x=1757605443; 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=uH5GoaTBRyB7KcBqQJW007sVFYYWWMl/EVhznJc6q9k=; b=VA6VcyyYR0jcLExyOqlVxP8poj3mvAjcvcP446rf9LxZ94WassdHHxvtDLa0vJp9aQ ZNQAeV2SI4ogB+TWBp+nAJ0iu3sqNG/sA03YPXeYFnSE5zlP5fP6mmnPDW8D3BJWr3Is yqTnYKn+FfMTShXZ4We1b7WOxB7yfq71r9e/eQxaraQdJeoLd0hHzQeHs2o8HDBGmF6C yVlUdClcRgvDPKTB3Qev/lG4PIuxxDkTE9O/NDUA6d6obLq/GfgFJ7bhgERlVNcQBPcU lQueCOkl24hSLU1EUvM3yPbLoEAKVQqtn6nUuk0kO0EM3ID/Ze61UPq/b3iKQbFd97bm 7itQ== X-Forwarded-Encrypted: i=1; AJvYcCUXsnsnj/rXSWfCwllTUlBBXS1bWG+DzDsKeEofqtE5g953zWuevTML1y/Oim/ecjSTJkHywsuWD1TPgdDr@postgresql.org X-Gm-Message-State: AOJu0YzP1Jqx8ehubsALzlamcLeCnIC3YMUmhAP0wNa5Y+AD72XXgOFQ rGiiKz5cifK2Ik0mnKGbNm8tLAADRjnDPVHwQvzn2TuOr9ut4aTi2cEP X-Gm-Gg: ASbGncuW0AmliouCG3M9AY0k57fp2UDirZt92fg/mvsHuQg+9D65AYR3jOip8GoTJaI Vthni3SmozH7p8Da4SN19gB7S/xhCoOxpksYe/czmx9cwUxO6qnkos1nEgdx31TmucR7MxtgO/o njXkXP0/chxlYJxQ2YptyNegAwxZn3zGHwq20LY/wXIGL9LiLfGZmJU+vjGumh1sHGh5Ossx0kr 6DqdTNzh3G/1bzORjK4yL7VVVMfwpZZ5V8bNMpdO0PRH3vaDIUlYswWeqA5BofPGCVKlPWD0PnS sYypT8z5wSTaQiuY2F17MvOwLYrJQCTuTNc4xA0gfaH1W89cK9JXHqPwn/CF+QjyW+qBfS7KnK+ Hxs5/FH739YDBkAo9Y3sjSqiGDNvMH53LM33i1DNdFMr5TW0NLyTz585d9l6VYI+6kAnjKHbqbC yKHaCdFfnEdKkT X-Google-Smtp-Source: AGHT+IH+81FIysC9P1D5/agMsHcAb2LHs6ZsmwjF2NG8y9IEmLpG/tT7CPLb1zwr0CLb47RKabjg6g== X-Received: by 2002:a05:6602:2b88:b0:881:7837:6058 with SMTP id ca18e2360f4ac-8871efebec5mr1217192439f.0.1757000643364; Thu, 04 Sep 2025 08:44:03 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-8871e3e7a37sm507607739f.24.2025.09.04.08.44.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Sep 2025 08:44:02 -0700 (PDT) Date: Thu, 4 Sep 2025 10:44:00 -0500 From: Nathan Bossart To: Rahila Syed Cc: Sami Imseih , Bertrand Drouvot , Tom Lane , Andres Freund , pgsql-hackers Subject: Re: Improve LWLock tranche name visibility across backends Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="So++thnogEem4ycW" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --So++thnogEem4ycW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Sep 03, 2025 at 02:01:14PM -0500, Nathan Bossart wrote: > Committed. I'm having some regrets about the changes to RequestNamedLWLockTranche(). Specifically, when it is first called, it immediately allocates an array big enough to hold 256 requests (~17 KB), whereas it used to only allocate space for 16 requests (~1 KB) and resize as needed. Furthermore, the MAX_NAMED_TRANCHES check isn't actually needed because InitializeLWLocks() will do the same check via its calls to LWLockNewTrancheId() for all the named tranche requests. -- nathan --So++thnogEem4ycW Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0001-Revert-some-recent-changes-to-RequestNamedLWLockT.patch From 6fe6590f86427c55ac831c5b48784d3d259fe1c8 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Thu, 4 Sep 2025 10:36:06 -0500 Subject: [PATCH v1 1/1] Revert some recent changes to RequestNamedLWLockTranche(). --- src/backend/storage/lmgr/lwlock.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c index 258cdebd0f5..a5f6b81806d 100644 --- a/src/backend/storage/lmgr/lwlock.c +++ b/src/backend/storage/lmgr/lwlock.c @@ -610,6 +610,7 @@ void RequestNamedLWLockTranche(const char *tranche_name, int num_lwlocks) { NamedLWLockTrancheRequest *request; + static int NamedLWLockTrancheRequestsAllocated; if (!process_shmem_requests_in_progress) elog(FATAL, "cannot request additional LWLocks outside shmem_request_hook"); @@ -628,17 +629,22 @@ RequestNamedLWLockTranche(const char *tranche_name, int num_lwlocks) if (NamedLWLockTrancheRequestArray == NULL) { + NamedLWLockTrancheRequestsAllocated = 16; NamedLWLockTrancheRequestArray = (NamedLWLockTrancheRequest *) MemoryContextAlloc(TopMemoryContext, MAX_NAMED_TRANCHES * sizeof(NamedLWLockTrancheRequest)); } - if (NamedLWLockTrancheRequests >= MAX_NAMED_TRANCHES) - ereport(ERROR, - (errmsg("maximum number of tranches already registered"), - errdetail("No more than %d tranches may be registered.", - MAX_NAMED_TRANCHES))); + if (NamedLWLockTrancheRequests >= NamedLWLockTrancheRequestsAllocated) + { + int i = pg_nextpower2_32(NamedLWLockTrancheRequests + 1); + + NamedLWLockTrancheRequestArray = (NamedLWLockTrancheRequest *) + repalloc(NamedLWLockTrancheRequestArray, + i * sizeof(NamedLWLockTrancheRequest)); + NamedLWLockTrancheRequestsAllocated = i; + } request = &NamedLWLockTrancheRequestArray[NamedLWLockTrancheRequests]; strlcpy(request->tranche_name, tranche_name, NAMEDATALEN); -- 2.39.5 (Apple Git-154) --So++thnogEem4ycW--