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 1w9Pye-001Pue-05 for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Apr 2026 16:05:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w9Pyc-003n0k-0I for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Apr 2026 16:05:30 +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 1w9Pyb-003n0c-2S for pgsql-hackers@lists.postgresql.org; Sun, 05 Apr 2026 16:05:30 +0000 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w9PyZ-00000000kaA-1XWX for pgsql-hackers@postgresql.org; Sun, 05 Apr 2026 16:05:29 +0000 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-66c304dbfd2so2262218a12.0 for ; Sun, 05 Apr 2026 09:05:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775405126; cv=none; d=google.com; s=arc-20240605; b=XuTY7WhWEn6DtoN+3Kto+EEA94LI+k4PnRAEl3SQsDr/rewtDh3Cf66kmzgzwLnGDx HOMO7KEfvUZoGThgps5pLZAOEOZ4HmVBPnNs7JPR8/hRo2yyYgIavlrOZjcdUXyAReuI m5rgPELOqMbwFd3sp8j/a2v2pnPlQxTm0mPyW3YnAgf7Q2I1kfMHlXZXIB7SSPSvMKvY oq7QRfYW0KrNJVDsa1poL9AXtWE1I7MFisVPe+GFF22C/xpIF1gl34HDmMGtGmc7urPV jCjZ0f6CUolA+SYbng82FaPeVpQfGm2SdhKmK59o6u1A+NbutiJ90BWxvx0tilsl8OLk vnPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=wnd63OyppEbjOvvjwBYE/FSmEt8z5vRw/uwftTbtxkQ=; fh=yOrL0mqLfVYRHcW34ZK5GwNSUjt9I4XLzyxQWI/7NQc=; b=GKRFvdU+mGo+PDbAKCUzTW1xgXjUVTadQeBgsQ5NxUbDEJzBV188rpknjmzKezCdQ/ gtgo9WjPoXjqeH+QXbv0mHEChecRtW8uE//an73jcAmjjPnjTNjfsQWHofIzsDQprRll Bo7ta+jSkS7GrXcM5KTB62/rkzZEPYjoox+w8GFh7X74hS4UuophRsJvDo/zUh33QNf4 RucAoWLuvRP9HxpT399H7iITpOUq29j4spq13ZiY1i38dOUuB9LIxeLqnhQPG4e/clVc V0JBDNGhs8FQXLoQNza21ftwlhesj0s20A7Yg62EWCuRhEXKl7nWfEl2m5741vaqg2Ff yo2Q==; darn=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=1775405126; x=1776009926; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=wnd63OyppEbjOvvjwBYE/FSmEt8z5vRw/uwftTbtxkQ=; b=fnFggncHTdNIEc/bGYzzvaDiwhI6XXSgMHdLLTmx+63dKnWZH4ctFmYPBejzA32lme Gb2Cs7a9S5MKyFgkBW2ffZvpTUmn/qxzY+HHwjISKBR68GEX9PhIlpwlV1zv9PHeJxDE EhE4GVnckUQZL1JM5+rkt+7ipsTAxZq4szVdsVs2si1dlxxoQt0hgrpcdlAxYLjqG4YL y9Nik9dat7bfCmDR4WmYpu0N0fl+AQXhXNgac7x6RcWvYrU6IyIAnAOvAjfqfJEhjjcG zAxTTgIZMcNmoFxpmREak2vSP6Y0o9/r1SxId/6Vukc/LbZ7sjeYASH4SaBmMNngrhgT lK4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775405126; x=1776009926; h=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=wnd63OyppEbjOvvjwBYE/FSmEt8z5vRw/uwftTbtxkQ=; b=IY67onb/eYP6rTacvErSfs8/gvVL15/xdONpSHKp4cB7RNpf97ywuEQpIQI1LYUqLP cWH6p/05DWCIOutEfJC0VjSbKpyYKDbIvFim6Q4fVXzhF4IBIjuL6NHLCLib8pg+5dnz rT0gBTJTr5275c8LOCJZleNOzNCEloUxDhggO4nvi+bVx8ZuDG8VC7GBQLyuqBSuk7vM YnQW0XXu25D2A4ujlLwXQcfXiXtriJOH6MVlHrUHA0a/ymPaxWhPAlRRgbozcZDLC3yf kvTaLL03EhlK/RGb1c3rSmXatqwe8zWlVmvEVYe4GtV8FnftwO1Hj6sLbwgqUSCua9Z5 1oRg== X-Forwarded-Encrypted: i=1; AJvYcCUBjx3L0Sl42RRN5Uoez+deaLoegKq/d6i8xSRrqNDodnG/yO2yGeJTH+07MBJ/xhlexJ+0wREMEYdYcaeI@postgresql.org X-Gm-Message-State: AOJu0YxKkNWg049EeNRXwiJ1arul5otfFl17DnZxlfnLQhRkOCv1QG4h licU9hZL+B23f5KfYKYtggVxeAT+hIfDGuNDn9sQNGMl3p79A96b62a3KsNpp4yqkVZ+d9Tjnrc qKcC+1/88TeVQgWLwMe23mvA4G4zPsUg= X-Gm-Gg: AeBDietd6BP11bCPYMyxOfE7PW7Yagv2SJ0Qo7C+24kM3byYAzwXzccJvfeIZccGxLH KZhhz1r8UK3looMMQ6cTUyCdoIoYrbL2TZ7ZuKd8IDoafbsdRI+LjrpxxK5/LX7e3e+JvehVCbU SAlqKP3rEPpQXMOAUaTn1BeAbFKScoUgk3aAz9oqLFdeuBakYjbzOMuozYL0hZZ7veqo+v5CkCy 73offksRsIyx6emJBh01cOzHz2OpLfyIERKpFv1kGHwx11HWZcNn42zkILMePtxUs1kmDquJF3E zDP+EW5jMuzAtA== X-Received: by 2002:a05:6402:278d:b0:66e:aade:1a0e with SMTP id 4fb4d7f45d1cf-66eaade20a6mr1503270a12.10.1775405126030; Sun, 05 Apr 2026 09:05:26 -0700 (PDT) MIME-Version: 1.0 References: <463a28db-0c0b-4af6-bac6-3891828bbbfe@iki.fi> In-Reply-To: <463a28db-0c0b-4af6-bac6-3891828bbbfe@iki.fi> From: Sami Imseih Date: Sun, 5 Apr 2026 11:05:14 -0500 X-Gm-Features: AQROBzDzONxcOqY68BoQ_KurUZgrX8iRuNrU1wlRW8yetq3A2U0LxN1Awkqq6Ls Message-ID: Subject: Re: Duplicate RequestNamedLWLocktranche() names and test_lwlock_tranches improvements To: Heikki Linnakangas Cc: Matthias van de Meent , Nathan Bossart , "pgsql-hackers@postgresql.org" Content-Type: multipart/alternative; boundary="000000000000de9891064eb8b71e" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000de9891064eb8b71e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > Starting new thread for this thing that Matthias noticed in my > work-in-progress patch at > > https://www.postgresql.org/message-id/CAEze2WjgCROMMXY0+j8FFdm3iFcr7By-+6= Mwiz=3DPgGSEydiW3A@mail.gmail.com > . > > On 05/04/2026 02:17, Matthias van de Meent wrote: > > 0006: I don't think it is a great idea to make the LwLock machinery > > the first to get allocation requests: > > It has the RequestNamedLWLockTranche infrastructure, which can only > > register new requests while process_shmem_requests_in_progress, and > > making it request its memory ahead of everything else is likely to > > cause an undersized tranche to be allocated. You could make sure that > > this isn't an issue by maintaining a flag in lwlock.c that's set when > > the shmem request is made (and reset on shmem exit), which must be > > false when RequestNamedLWLockTranche() is called, and if not then it > > should throw an error. > > Good catch, RequestNamedLWLocktranche() was quite broken with the patch. > I'm surprised it didn't cause test failures. We even have unit tests for > that at src/test/modules/test_lwlock_tranches. > > Looking at src/test/modules/test_lwlock_tranches, I realized that we > don't currently check that the tranche name registered with > RequestNamedLWLocktranche() is unique. If two extensions registered a > tranche with same name, we'd allocate two separate tranches for them, > but GetNamedLWLockTranche() would always return the first one. Yes, while that is not very likely scenario, it=E2=80=99s wrong. The caller= will get the wrong pointer to the locks. > > > Attached patches add a uniqueness check, and improves > test_lwlock_tranches so that it actually uses the requested LWLocks. And > I couldn't resist doing some more refactoring of the test while I was at > it; IMO it's more readable now. > > Barring objections, I will commit these shortly. > LGTM -- Sami Imseih Amazon Web Services (AWS) --000000000000de9891064eb8b71e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Starting new thread for this thing that Matthias no= ticed in my
work-in-progress patch at
https://www.postgresql.org/message-id/CAEze2WjgCROMMXY0+j8FFdm3iFcr7B= y-+6Mwiz=3DPgGSEydiW3A@mail.gmail.com.

On 05/04/2026 02:17, Matthias van de Meent wrote:
> 0006: I don't think it is a great idea to make the LwLock machiner= y
> the first to get allocation requests:
> It has the RequestNamedLWLockTranche infrastructure, which can only > register new requests while process_shmem_requests_in_progress, and > making it request its memory ahead of everything else is likely to
> cause an undersized tranche to be allocated. You could make sure that<= br> > this isn't an issue by maintaining a flag in lwlock.c that's s= et when
> the shmem request is made (and reset on shmem exit), which must be
> false when RequestNamedLWLockTranche() is called, and if not then it > should throw an error.

Good catch, RequestNamedLWLocktranche() was quite broken with the patch. I'm surprised it didn't cause test failures. We even have unit test= s for
that at src/test/modules/test_lwlock_tranches.

Looking at src/test/modules/test_lwlock_tranches, I realized that we
don't currently check that the tranche name registered with
RequestNamedLWLocktranche() is unique. If two extensions registered a
tranche with same name, we'd allocate two separate tranches for them, <= br> but GetNamedLWLockTranche() would always return the first one.
=

Yes, while that is not very l= ikely scenario, it=E2=80=99s wrong. The caller will get the wrong pointer t= o the locks.


Attached patches add a uniqueness check, and improves
test_lwlock_tranches so that it actually uses the requested LWLocks. And I couldn't resist doing some more refactoring of the test while I was a= t
it; IMO it's more readable now.

Barring objections, I will commit these shortly.

LGTM

--
Sami Imseih
Amazon Web Services = (AWS)

=


--000000000000de9891064eb8b71e--