Skip to content

Commit 166af55

Browse files
anarazelCommitfest Bot
authored and
Commitfest Bot
committed
bufmgr: Add interface to acquire right to set hint bits
At the moment hint bits can be set with just a share lock on a page (and in one place even without any lock). Because of this we need to copy pages while writing them out, as otherwise the checksum could be corrupted. The need to copy the page is problematic for the AIO patchset: 1) Instead of just needing a single buffer for a copied page we need one for each page that's potentially undergoing IO 2) To be able to use the "worker" AIO implementation the copied page needs to reside in shared memory. Even without AIO copying the page isn't free... This commit starts to address that by adding BufferPrepareToSetHintBits(), which needs to be called before setting hint bits on a buffer. BufferPrepareToSetHintBits() only allows hint bit writes if there's no ongoing IO and while hint bits are being set no IO is allowed to be started. To know that a buffer is undergoing IO a new BufferDesc state flag is used, BM_SETTING_HINTS. Theoretically it'd be possible to reuse BM_IO_IN_PROGRESS, but that'd make it harder to debug the system. The new interface is not yet used, that will happen in subsequent commits, to make review a bit easier. Therefore we cannot yet rely on not needing a copy of the buffer during IO. Author: Reviewed-by: Discussion: https://postgr.es/m/ Backpatch:
1 parent a37b3ef commit 166af55

File tree

5 files changed

+351
-49
lines changed

5 files changed

+351
-49
lines changed

src/backend/storage/buffer/README

+5-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ tuple while they are doing visibility checks.
5858
4. It is considered OK to update tuple commit status bits (ie, OR the
5959
values HEAP_XMIN_COMMITTED, HEAP_XMIN_INVALID, HEAP_XMAX_COMMITTED, or
6060
HEAP_XMAX_INVALID into t_infomask) while holding only a shared lock and
61-
pin on a buffer. This is OK because another backend looking at the tuple
61+
pin on a buffer after calling BufferPrepareToSetHintBits().
62+
This is OK because another backend looking at the tuple
6263
at about the same time would OR the same bits into the field, so there
6364
is little or no risk of conflicting update; what's more, if there did
6465
manage to be a conflict it would merely mean that one bit-update would
@@ -68,6 +69,9 @@ great harm is done if they get reset to zero by conflicting updates.
6869
Note, however, that a tuple is frozen by setting both HEAP_XMIN_INVALID
6970
and HEAP_XMIN_COMMITTED; this is a critical update and accordingly requires
7071
an exclusive buffer lock (and it must also be WAL-logged).
72+
Calling BufferPrepareToSetHintBits() ensures that write IO cannot happen at
73+
the same time as modifying hint bits, which can lead the checksum computed at
74+
the start of the write to not match anymore.
7175

7276
5. To physically remove a tuple or compact free space on a page, one
7377
must hold a pin and an exclusive lock, *and* observe while holding the

0 commit comments

Comments
 (0)