Skip to content

Commit 7a031bf

Browse files
anarazelCommitfest Bot
authored andcommitted
Acquire right to set hint bits in the remaining places
Use BufferPrepareToSetHintBits() in the remaining places that modify buffers without an exclusive lock. The remaining places are indexes with support for kill_prior_tuples and the freespace code. After this we do not need to copy buffers to write them out anymore. That change is done separately however. Author: Reviewed-by: Discussion: https://postgr.es/m/ Backpatch:
1 parent e77bc80 commit 7a031bf

File tree

6 files changed

+57
-24
lines changed

6 files changed

+57
-24
lines changed

src/backend/access/gist/gistget.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@ gistkillitems(IndexScanDesc scan)
6363
* safe.
6464
*/
6565
if (BufferGetLSNAtomic(buffer) != so->curPageLSN)
66-
{
67-
UnlockReleaseBuffer(buffer);
68-
so->numKilled = 0; /* reset counter */
69-
return;
70-
}
66+
goto unlock;
7167

7268
Assert(GistPageIsLeaf(page));
7369

@@ -77,6 +73,12 @@ gistkillitems(IndexScanDesc scan)
7773
*/
7874
for (i = 0; i < so->numKilled; i++)
7975
{
76+
if (!killedsomething)
77+
{
78+
if (!BufferPrepareToSetHintBits(buffer))
79+
goto unlock;
80+
}
81+
8082
offnum = so->killedItems[i];
8183
iid = PageGetItemId(page, offnum);
8284
ItemIdMarkDead(iid);
@@ -86,9 +88,10 @@ gistkillitems(IndexScanDesc scan)
8688
if (killedsomething)
8789
{
8890
GistMarkPageHasGarbage(page);
89-
MarkBufferDirtyHint(buffer, true);
91+
BufferFinishSetHintBits(buffer, true, true);
9092
}
9193

94+
unlock:
9295
UnlockReleaseBuffer(buffer);
9396

9497
/*

src/backend/access/hash/hashutil.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,9 @@ _hash_kill_items(IndexScanDesc scan)
593593

594594
if (ItemPointerEquals(&ituple->t_tid, &currItem->heapTid))
595595
{
596+
if (!BufferPrepareToSetHintBits(so->currPos.buf))
597+
goto unlock_page;
598+
596599
/* found the item */
597600
ItemIdMarkDead(iid);
598601
killedsomething = true;
@@ -610,9 +613,10 @@ _hash_kill_items(IndexScanDesc scan)
610613
if (killedsomething)
611614
{
612615
opaque->hasho_flag |= LH_PAGE_HAS_DEAD_TUPLES;
613-
MarkBufferDirtyHint(buf, true);
616+
BufferFinishSetHintBits(so->currPos.buf, true, true);
614617
}
615618

619+
unlock_page:
616620
if (so->hashso_bucket_buf == so->currPos.buf ||
617621
havePin)
618622
LockBuffer(so->currPos.buf, BUFFER_LOCK_UNLOCK);

src/backend/access/nbtree/nbtinsert.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -679,20 +679,29 @@ _bt_check_unique(Relation rel, BTInsertState insertstate, Relation heapRel,
679679
{
680680
/*
681681
* The conflicting tuple (or all HOT chains pointed to by
682-
* all posting list TIDs) is dead to everyone, so mark the
683-
* index entry killed.
682+
* all posting list TIDs) is dead to everyone, so try to
683+
* mark the index entry killed. It's ok if we're not
684+
* allowed to, this isn't required for correctness.
684685
*/
685-
ItemIdMarkDead(curitemid);
686-
opaque->btpo_flags |= BTP_HAS_GARBAGE;
686+
Buffer buf;
687687

688-
/*
689-
* Mark buffer with a dirty hint, since state is not
690-
* crucial. Be sure to mark the proper buffer dirty.
691-
*/
688+
/* Be sure to operate on the proper buffer */
692689
if (nbuf != InvalidBuffer)
693-
MarkBufferDirtyHint(nbuf, true);
690+
buf = nbuf;
694691
else
695-
MarkBufferDirtyHint(insertstate->buf, true);
692+
buf = insertstate->buf;
693+
694+
if (BufferPrepareToSetHintBits(buf))
695+
{
696+
ItemIdMarkDead(curitemid);
697+
opaque->btpo_flags |= BTP_HAS_GARBAGE;
698+
699+
/*
700+
* Mark buffer with a dirty hint, since state is not
701+
* crucial.
702+
*/
703+
BufferFinishSetHintBits(buf, true, true);
704+
}
696705
}
697706

698707
/*

src/backend/access/nbtree/nbtutils.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2492,6 +2492,10 @@ _bt_killitems(IndexScanDesc scan)
24922492
*/
24932493
if (killtuple && !ItemIdIsDead(iid))
24942494
{
2495+
/* if we're not able to set hint bits, there's no point continuing */
2496+
if (!killedsomething && !BufferPrepareToSetHintBits(so->currPos.buf))
2497+
goto unlock_page;
2498+
24952499
/* found the item/all posting list items */
24962500
ItemIdMarkDead(iid);
24972501
killedsomething = true;
@@ -2511,9 +2515,10 @@ _bt_killitems(IndexScanDesc scan)
25112515
if (killedsomething)
25122516
{
25132517
opaque->btpo_flags |= BTP_HAS_GARBAGE;
2514-
MarkBufferDirtyHint(so->currPos.buf, true);
2518+
BufferFinishSetHintBits(so->currPos.buf, true, true);
25152519
}
25162520

2521+
unlock_page:
25172522
_bt_unlockbuf(scan->indexRelation, so->currPos.buf);
25182523
}
25192524

src/backend/storage/freespace/freespace.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -904,12 +904,18 @@ fsm_vacuum_page(Relation rel, FSMAddress addr,
904904
max_avail = fsm_get_max_avail(page);
905905

906906
/*
907-
* Reset the next slot pointer. This encourages the use of low-numbered
908-
* pages, increasing the chances that a later vacuum can truncate the
909-
* relation. We don't bother with a lock here, nor with marking the page
910-
* dirty if it wasn't already, since this is just a hint.
907+
* Try to reset the next slot pointer. This encourages the use of
908+
* low-numbered pages, increasing the chances that a later vacuum can
909+
* truncate the relation. We don't bother with a lock here, nor with
910+
* marking the page dirty if it wasn't already, since this is just a hint.
911+
*
912+
* FIXME: Should probably use BufferSetHintBits16()
911913
*/
912-
((FSMPage) PageGetContents(page))->fp_next_slot = 0;
914+
if (BufferPrepareToSetHintBits(buf))
915+
{
916+
((FSMPage) PageGetContents(page))->fp_next_slot = 0;
917+
BufferFinishSetHintBits(buf, false, false);
918+
}
913919

914920
ReleaseBuffer(buf);
915921

src/backend/storage/freespace/fsmpage.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,13 @@ fsm_search_avail(Buffer buf, uint8 minvalue, bool advancenext,
300300
*
301301
* Wrap-around is handled at the beginning of this function.
302302
*/
303-
fsmpage->fp_next_slot = slot + (advancenext ? 1 : 0);
303+
if (exclusive_lock_held || BufferPrepareToSetHintBits(buf))
304+
{
305+
fsmpage->fp_next_slot = slot + (advancenext ? 1 : 0);
306+
307+
if (!exclusive_lock_held)
308+
BufferFinishSetHintBits(buf, false, true);
309+
}
304310

305311
return slot;
306312
}

0 commit comments

Comments
 (0)