| From: | Melanie Plageman <melanieplageman(at)gmail(dot)com> |
|---|---|
| To: | Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> |
| Cc: | Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrey Borodin <x4mmm(at)yandex-team(dot)ru>, Andres Freund <andres(at)anarazel(dot)de>, Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi> |
| Subject: | Re: Why clearing the VM doesn't require registering vm buffer in wal record |
| Date: | 2026-11-25 18:34:10 |
| Message-ID: | CAAKRu_YEjv10SZ9iGzVQNE9jwmqHmDvpRa+0Kq=Up49TsNcQ2w@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Mon, Oct 26, 2026 at 6:31 AM Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> wrote:
>
> While reading the code committed as ed62d26cac, I wonder whether the
> change in commit requires an update in the comments atop
> visibilitymap.c. See following observations:
Thanks for taking the time.
> 1. The following text on WAL-logging doesn't seem to match the changed
> code. "Changes to the visibility map bits are not separately
> WAL-logged. Callers must make sure that whenever a visibility map bit
> is cleared, the bit is cleared on WAL replay of the updating
> operation…"
>
> The VM page is still not logged by its own record. But after commit
> ed62d26cac, a caller that clears a bit must register the VM buffer
> (block ref *_BLKREF_VM) in the heap record. It must also PageSetLSN()
> the VM page. This makes me feel that the above quoted text could be
> updated.
I made some tweaks, but I thought pointing out that you have to
register the VM blocks actually took away from the clarity because WAL
registering all blocks you modify is the normal course of operation.
The fact that we didn't do it before would need to be called out. That
being said, I did do some rewording in the attached patch.
> 2. The LOCKING section is now wrong about the lock order and critical section.
>
> It describes only a pin on the VM page before locking the heap buffer,
> and the pin/relock race. Callers now also take an exclusive lock on
> the VM buffer before START_CRIT_SECTION() and hold it until after
> XLogInsert() and release it before the heap buffer lock.
I've done some tweaks here but visibilitymap_clear() did take the
exclusive lock before. The difference is now that callers take the
lock as opposed to the function doing it itself.
> 3. The last LOCKING paragraph also needs an update. I am referring to:
> "But when a bit is cleared, we don't have to do that [update the VM
> page LSN] because it's always safe to clear a bit in the map from
> correctness point of view."
That's right. I've updated that.
- Melanie
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Update-visibilitymap.c-comments.patch | application/octet-stream | 5.8 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Henson Choi | 2026-11-25 18:54:40 | Re: Row pattern recognition |
| Previous Message | Andrey Rachitskiy | 2026-11-25 18:31:47 | Re: Fix OOM when rendering large geometry arrays |