Skip to content

Commit 5787c67

Browse files
Skip extraneous locking in XLogCheckBuffer().
Heikki reported comment was wrong, so fixed code to match the comment: we only need to take additional locking precautions when we have a shared lock on the buffer.
1 parent 47c4333 commit 5787c67

File tree

1 file changed

+16
-11
lines changed
  • src/backend/access/transam

1 file changed

+16
-11
lines changed

src/backend/access/transam/xlog.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ static void CreateEndOfRecoveryRecord(void);
646646
static void CheckPointGuts(XLogRecPtr checkPointRedo, int flags);
647647
static void KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo);
648648

649-
static bool XLogCheckBuffer(XLogRecData *rdata, bool doPageWrites,
649+
static bool XLogCheckBuffer(XLogRecData *rdata, bool holdsExclusiveLock,
650650
XLogRecPtr *lsn, BkpBlock *bkpb);
651651
static Buffer RestoreBackupBlockContents(XLogRecPtr lsn, BkpBlock bkpb,
652652
char *blk, bool get_cleanup_lock, bool keep_buffer);
@@ -822,7 +822,7 @@ begin:;
822822
{
823823
/* OK, put it in this slot */
824824
dtbuf[i] = rdt->buffer;
825-
if (XLogCheckBuffer(rdt, doPageWrites,
825+
if (doPageWrites && XLogCheckBuffer(rdt, true,
826826
&(dtbuf_lsn[i]), &(dtbuf_xlg[i])))
827827
{
828828
dtbuf_bkp[i] = true;
@@ -1243,23 +1243,25 @@ begin:;
12431243
* save the buffer's LSN at *lsn.
12441244
*/
12451245
static bool
1246-
XLogCheckBuffer(XLogRecData *rdata, bool doPageWrites,
1246+
XLogCheckBuffer(XLogRecData *rdata, bool holdsExclusiveLock,
12471247
XLogRecPtr *lsn, BkpBlock *bkpb)
12481248
{
12491249
Page page;
12501250

12511251
page = BufferGetPage(rdata->buffer);
12521252

12531253
/*
1254-
* XXX We assume page LSN is first data on *every* page that can be passed
1255-
* to XLogInsert, whether it otherwise has the standard page layout or
1256-
* not. We don't need the buffer header lock for PageGetLSN because we
1257-
* have exclusive lock on the page and/or the relation.
1254+
* We assume page LSN is first data on *every* page that can be passed
1255+
* to XLogInsert, whether it has the standard page layout or not. We
1256+
* don't need to take the buffer header lock for PageGetLSN if we hold
1257+
* an exclusive lock on the page and/or the relation.
12581258
*/
1259-
*lsn = BufferGetLSNAtomic(rdata->buffer);
1259+
if (holdsExclusiveLock)
1260+
*lsn = PageGetLSN(page);
1261+
else
1262+
*lsn = BufferGetLSNAtomic(rdata->buffer);
12601263

1261-
if (doPageWrites &&
1262-
*lsn <= RedoRecPtr)
1264+
if (*lsn <= RedoRecPtr)
12631265
{
12641266
/*
12651267
* The page needs to be backed up, so set up *bkpb
@@ -7683,7 +7685,10 @@ XLogSaveBufferForHint(Buffer buffer)
76837685
rdata[0].buffer = buffer;
76847686
rdata[0].buffer_std = true;
76857687

7686-
if (XLogCheckBuffer(rdata, true, &lsn, &bkpb))
7688+
/*
7689+
* Check buffer while not holding an exclusive lock.
7690+
*/
7691+
if (XLogCheckBuffer(rdata, false, &lsn, &bkpb))
76877692
{
76887693
char copied_buffer[BLCKSZ];
76897694
char *origdata = (char *) BufferGetBlock(buffer);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy