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 1vffrl-00407a-2q for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Jan 2026 14:59:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vffrl-005KeG-0D for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Jan 2026 14:59:29 +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.96) (envelope-from ) id 1vffrk-005Ke8-24 for pgsql-hackers@lists.postgresql.org; Tue, 13 Jan 2026 14:59:28 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vffri-000Dho-1J for pgsql-hackers@postgresql.org; Tue, 13 Jan 2026 14:59:27 +0000 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-64b791b5584so12601552a12.0 for ; Tue, 13 Jan 2026 06:59:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768316364; x=1768921164; darn=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=sjAsXth9sP7nsHeUdNdR8jZGc6Bc2mZlcdYEH+WjyMU=; b=CdyuMkvgk4o5/OBkzTMa+H0wSCHliSa4Fj/dpmC9KLMgCGJjVAwau4So1hZNOjtY7Z LJsFJY4lWc3Sf0K8moKd2RzR0FxxfoxhmyJkw4E/81IIuAve7lyQzYYstxZ/Si5WQMjz 9fWuF2CuGAN/QlbVN7MBGJM4ptrdv0NwK1MOc5TPF5tQ1oiippzozCz3wxn+on1XPoys hw4z+WIu2+SEOLY0nCatTKSThxDVoaVsuLWzid/c7AEtFANNRdYbHi3hcs7TedRz6GKY o2rvYt2F+Ohkq4D0iR9mRRgjqYq0boyVbC96EhLahubeiQ1azmQAWwO804CdXeVr8+S9 nGVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768316364; x=1768921164; 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=sjAsXth9sP7nsHeUdNdR8jZGc6Bc2mZlcdYEH+WjyMU=; b=trMc7kZfB8wmuGp8gYERnVsZFms8xyoDQn2WyTdZOasMKG8DhEdWHTmfxwPCbyKIMg P1IN10Az83Y9TmyLNPduUIGKCWiXmIOER700Mwro/cuXlEIdvd26tjtlrGAg4p37rtzF /OFOgiKa5j3hOJ4MwiaocSHr1MOxlqh9PtzJpOmOojN1Qlbo3jgE3I0He2k/M9m2A4k6 njNqpQkAYmTO8UGuv7/DAD1uWFGm+qWF+ny2gdFWFiyZV8pB9laH/GbCAza8iFU+Bit1 RMGWfh9D/JohYLTelnIVjSdJWAxCd1FJD7rb/01SUvRa2QWh/0DKK6gccFiv/Yb6Ugc7 3xHw== X-Forwarded-Encrypted: i=1; AJvYcCWLO1sM49Vob1kAMPaUnHJD2/pYU1RchWejr72ajZqsIf2pEuSSoI3v7ONd4CHRUlJHZYsY5yPgSZdI4fge@postgresql.org X-Gm-Message-State: AOJu0Yz69lP4Hewm9fzh3wrfAq5jBlaCvHzzaZtmnbWFsWUaJN364z9i 2qsgsdDCfkEPEmdPXoL48rWkvfeF8Op9CuPIi0HmfSvYtcu0lmn1/CDSiWUss2OtxkkvygxIpNK ckj3htu/tMm+RP65Zmum17AevC17cxRI= X-Gm-Gg: AY/fxX4Qt94XcURWOXBJ7pjWHWNo7qPePK+kK77LpkucuAcrqAGtaVKFg1HPuPl1XsW A/kQcCTfMcxHlOPYzsNRkcYCKWiCUHhVL3hNAHFbp2MiCc2jssLM07ypg0yZx96Rd7xDqQssmYk qwwpq4krrNYN3sh3OadWsYorHkB/t6R8irEKYPcqIXzX3FOKRjGDOiaYxgEslA/xat0wCZHaUw9 lMDxcD7XNFSFkcT4nclD2q2CW598g9iBg7cfuYQBdaxJTkRED4Ui9HqiCIpkWccFlRjDgCydguj M23+UAtdp5VR5+odq3wqGhT5nvy+Qaikc4ZywiE= X-Google-Smtp-Source: AGHT+IHk7JtaT6vqh09Z6EyjGxJD/Sr44jfcp8SHtUJlEQcfqMkJ7Kr1ERCA3V4DTsyCh/8tT7ByL2GVhNaNiWScwD4= X-Received: by 2002:a17:906:478c:b0:b87:3b:12ab with SMTP id a640c23a62f3a-b87003b3a7dmr974768166b.17.1768316364247; Tue, 13 Jan 2026 06:59:24 -0800 (PST) MIME-Version: 1.0 References: <1108f18d-cf7c-4f17-b29c-a119fe42f7e5@iki.fi> <5dwlfu2jyzkyf3nrlzxxblxctb6xio5es73ptgsahjnmfu5miu@772rc764hfhi> <4csodkvvfbfloxxjlkgsnl2lgfv2mtzdl7phqzd4jxjadxm4o5@usw7feyb5bzf> In-Reply-To: From: Melanie Plageman Date: Tue, 13 Jan 2026 09:59:12 -0500 X-Gm-Features: AZwV_Qh0IPha7_fcDqtPNlc7s8dA8HNgC1kcZHKe_2sP-OxTy4TR2G1U3o_epL4 Message-ID: Subject: Re: Buffer locking is special (hints, checksums, AIO writes) To: Andres Freund Cc: Kirill Reshke , Heikki Linnakangas , Matthias van de Meent , pgsql-hackers@postgresql.org, Thomas Munro , Noah Misch , Robert Haas , Michael Paquier 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, Jan 12, 2026 at 6:22=E2=80=AFPM Andres Freund = wrote: > > Is this better? > lwlock: Invert meaning of LW_FLAG_RELEASE_OK > > Previously, a flag was set to indicate that a lock release should wak= e up > waiters. Since waking waiters is the default behavior in the majority= of > cases, this logic has been inverted. The new LW_FLAG_WAKE_IN_PROGRESS= flag is > now set iff wakeups are explicitly inhibited. I think what you have would work for most people. The key thing for me is that the wakeups are inhibited _because_ someone else is already awake. So, you don't have to wake anyone up when you release the lock because there is already someone awake. Having you explain that off-list was necessary for me to bridge the gap between RELEASE_NOT_OK and WAKE_IN_PROGRESS. And I do agree that WAKE_IN_PROGRESS is more descriptive of when the flag is actually set. RELEASE_NOT_OK doesn't explain the state or who/when it should be set. > > I wondered why this was needed (i.e. why it wasn't needed before) > > > @@ -6688,7 +7428,25 @@ ResOwnerReleaseBufferPin(Datum res) > > if (BufferIsLocal(buffer)) > > UnpinLocalBufferNoOwner(buffer); > > else > > + { > > + PrivateRefCountEntry *ref; > > + > > + ref =3D GetPrivateRefCountEntry(buffer, false); > > + > > + /* > > + * If the buffer was locked at the time of the resowner releas= e, > > + * release the lock now. This should only happen after errors. > > + */ > > + if (ref->data.lockmode !=3D BUFFER_LOCK_UNLOCK) > > + { > > + BufferDesc *buf =3D GetBufferDescriptor(buffer - 1); > > + > > + HOLD_INTERRUPTS(); /* match the upcoming RESUME_INTERRU= PTS */ > > + BufferLockUnlock(buffer, buf); > > + } > > + > > UnpinBufferNoOwner(GetBufferDescriptor(buffer - 1)); > > + } > > } > > It's needed because previously content locks were released as part of the > LWLockReleaseAll() that are sprinkled across various error recovery paths= . Now > that content locks aren't implemented via lwlocks anymore, something new = is needed. And all those LWLockReleaseAll()s are still needed because we might hold other LWLocks even though we won't hold them for buffer content access? > > + /* XXX: combine with fetch_and above? */ > > + UnlockBufHdr(buf_hdr); > > > > Are you thinking about adding a helper that stops waiting and unlocks? > > I'm not sure what you mean by that? Just whether I plan to implement the > FIXME? I was trying to figure out why you left it as a FIXME and didn't just do it or not do it. I thought maybe it was because you weren't sure if you wanted to add another helper in addition to UnlockBufHdr(). > > bufmgr.c is super long anyway, so it's not like making it separate > > makes the file manageable. On the other hand, it's probably better to > > not keep making it worse. > > Yea. OTOH I don't know if a header that's just included by one file is re= ally > an improvement :/ Yea, I suppose that is a bit odd. Though it could be a pattern you start for organizing gigantic files. I'm overall a +0.7 unless you explain some other downsides than oddity. - Melanie