Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfbbe002

Browse files
committed
Tweak buffer manager so that 'internal' accesses to a buffer do not
advance its usage_count. This includes writes of dirty buffers triggeredby bgwriter, checkpoint, or FlushRelationBuffers, as well as variouscorner cases that really ought not count as accesses to the page.Should make for some marginal improvement in the quality of our decisionsabout when to recycle buffers. Per suggestion from ITAGAKI Takahiro.
1 parentbc93b37 commitfbbe002

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.197 2005/10/15 02:49:24 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.198 2005/10/27 17:07:58 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -85,7 +85,8 @@ static volatile BufferDesc *PinCountWaitBuf = NULL;
8585

8686
staticboolPinBuffer(volatileBufferDesc*buf);
8787
staticvoidPinBuffer_Locked(volatileBufferDesc*buf);
88-
staticvoidUnpinBuffer(volatileBufferDesc*buf,boolfixOwner,booltrashOK);
88+
staticvoidUnpinBuffer(volatileBufferDesc*buf,
89+
boolfixOwner,boolnormalAccess);
8990
staticboolSyncOneBuffer(intbuf_id,boolskip_pinned);
9091
staticvoidWaitIO(volatileBufferDesc*buf);
9192
staticboolStartBufferIO(volatileBufferDesc*buf,boolforInput);
@@ -780,12 +781,18 @@ PinBuffer_Locked(volatile BufferDesc *buf)
780781
* This should be applied only to shared buffers, never local ones.
781782
*
782783
* Most but not all callers want CurrentResourceOwner to be adjusted.
784+
* Those that don't should pass fixOwner = FALSE.
785+
*
786+
* normalAccess indicates that we are finishing a "normal" page access,
787+
* that is, one requested by something outside the buffer subsystem.
788+
* Passing FALSE means it's an internal access that should not update the
789+
* buffer's usage count nor cause a change in the freelist.
783790
*
784791
* If we are releasing a buffer during VACUUM, and it's not been otherwise
785-
* used recently, andtrashOK is true, send the buffer to the freelist.
792+
* used recently, andnormalAccess is true, we send the buffer to the freelist.
786793
*/
787794
staticvoid
788-
UnpinBuffer(volatileBufferDesc*buf,boolfixOwner,booltrashOK)
795+
UnpinBuffer(volatileBufferDesc*buf,boolfixOwner,boolnormalAccess)
789796
{
790797
intb=buf->buf_id;
791798

@@ -797,7 +804,7 @@ UnpinBuffer(volatile BufferDesc *buf, bool fixOwner, bool trashOK)
797804
PrivateRefCount[b]--;
798805
if (PrivateRefCount[b]==0)
799806
{
800-
booltrash_buffer= false;
807+
boolimmed_free_buffer= false;
801808

802809
/* I'd better not still hold any locks on the buffer */
803810
Assert(!LWLockHeldByMe(buf->content_lock));
@@ -810,16 +817,21 @@ UnpinBuffer(volatile BufferDesc *buf, bool fixOwner, bool trashOK)
810817
Assert(buf->refcount>0);
811818
buf->refcount--;
812819

813-
/*Mark thebufferrecently used, unlesswe are in VACUUM */
814-
if (!strategy_hint_vacuum)
820+
/*Updatebufferusage info, unlessthis is an internal access */
821+
if (normalAccess)
815822
{
816-
if (buf->usage_count<BM_MAX_USAGE_COUNT)
817-
buf->usage_count++;
823+
if (!strategy_hint_vacuum)
824+
{
825+
if (buf->usage_count<BM_MAX_USAGE_COUNT)
826+
buf->usage_count++;
827+
}
828+
else
829+
{
830+
/* VACUUM accesses don't bump usage count, instead... */
831+
if (buf->refcount==0&&buf->usage_count==0)
832+
immed_free_buffer= true;
833+
}
818834
}
819-
elseif (trashOK&&
820-
buf->refcount==0&&
821-
buf->usage_count==0)
822-
trash_buffer= true;
823835

824836
if ((buf->flags&BM_PIN_COUNT_WAITER)&&
825837
buf->refcount==1)
@@ -839,7 +851,7 @@ UnpinBuffer(volatile BufferDesc *buf, bool fixOwner, bool trashOK)
839851
* freelist for near-term reuse. We put it at the tail so that it
840852
* won't be used before any invalid buffers that may exist.
841853
*/
842-
if (trash_buffer)
854+
if (immed_free_buffer)
843855
StrategyFreeBuffer(buf, false);
844856
}
845857
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp