| 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-30 16:14:54 |
| Message-ID: | CAAKRu_ZS7aP3HUHbd0MDaHYqZjXYRMqc8VFKiXk7W-ueHd+H-w@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Sat, Nov 28, 2026 at 1:49 AM Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> wrote:
>
Thanks for taking another look
> One minor comment:
> - * To set a bit, you need to hold a lock on the heap page. That prevents
> - * the race condition where VACUUM sees that all tuples on the page are
> - * visible to everyone, but another backend modifies the page before VACUUM
> - * sets the bit in the visibility map.
>
> + * Setting or clearing VM bits requires locks on both the heap and VM buffers.
> + * The heap buffer lock keeps the heap page and its VM bits consistent, while
> + * the exclusive VM buffer lock protects the VM page. Callers acquire the VM
> + * lock after the heap buffer lock and before entering the critical section.
> + * Both locks are held throughout the critical section, including WAL insertion
> + * and updating the page LSNs. The VM buffer must remain locked while the WAL
> + * record is constructed, since the record may include a full-page image of it.
>
> The previous comment mentions about the Vacuum's race "That prevents
> the race condition where VACUUM sees that .." which the new text
> doesn't seem to cover. If you omitted that intentionally then fine,
> otherwise, something like attached atop your patch could be helpful.
Makes sense. I've done a version of that in the attached I plan to
commit later today.
> BTW, does following text in same file also needs an update:
> This shouldn't happen
> + * often, because only VACUUM currently sets visibility map bits, and the race
> + * will only occur if VACUUM processes a given page at almost exactly the same
> + * time that someone tries to further modify it.
>
> The code is setting the visibility map bit even on pruning via
> heap_page_prune_opt()->heap_page_prune_and_freeze(), so the "...
> because only VACUUM ..." part probably requires an update.
Good call. I've gone through and updated any of the references to
vacuum that seemed a bit out of date. Of course, that only applies to
19 and master, so I've changed the comments a bit for 17 and 18.
- Melanie
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Update-visibilitymap.c-comments.patch | text/x-patch | 8.5 KB |
| 18_v2-0001-Update-visibilitymap.c-comments.patch | text/x-patch | 8.1 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Rui Zhao | 2026-11-30 16:24:35 | Re: improvements / reworks for FDW insert batching |
| Previous Message | Antonin Houska | 2026-11-30 16:10:30 | Re: Allow progress tracking of sub-commands |