From: | Andres Freund <andres(at)anarazel(dot)de> |
---|---|
To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
Subject: | pgsql: hio: Don't pin the VM while holding buffer lock while extending |
Date: | 2023-04-06 18:28:41 |
Message-ID: | E1pkULg-001ig5-AI@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
hio: Don't pin the VM while holding buffer lock while extending
Starting with commit 7db0cd2145f, RelationGetBufferForTuple() did a
visibilitymap_pin() while holding an exclusive buffer content lock on a newly
extended page, when using COPY FREEZE. We elsewhere try hard to avoid to doing
IO while holding a content lock. And until 14f98e0af99, that happened while
holding the relation extension lock.
Practically, this isn't a huge issue, because COPY FREEZE is restricted to
relations created or truncated in the current session, so it's unlikely
there's a lot of contention.
We can't avoid doing IO while holding the content lock by pinning the VM
earlier, because we don't know which page it will be on.
While we could just ignore the issue in this case, a future commit will add
bulk relation extension, which needs to enter pages into the FSM while also
trying to hold onto a buffer lock.
To address this issue, use visibilitymap_pin_ok() to see if the relevant
buffer is already pinned. If not, release the buffer, pin the VM buffer, and
acquire the lock again. This opens up a small window for other backends to
insert data onto the page - as the page is not entered into the freespacemap,
other backends won't see it normally, but a concurrent vacuum could enter the
page, if it started just after the relation is extended. In case the page is
used by another backend, retry. This is very similar to how locking
"otherBuffer" is already dealt with.
Reviewed-by: Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>
Discussion: http://postgr.es/m/20230325025740.wzvchp2kromw4zqz@awork3.anarazel.de
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/18103b7c5f1aed4ca22f75229346eddb6e20d725
Modified Files
--------------
src/backend/access/heap/hio.c | 126 ++++++++++++++++++++++++++++--------------
1 file changed, 85 insertions(+), 41 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Daniel Gustafsson | 2023-04-06 18:40:55 | Re: lz4 --rm on Ubuntu 18.04 (Add LZ4 compression to pg_dump) |
Previous Message | Andres Freund | 2023-04-06 18:11:02 | pgsql: hio: Relax rules for calling GetVisibilityMapPins() |