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

Commitc40a0a1

Browse files
committed
Marginal performance improvement in LockBuffer --- calculate address
of BufferLocks[] entry just once. Seems to save 10% or so of theroutine's runtime, which'd not be worth worrying about if it weren'tsuch a hotspot.
1 parente02cde4 commitc40a0a1

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.75 2000/02/21 18:49:00 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.76 2000/03/14 22:46:27 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2072,12 +2072,14 @@ void
20722072
LockBuffer(Bufferbuffer,intmode)
20732073
{
20742074
BufferDesc*buf;
2075+
bits8*buflock;
20752076

20762077
Assert(BufferIsValid(buffer));
20772078
if (BufferIsLocal(buffer))
20782079
return;
20792080

20802081
buf=&(BufferDescriptors[buffer-1]);
2082+
buflock=&(BufferLocks[buffer-1]);
20812083

20822084
#ifdefHAS_TEST_AND_SET
20832085
S_LOCK(&(buf->cntx_lock));
@@ -2087,21 +2089,21 @@ LockBuffer(Buffer buffer, int mode)
20872089

20882090
if (mode==BUFFER_LOCK_UNLOCK)
20892091
{
2090-
if (BufferLocks[buffer-1]&BL_R_LOCK)
2092+
if (*buflock&BL_R_LOCK)
20912093
{
20922094
Assert(buf->r_locks>0);
20932095
Assert(!(buf->w_lock));
2094-
Assert(!(BufferLocks[buffer-1]& (BL_W_LOCK |BL_RI_LOCK)))
2095-
(buf->r_locks)--;
2096-
BufferLocks[buffer-1] &= ~BL_R_LOCK;
2096+
Assert(!(*buflock& (BL_W_LOCK |BL_RI_LOCK)));
2097+
(buf->r_locks)--;
2098+
*buflock &= ~BL_R_LOCK;
20972099
}
2098-
elseif (BufferLocks[buffer-1]&BL_W_LOCK)
2100+
elseif (*buflock&BL_W_LOCK)
20992101
{
21002102
Assert(buf->w_lock);
21012103
Assert(buf->r_locks==0);
2102-
Assert(!(BufferLocks[buffer-1]& (BL_R_LOCK |BL_RI_LOCK)))
2103-
buf->w_lock= false;
2104-
BufferLocks[buffer-1] &= ~BL_W_LOCK;
2104+
Assert(!(*buflock& (BL_R_LOCK |BL_RI_LOCK)));
2105+
buf->w_lock= false;
2106+
*buflock &= ~BL_W_LOCK;
21052107
}
21062108
else
21072109
elog(ERROR,"UNLockBuffer: buffer %lu is not locked",buffer);
@@ -2110,7 +2112,7 @@ LockBuffer(Buffer buffer, int mode)
21102112
{
21112113
unsignedi=0;
21122114

2113-
Assert(!(BufferLocks[buffer-1]& (BL_R_LOCK |BL_W_LOCK |BL_RI_LOCK)));
2115+
Assert(!(*buflock& (BL_R_LOCK |BL_W_LOCK |BL_RI_LOCK)));
21142116
while (buf->ri_lock||buf->w_lock)
21152117
{
21162118
#ifdefHAS_TEST_AND_SET
@@ -2124,24 +2126,24 @@ LockBuffer(Buffer buffer, int mode)
21242126
#endif
21252127
}
21262128
(buf->r_locks)++;
2127-
BufferLocks[buffer-1] |=BL_R_LOCK;
2129+
*buflock |=BL_R_LOCK;
21282130
}
21292131
elseif (mode==BUFFER_LOCK_EXCLUSIVE)
21302132
{
21312133
unsignedi=0;
21322134

2133-
Assert(!(BufferLocks[buffer-1]& (BL_R_LOCK |BL_W_LOCK |BL_RI_LOCK)));
2135+
Assert(!(*buflock& (BL_R_LOCK |BL_W_LOCK |BL_RI_LOCK)));
21342136
while (buf->r_locks>0||buf->w_lock)
21352137
{
2136-
if (buf->r_locks>3|| (BufferLocks[buffer-1]&BL_RI_LOCK))
2138+
if (buf->r_locks>3|| (*buflock&BL_RI_LOCK))
21372139
{
21382140
/*
21392141
* Our RI lock might be removed by concurrent W lock
21402142
* acquiring (see what we do with RI locks below
21412143
* when our own W acquiring succeeded) and so
21422144
* we set RI lock again if we already did this.
21432145
*/
2144-
BufferLocks[buffer-1] |=BL_RI_LOCK;
2146+
*buflock |=BL_RI_LOCK;
21452147
buf->ri_lock= true;
21462148
}
21472149
#ifdefHAS_TEST_AND_SET
@@ -2155,15 +2157,15 @@ LockBuffer(Buffer buffer, int mode)
21552157
#endif
21562158
}
21572159
buf->w_lock= true;
2158-
BufferLocks[buffer-1] |=BL_W_LOCK;
2159-
if (BufferLocks[buffer-1]&BL_RI_LOCK)
2160+
*buflock |=BL_W_LOCK;
2161+
if (*buflock&BL_RI_LOCK)
21602162
{
21612163
/*
21622164
* It's possible to remove RI locks acquired by another
21632165
* W lockers here, but they'll take care about it.
21642166
*/
21652167
buf->ri_lock= false;
2166-
BufferLocks[buffer-1] &= ~BL_RI_LOCK;
2168+
*buflock &= ~BL_RI_LOCK;
21672169
}
21682170
}
21692171
else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp