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 1vFUse-00CTXK-S2 for pgsql-hackers@arkaria.postgresql.org; Sun, 02 Nov 2025 10:00:12 +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 1vFUsb-00AKTG-Qe for pgsql-hackers@arkaria.postgresql.org; Sun, 02 Nov 2025 10:00:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vFUsb-00AKT2-Gr for pgsql-hackers@lists.postgresql.org; Sun, 02 Nov 2025 10:00:08 +0000 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vFUsY-0051jf-2z for pgsql-hackers@postgresql.org; Sun, 02 Nov 2025 10:00:07 +0000 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-57bd04f2e84so4364251e87.1 for ; Sun, 02 Nov 2025 02:00:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762077603; x=1762682403; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=oSqmc0rSf/mFYfe7Q6dSBI1GqOEyXiSI+NC1Uyatx/M=; b=RQe17Yp+atANJBkI5f3f/PjumR5SnqY7WlaIR4yLSPifuSY2xbNlAGgUm5TWL1GK1q miC4oC10UxWG4Wh/UvtX7fVtomzA7GCo6UcUXAYvcKhj1vKdXKrUBSH6L4+mDPpYQFnT 9mldIuqZ7bx5fyRLtT8L+xXpUYJReThsu11GM618IYluxNi68htPd1I/MT6UBaEdwHfg JDLhdDY67lRhydPrzZc6D3iJtYoLwLiauIoHzqiZj0daO7b6+743s+FiFFss/nzca8kX ZYUNVXgwQvvqUYqLlBE+VUy0dIfjaaJWlvGnLH6MIk1A446ZSIxk0BioBVRd1xZ83y7h +vuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762077603; x=1762682403; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oSqmc0rSf/mFYfe7Q6dSBI1GqOEyXiSI+NC1Uyatx/M=; b=m1yQ30d04tZFKzikV2N24NXCvfDQc6QUhsT/QQ5Ql4qXJnPv6bqDLgES1vrrYxr7oO dUJrmXRkM7nk7NTTUQmaGc9xN2JGSKProoINYbu9zai/xedRuXPLn/EmY5X6748v6o7q UrFpR3LvYoR8+LPRLWVrwMwRNuDlFk9xdwKFZKHE40oCV0L0kn7JyxqiFGZpvIAcrAGe LxtS8Ndz3YBJfoGS4ygxEcKXeqyVFq/hjuQAhqQr+59zWsY0bpS2lWRJePutBBYtGZ7N p6UScXnWxRuOsC+IRd0VB12nu5O2v6oYYw1WT6jXwiY1I6GLDhEuc8wHLBVcVOpXO4Be RV/Q== X-Forwarded-Encrypted: i=1; AJvYcCUQJCnz9XWtNAqc8wN5plTQdbK6bPYIwoFIoRnEhGd78kJgoRpNCcW8O23syewPlgwbbQ+iHr1oTdAqN2Mn@postgresql.org X-Gm-Message-State: AOJu0YzA9J1xaUYWxh/n80hLMd63Ip5JQfwqPLWAQVGa0EGDF4jkiW8z 8fXZIA1d9UCNMogoGKy/yKyl2qUOfhgI1UIk/LUUcsYvZwh0VR7bz8lZ X-Gm-Gg: ASbGncv08DczL5QMn27usYmDtmvfUIn4cFqt/VlvAD/9CvQW+iTxuhYNQ5Y5VJROmpb 1p+nnblNv2lxeFqS9Nj5CjmDu3Wv2atfKJupI2vr2mDTr4P2w2lZncY/XTTNM1WofRaopZkjck9 HaeiljkcDfkW9KSFx+C08HS5MkDJAUxy6b3XfUiYnVI4tgKkg8tiU6lfuPpydtTo0W4QZ1RfJw5 bpGKrSa2onupJz3av9waoksg7pWD92JKxlWOH6zQsBiuiVERnPd7FzPAX5plCfJZ1AHWcspabdz WHhI66+m04kWgYZFBWkW3LBa6QV0z3BvLTaF1nuZmOf10M/qznQiGpJmZ/HlrhXFLdsNLHfokKz PlgqB+4FftclF4K7N+Lp+9qKoRK7glP+eaoJ66YY+Z4dcTvLLPkNo7pKEHFS+An1uAhMlczlTsN NgKDs= X-Google-Smtp-Source: AGHT+IHTJfbB0+gOX5wJgyQsChGaO1yJpw7/4jGhO+snmxaG1/KC3GyNIf3ILIxKfjqVmhUb0XttDg== X-Received: by 2002:a05:6512:234c:b0:583:b32d:a9c8 with SMTP id 2adb3069b0e04-5941d4fec2amr3209936e87.2.1762077602954; Sun, 02 Nov 2025 02:00:02 -0800 (PST) Received: from [192.168.0.50] ([89.149.120.198]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-594294f0130sm419385e87.69.2025.11.02.02.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 02 Nov 2025 02:00:02 -0800 (PST) Message-ID: Date: Sun, 2 Nov 2025 12:00:00 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Improve LWLock tranche name visibility across backends To: Nathan Bossart , Sami Imseih Cc: Rahila Syed , Bertrand Drouvot , Tom Lane , Andres Freund , pgsql-hackers References: Content-Language: en-US From: Alexander Lakhin In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello Nathan, 04.09.2025 23:37, Nathan Bossart wrote: > On Thu, Sep 04, 2025 at 12:30:27PM -0500, Sami Imseih wrote: >> I liked removing the repalloc calls inside this routine and did not think >> it was worth optimizing. I am OK with reverting it back. Although v1 >> is incorrect since it's still initializing >> NamedLWLockTrancheRequestArray to MAX_NAMED_TRANCHES > Committed with that fix. > >>> 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. >> I thought about that one and decided to add the error message there, since >> requesting a tranche happens way before LWLockNewTrancheId is called >> during CreateLWLocks, so it was more about erroring out slightly earlier. >> But it may be ok to also just remove it. > We needed it before because the array could only ever hold > MAX_NAMED_TRANCHES requests. I've discovered (with SQLsmith) that the new possible error makes pg_prewarm/autoprewarm fail when the error triggered during it's initialization and then another instance tries to acquire apw_state->lock. Please try the following: psql -c "CREATE EXTENSION test_dsa; CREATE EXTENSION pg_prewarm;" psql -c "SELECT test_dsa_resowners() FROM generate_series(1, 256)" >/dev/null psql -c "SELECT pg_sleep(0.5); SELECT autoprewarm_dump_now()" & psql -c "SELECT pg_sleep(1); SELECT autoprewarm_dump_now()" with debug_parallel_query = 'on' min_dynamic_shared_memory = '1GB' in postgresql.conf it causes PANIC for me (on roughly 5 out or 10 runs) as below: CREATE EXTENSION CREATE EXTENSION  pg_sleep ---------- (1 row) ERROR:  maximum number of tranches already registered DETAIL:  No more than 256 tranches may be registered.  pg_sleep ---------- (1 row) server closed the connection unexpectedly         This probably means the server terminated abnormally         before or while processing the request. PANIC:  stuck spinlock detected at LWLockWaitListLock, lwlock.c:882 ... #5  0x000057831e809d1d in errfinish (filename=0x57831ea53edd "s_lock.c", lineno=89, funcname=0x57831ea53ee8 <__func__.0> "s_lock_stuck") at elog.c:609 #6  0x000057831e5f2185 in s_lock_stuck (file=0x57831ea5184c "lwlock.c", line=882, func=0x57831ea51c30 <__func__.5> "LWLockWaitListLock") at s_lock.c:89 #7  0x000057831e5f2291 in perform_spin_delay (status=0x7ffdf9fabbe0) at s_lock.c:135 #8  0x000057831e5e4015 in LWLockWaitListLock (lock=0x736a16ad6500) at lwlock.c:886 #9  0x000057831e5e4475 in LWLockQueueSelf (lock=0x736a16ad6500, mode=LW_EXCLUSIVE) at lwlock.c:1055 #10 0x000057831e5e4728 in LWLockAcquire (lock=0x736a16ad6500, mode=LW_EXCLUSIVE) at lwlock.c:1259 #11 0x0000736a63dbcc82 in apw_dump_now (is_bgworker=false, dump_unlogged=true) at autoprewarm.c:676 #12 0x0000736a63dbd5c9 in autoprewarm_dump_now (fcinfo=0x57835c770fe8) at autoprewarm.c:854 ... Best regards, Alexander