Skip to content

Commit c2281ac

Browse files
committed
Remove belt-and-suspenders guards against buffer pin leaks.
Forcibly releasing all leftover buffer pins should be unnecessary now that we have a robust ResourceOwner mechanism, and it significantly increases the cost of process shutdown. Instead, in an assert-enabled build, assert that no pins are held; in a non-assert-enabled build, do nothing.
1 parent 58dfb07 commit c2281ac

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

src/backend/storage/buffer/bufmgr.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,31 +1659,26 @@ InitBufferPoolBackend(void)
16591659
}
16601660

16611661
/*
1662-
* Ensure we have released all shared-buffer locks and pins during backend exit
1662+
* During backend exit, ensure that we released all shared-buffer locks and
1663+
* assert that we have no remaining pins.
16631664
*/
16641665
static void
16651666
AtProcExit_Buffers(int code, Datum arg)
16661667
{
1667-
int i;
1668-
16691668
AbortBufferIO();
16701669
UnlockBuffers();
16711670

1672-
for (i = 0; i < NBuffers; i++)
1671+
#ifdef USE_ASSERT_CHECKING
1672+
if (assert_enabled)
16731673
{
1674-
if (PrivateRefCount[i] != 0)
1675-
{
1676-
volatile BufferDesc *buf = &(BufferDescriptors[i]);
1674+
int i;
16771675

1678-
/*
1679-
* We don't worry about updating ResourceOwner; if we even got
1680-
* here, it suggests that ResourceOwners are messed up.
1681-
*/
1682-
PrivateRefCount[i] = 1; /* make sure we release shared pin */
1683-
UnpinBuffer(buf, false);
1676+
for (i = 0; i < NBuffers; i++)
1677+
{
16841678
Assert(PrivateRefCount[i] == 0);
16851679
}
16861680
}
1681+
#endif
16871682

16881683
/* localbuf.c needs a chance too */
16891684
AtProcExit_LocalBuffers();

src/backend/storage/buffer/localbuf.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,23 @@ AtEOXact_LocalBuffers(bool isCommit)
468468
/*
469469
* AtProcExit_LocalBuffers - ensure we have dropped pins during backend exit.
470470
*
471-
* This is just like AtProcExit_Buffers, but for local buffers. We have
472-
* to drop pins to ensure that any attempt to drop temp files doesn't
473-
* fail in DropRelFileNodeBuffers.
471+
* This is just like AtProcExit_Buffers, but for local buffers. We shouldn't
472+
* be holding any remaining pins; if we are, and assertions aren't enabled,
473+
* we'll fail later in DropRelFileNodeBuffers while trying to drop the temp
474+
* rels.
474475
*/
475476
void
476477
AtProcExit_LocalBuffers(void)
477478
{
478-
/* just zero the refcounts ... */
479-
if (LocalRefCount)
480-
MemSet(LocalRefCount, 0, NLocBuffer * sizeof(*LocalRefCount));
479+
#ifdef USE_ASSERT_CHECKING
480+
if (assert_enabled && LocalRefCount)
481+
{
482+
int i;
483+
484+
for (i = 0; i < NLocBuffer; i++)
485+
{
486+
Assert(LocalRefCount[i] == 0);
487+
}
488+
}
489+
#endif
481490
}

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