Re: BgBufferSync(): clarification about reusable_buffers variable

From: Aidar Imamov <imamovaj22(at)gmail(dot)com>
To: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
Cc: Xuneng Zhou <xunengzhou(at)gmail(dot)com>, mvdholst(at)gmail(dot)com, tgl(at)sss(dot)pgh(dot)pa(dot)us, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: BgBufferSync(): clarification about reusable_buffers variable
Date: 2026-09-07 19:59:22
Message-ID: F327EAD0-A49A-4413-8399-EA297600E3FE@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I went through this part of BgBufferSync() as well, and I agree the
patch is a nice improvement. Hoisting the reusable_buffers++
out of the two branches makes the real condition (BUF_REUSABLE)
explicit, and the Assert captures a real invariant of this call path:
since we pass skip_recently_used = true, SyncOneBuffer() can only
return BUF_WRITTEN together with BUF_REUSABLE, never alone.

Just a small wording nit on the comment. As written,

/*
* We instructed SyncOneBuffer not to write a recently used
* buffer.
*/
Assert(sync_state & BUF_REUSABLE);

it states the precondition rather than the invariant the Assert is
actually checking. I'd find it easier to read if it said the consequence directly, e.g.

/*
* skip_recently_used is true, so SyncOneBuffer() only writes a
* buffer when it's reusable (refcount 0 and usage count 0).
*/
Assert(sync_state & BUF_REUSABLE);

Purely cosmetic, of course, the patch is correct either way.

With or without that tweak, it looks good to me.

Regards,
Aidar Imamov

> On Aug 17, 2026, at 19:58, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com> wrote:
>
> On Mon, Aug 17, 2026 at 9:42 PM Ashutosh Bapat
> <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com> wrote:
>>
>> On Mon, May 5, 2025 at 7:07 PM Xuneng Zhou <xunengzhou(at)gmail(dot)com> wrote:
>>>
>>> Here's a rebase.
>>
>> Sorry for a very delayed response. Adding this to the next commitfest
>> so as not to forget it again.
>
> And rebased as required by CFBot. No actual conflict.
>
> --
> Best Wishes,
> Ashutosh Bapat
> <v20260817-0001-BgBufferSync-refactor-reusable_buffers-inc.patch>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bharath Rupireddy 2026-09-07 20:56:00 Re: Use WALReadFromBuffers in more places
Previous Message Peter Eisentraut 2026-09-07 19:34:28 Re: PGQ catalog representation and pg_dump support