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 1uuAN5-003lWa-T9 for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Sep 2025 13:51:28 +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 1uuAN4-00GKNm-Hh for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Sep 2025 13:51:26 +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 1uuAN4-00GKMy-83 for pgsql-hackers@lists.postgresql.org; Thu, 04 Sep 2025 13:51:26 +0000 Received: from mail-il1-x12b.google.com ([2607:f8b0:4864:20::12b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uuAN2-000Vy4-28 for pgsql-hackers@postgresql.org; Thu, 04 Sep 2025 13:51:25 +0000 Received: by mail-il1-x12b.google.com with SMTP id e9e14a558f8ab-3f0651cb8aeso10493755ab.3 for ; Thu, 04 Sep 2025 06:51:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756993884; x=1757598684; 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=vhqHLbvEQhK45n7yI7u9XopNib+4/Io8MvLJcjnAG6M=; b=kRF8xUw5X9Z5/seocBXjdMO0LpeUSE3jk8T248Bt2YD23dQoUWZr2ONhQQdfML3V7j 1FdbBHqnm28DNNKkNh7B1SF9s1G4ydgnI57pzFSsACZ5atzldnAIJK5thsCyF0wl+syY a/QkrjoY9wd0k8ZPCeiLpiyaUczZd+hAjIwkgBiIAXto3jl3fXrz0fCVtfltKueea+f1 5J35CjEbeeCM4OXo9CvxPWuQk3hgpZss6rCf4VLS/LE1wsf3GQQ8G4WaQBjX+v4Vhx1K 4z5U5CGWbAZwIC0bPWM6Wha44I5Zz8TkBYuFMLYbdtPdmrTydsQFN1zw3dLiJzp1N2vy /b/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756993884; x=1757598684; 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=vhqHLbvEQhK45n7yI7u9XopNib+4/Io8MvLJcjnAG6M=; b=v8jJHDM3QiFgM81ASsRB3DH1xrH8dKM0u0frgo/enVA66Gx9z5oKgG7fU3nZXCNnQX 0X/JdISmr1ojJFO83U9IFUwIyI7GYRoOu9oGmWDVlRxsUeYTjDsy+oKg1Bjzsl5N60lB /5D8LYNIoLq7fNJT4SIAdlBEY8VthZQjGZ9EReipxCZ1vK89PfKkx3QmNmCT506MfV00 NENAfQnoaAEwy1BVtIfTXsh7frjKFK9mc0oA4kB94X+XYva22zAim+pjqi5IcKapJ8sH hc+t5tJdY+L0WCZqnpSU5r+b5uGq7V1g3umH0cS+labkJ+kByu+5uWJu0xHG8F7O5NH7 5OVQ== X-Forwarded-Encrypted: i=1; AJvYcCVtndTB3iaceOnrNCqT5G/1tRLtFayhDfLC9xt5pgWcSUZKWMbxfa8jaKnYMbqNFiK8BAzRPyptCk73mgOz@postgresql.org X-Gm-Message-State: AOJu0Yzgw7thAtnn/IeuUXsIY/mxfW4SzNDI1wZUEf9xLaC88lCAt6e2 AflIl6Uj/d+CuzYjl3V6MF+GhutKIjupup2vlWzcfuTIQfLdd3E9kFWK X-Gm-Gg: ASbGncsfXF96Ht5gG6Xrdf6KDLGqDlrLu7sozAXXaHzFA70pRUcAXmiSc0Bij3h2PQx LnVBfkm/IFZg0BV49rMs34uhZsUVnlx5Llrl28+sITbpskGe1d9INw/LA1RTCgnetyL2/mhVTgt Wy3Qp3YAAjaJ3q72HBFs9Ko0aCUjFHAmkEI2PE9M7LVGA3FBMA1bTTDQRpOXl/KgBbCzDyPdnrJ MUg86/diSxMgz7zTKplcaEZUE4g8VKNrOIme0OBTdAZQEX5l3iJFimVrjANNVZgIgoiQF+kI29N bFxNxqYfrkNP3UUAMlaYF/9mDXgvQ7J5p0jz8w6FU92YZC7Kk2qzGrLyzN+Zu9/dz3S1cwqfnyJ aJHLp1g6coalpIHR2wfHNb8ewoslqXKDIAICpUDHVF+e4+0x94Ok5gLl0ZdGrRtHGUZETFwiA75 kZMgfb3IVJwRPN X-Google-Smtp-Source: AGHT+IE/UoWEGZzmtH7KmzqrWksCzszgmZH/tuXZeGW+GLqW17vDCLs0lAbqolZhIVVJ6lZdCpLFJg== X-Received: by 2002:a05:6e02:160a:b0:3ee:8e4b:e6db with SMTP id e9e14a558f8ab-3f40028ab8fmr343876975ab.12.1756993883765; Thu, 04 Sep 2025 06:51:23 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-50d8f32051dsm5163433173.54.2025.09.04.06.51.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Sep 2025 06:51:23 -0700 (PDT) Date: Thu, 4 Sep 2025 08:51:21 -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: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Sep 04, 2025 at 03:29:52PM +0530, Rahila Syed wrote: > Since updates to LocalLWLockCounter and LWLockTrancheNames are performed > while holding the lock, but reading LocalLWLockCounter and then > LWLockTrancheNames in GetLWTrancheName can occur without acquiring the > same lock in case trancheID < LocalLWLockCounter, There is a small window > between updating LocalLWLockCounter and adding the name to > LWLockTrancheNames. During this window, if GetLWTrancheNames is called, > it might attempt to access a name in LWLockTrancheNames that hasn't been > added yet. We hold the lock when reading/writing the shared-memory LWLockCounter. There's no need to take a lock when reading the backend-local LocalLWLockCounter, as it can't be modified by any other process. Additionally, when adding a new tranche name, we hold the lock the entire time while we bump the shared-memory counter and copy the name, so there's no chance another backend will see the counter update but not the name or attempt to use the same LWLockTrancheNames slot. -- nathan