From 7e04843ba7d4a4bd39665f73f0ae5aaa047591d6 Mon Sep 17 00:00:00 2001 From: "Vadim B. Mikheev" Date: Tue, 13 Feb 2001 20:40:25 +0000 Subject: [PATCH] Comments about GetFreeXLBuffer(). GetFreeXLBuffer(): use Insert->LgwrResult instead of private LgwrResult copy if it's more fresh (attempt to avoid acquiring info_lck/lgwr_lck). --- src/backend/access/transam/xlog.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 8b701a85df..7c18f0ff5a 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.52 2001/02/13 08:44:09 vadim Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.53 2001/02/13 20:40:25 vadim Exp $ * *------------------------------------------------------------------------- */ @@ -612,6 +612,7 @@ begin:; if (updrqst) { S_LOCK(&(XLogCtl->info_lck)); + LgwrResult = XLogCtl->LgwrResult; if (XLByteLT(XLogCtl->LgwrRqst.Write, LgwrRqst.Write)) XLogCtl->LgwrRqst.Write = LgwrRqst.Write; S_UNLOCK(&(XLogCtl->info_lck)); @@ -760,6 +761,10 @@ XLogFlush(XLogRecPtr record) } +/* + * We use this routine when Insert->curridx block is full and the next XLOG + * buffer looks as unwritten to OS' cache. insert_lck is assumed here. + */ static void GetFreeXLBuffer() { @@ -768,12 +773,24 @@ GetFreeXLBuffer() uint16 curridx = NextBufIdx(Insert->curridx); unsigned spins = 0; + /* Use Insert->LgwrResult copy if it's more fresh */ + if (XLByteLT(LgwrResult.Write, Insert->LgwrResult.Write)) + { + LgwrResult = Insert->LgwrResult; + if (XLByteLE(XLogCtl->xlblocks[curridx], LgwrResult.Write)) + { + InitXLBuffer(curridx); + return; + } + } + LgwrRqst.Write = XLogCtl->xlblocks[Insert->curridx]; for (;;) { if (!TAS(&(XLogCtl->info_lck))) { LgwrResult = XLogCtl->LgwrResult; + /* LgwrRqst.Write GE XLogCtl->LgwrRqst.Write */ XLogCtl->LgwrRqst.Write = LgwrRqst.Write; S_UNLOCK(&(XLogCtl->info_lck)); if (XLByteLE(XLogCtl->xlblocks[curridx], LgwrResult.Write))