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

Commit1c2de47

Browse files
committed
Remove BufferLocks[] array in favor of a single pointer to the buffer
(if any) currently waited for by LockBufferForCleanup(), which is allthat we were using it for anymore. Saves some space and eliminatesproportional-to-NBuffers slowdown in UnlockBuffers().
1 parent72f9013 commit1c2de47

File tree

3 files changed

+35
-56
lines changed

3 files changed

+35
-56
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/buffer/buf_init.c,v 1.68 2004/08/2905:06:47 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/buffer/buf_init.c,v 1.69 2004/10/16 18:05:06 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -20,9 +20,7 @@
2020

2121
BufferDesc*BufferDescriptors;
2222
Block*BufferBlockPointers;
23-
24-
int32*PrivateRefCount;/* also used in freelist.c */
25-
bits8*BufferLocks;/* flag bits showing locks I have set */
23+
int32*PrivateRefCount;
2624

2725
/* statistics counters */
2826
longintReadBufferCount;
@@ -177,7 +175,6 @@ InitBufferPoolAccess(void)
177175
sizeof(*BufferBlockPointers));
178176
PrivateRefCount= (int32*)calloc(NBuffers,
179177
sizeof(*PrivateRefCount));
180-
BufferLocks= (bits8*)calloc(NBuffers,sizeof(*BufferLocks));
181178

182179
/*
183180
* Convert shmem offsets into addresses as seen by this process. This

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

Lines changed: 31 additions & 37 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.178 2004/10/15 22:39:59 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.179 2004/10/16 18:05:06 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -66,6 +66,13 @@ longNDirectFileRead;/* some I/O's are direct file access.
6666
longNDirectFileWrite;/* e.g., I/O in psort and hashjoin. */
6767

6868

69+
/* local state for StartBufferIO and related functions */
70+
staticBufferDesc*InProgressBuf=NULL;
71+
staticboolIsForInput;
72+
/* local state for LockBufferForCleanup */
73+
staticBufferDesc*PinCountWaitBuf=NULL;
74+
75+
6976
staticvoidPinBuffer(BufferDesc*buf,boolfixOwner);
7077
staticvoidUnpinBuffer(BufferDesc*buf,boolfixOwner);
7178
staticvoidWaitIO(BufferDesc*buf);
@@ -1650,48 +1657,38 @@ SetBufferCommitInfoNeedsSave(Buffer buffer)
16501657
* Release buffer context locks for shared buffers.
16511658
*
16521659
* Used to clean up after errors.
1660+
*
1661+
* Currently, we can expect that lwlock.c's LWLockReleaseAll() took care
1662+
* of releasing buffer context locks per se; the only thing we need to deal
1663+
* with here is clearing any PIN_COUNT request that was in progress.
16531664
*/
16541665
void
16551666
UnlockBuffers(void)
16561667
{
1657-
BufferDesc*buf;
1658-
inti;
1668+
BufferDesc*buf=PinCountWaitBuf;
16591669

1660-
for (i=0;i<NBuffers;i++)
1670+
if (buf)
16611671
{
1662-
bits8buflocks=BufferLocks[i];
1663-
1664-
if (buflocks==0)
1665-
continue;
1666-
1667-
buf=&(BufferDescriptors[i]);
1668-
16691672
HOLD_INTERRUPTS();/* don't want to die() partway through... */
16701673

1674+
LWLockAcquire(BufMgrLock,LW_EXCLUSIVE);
1675+
16711676
/*
1672-
* The buffer's cntx_lock has already been released by lwlock.c.
1677+
* Don't complain if flag bit not set; it could have been
1678+
* reset but we got a cancel/die interrupt before getting the
1679+
* signal.
16731680
*/
1681+
if ((buf->flags&BM_PIN_COUNT_WAITER)!=0&&
1682+
buf->wait_backend_id==MyBackendId)
1683+
buf->flags &= ~BM_PIN_COUNT_WAITER;
1684+
LWLockRelease(BufMgrLock);
16741685

1675-
if (buflocks&BL_PIN_COUNT_LOCK)
1676-
{
1677-
LWLockAcquire(BufMgrLock,LW_EXCLUSIVE);
1678-
1679-
/*
1680-
* Don't complain if flag bit not set; it could have been
1681-
* reset but we got a cancel/die interrupt before getting the
1682-
* signal.
1683-
*/
1684-
if ((buf->flags&BM_PIN_COUNT_WAITER)!=0&&
1685-
buf->wait_backend_id==MyBackendId)
1686-
buf->flags &= ~BM_PIN_COUNT_WAITER;
1687-
LWLockRelease(BufMgrLock);
1688-
ProcCancelWaitForSignal();
1689-
}
1690-
1691-
BufferLocks[i]=0;
1686+
ProcCancelWaitForSignal();
16921687

16931688
RESUME_INTERRUPTS();
16941689
}
1690+
1691+
PinCountWaitBuf=NULL;
16951692
}
16961693

16971694
/*
@@ -1779,9 +1776,9 @@ void
17791776
LockBufferForCleanup(Bufferbuffer)
17801777
{
17811778
BufferDesc*bufHdr;
1782-
bits8*buflock;
17831779

17841780
Assert(BufferIsValid(buffer));
1781+
Assert(PinCountWaitBuf==NULL);
17851782

17861783
if (BufferIsLocal(buffer))
17871784
{
@@ -1799,7 +1796,6 @@ LockBufferForCleanup(Buffer buffer)
17991796
PrivateRefCount[buffer-1]);
18001797

18011798
bufHdr=&BufferDescriptors[buffer-1];
1802-
buflock=&(BufferLocks[buffer-1]);
18031799

18041800
for (;;)
18051801
{
@@ -1822,24 +1818,22 @@ LockBufferForCleanup(Buffer buffer)
18221818
}
18231819
bufHdr->wait_backend_id=MyBackendId;
18241820
bufHdr->flags |=BM_PIN_COUNT_WAITER;
1825-
*buflock |=BL_PIN_COUNT_LOCK;
1821+
PinCountWaitBuf=bufHdr;
18261822
LWLockRelease(BufMgrLock);
18271823
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
18281824
/* Wait to be signaled by UnpinBuffer() */
18291825
ProcWaitForSignal();
1830-
*buflock &= ~BL_PIN_COUNT_LOCK;
1826+
PinCountWaitBuf=NULL;
18311827
/* Loop back and try again */
18321828
}
18331829
}
18341830

18351831
/*
18361832
*Functions for IO error handling
18371833
*
1838-
*Note: We assume that nested buffer IO neveroccur.
1834+
*Note: We assume that nested buffer IO neveroccurs.
18391835
*i.e at most one io_in_progress lock is held per proc.
1840-
*/
1841-
staticBufferDesc*InProgressBuf=NULL;
1842-
staticboolIsForInput;
1836+
*/
18431837

18441838
/*
18451839
* Function:StartBufferIO

‎src/include/storage/buf_internals.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/storage/buf_internals.h,v 1.73 2004/08/2905:06:58 momjian Exp $
11+
* $PostgreSQL: pgsql/src/include/storage/buf_internals.h,v 1.74 2004/10/16 18:05:07 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -75,8 +75,7 @@ typedef struct buftag
7575
)
7676

7777
/*
78-
*BufferDesc -- shared buffer cache metadata for a single
79-
* shared buffer descriptor.
78+
*BufferDesc -- shared descriptor/state data for a single shared buffer.
8079
*/
8180
typedefstructsbufdesc
8281
{
@@ -108,16 +107,6 @@ typedef struct sbufdesc
108107

109108
#defineBufferDescriptorGetBuffer(bdesc) ((bdesc)->buf_id + 1)
110109

111-
112-
/*
113-
* Each backend has its own BufferLocks[] array holding flag bits
114-
* showing what locks it has set on each buffer.
115-
*
116-
* We have to free these locks during ereport(ERROR)...
117-
*/
118-
#defineBL_IO_IN_PROGRESS(1 << 0)/* unimplemented */
119-
#defineBL_PIN_COUNT_LOCK(1 << 1)
120-
121110
/* entry for buffer lookup hashtable */
122111
typedefstruct
123112
{
@@ -206,7 +195,6 @@ extern void BufTableDelete(BufferTag *tagPtr);
206195

207196
/* bufmgr.c */
208197
externBufferDesc*BufferDescriptors;
209-
externbits8*BufferLocks;
210198

211199
/* localbuf.c */
212200
externBufferDesc*LocalBufferDescriptors;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp