| From: | Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> |
|---|---|
| To: | Melanie Plageman <melanieplageman(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-28 06:49:17 |
| Message-ID: | CAA4eK1+hBCVN-uvJ0+c2z4uB_UBiCkssXTRVxXj7ArVyQ5PkBg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Thu, Nov 26, 2026 at 12:04 AM Melanie Plageman
<melanieplageman(at)gmail(dot)com> wrote:
>
> That's right. I've updated that.
>
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.
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.
--
With Regards,
Amit Kapila.
| Attachment | Content-Type | Size |
|---|---|---|
| v1-topup-amit.1.txt | text/plain | 1.2 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Michael Paquier | 2026-11-28 07:13:45 | Re: [PATCH] libpq: Add PQpassfileLookup() |
| Previous Message | ZizhuanLiu X-MAN | 2026-11-28 06:42:12 | Re: examine_variable ignored CollateExpr |